Skip to content

Commit

Permalink
implementing an interface to get the variables from the gamefragment …
Browse files Browse the repository at this point in the history
…over to createnewgameactivity somehow. Implementing the function for the listener only workings in maintabbedactivity even though I want it in the createnewgame one. If you take it out of the maintabbedactivity it will crash.
  • Loading branch information
kyleMeyers committed Nov 14, 2016
1 parent d45d7d2 commit 8da03cf
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 2 deletions.
4 changes: 3 additions & 1 deletion heroku/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
android:name=".PlayerFragment"
android:label="Main Baseballsim Display" />
<activity android:name=".MainTabbedActivity" />
<activity android:name=".CreateUserActivity"></activity>
<activity android:name=".CreateUserActivity"/>
<activity android:name=".CreateNewGameActivity"></activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kylemeyers22.heroku;


import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;


public class CreateNewGameActivity extends AppCompatActivity{
private int teamOneId;
private String teamOneName;

private int teamTwoId;
private String teamTwoName;
@Override
protected void onCreate(Bundle savedInstanceState)
{
System.out.println("create the new game");
super.onCreate(savedInstanceState);
setContentView(R.layout.create_game);


System.out.println(teamOneId +" whoo " + teamOneName);
}

}
38 changes: 38 additions & 0 deletions heroku/src/main/java/kylemeyers22/heroku/GameFragment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kylemeyers22.heroku;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.app.ProgressDialog;
import android.content.Context;
Expand Down Expand Up @@ -32,6 +34,36 @@
public class GameFragment extends Fragment {
private ListView gameListView;

private int teamOneId;
private String teamOneName;

private int teamTwoId;
private String teamTwoName;


//interface to interact with the activity for the team id variables
public interface OnGameCreatedListener{
public void onTeamSelected(int teamOneId, String teamOneName, int teamTwoId, String teamTwoName);
}

OnGameCreatedListener mCallback;

@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
try{
mCallback = (OnGameCreatedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException((activity.toString() + "must implement OnGameCreatedListener"));
}
}

public void setListener(OnGameCreatedListener listener)
{
mCallback = listener;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
return inflater.inflate(R.layout.game_fragment, viewGroup, false);
Expand Down Expand Up @@ -86,7 +118,13 @@ public void onClick(View v) {
System.out.println("Team 1: " + teamOne.toString() + " | " + teamOne.getTeamID());
System.out.println("Team 2: " + teamTwo.toString() + " | " + teamTwo.getTeamID());

//send the event to the host activity
mCallback.onTeamSelected(teamOne.getTeamID(), teamOne.toString(), teamTwo.getTeamID(), teamTwo.toString());

//creating a new game
Intent intent = new Intent(v.getContext(), CreateNewGameActivity.class);
startActivity(intent);
//finish();
}
});

Expand Down
18 changes: 17 additions & 1 deletion heroku/src/main/java/kylemeyers22/heroku/MainTabbedActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kylemeyers22.heroku;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
Expand All @@ -12,10 +13,25 @@
import kylemeyers22.heroku.adapters.TabAdapter;
import kylemeyers22.heroku.apiObjects.Team;
import kylemeyers22.heroku.utils.Constants;
import kylemeyers22.heroku.utils.TeamVariables;

public class MainTabbedActivity extends AppCompatActivity {
public class MainTabbedActivity extends AppCompatActivity implements GameFragment.OnGameCreatedListener{
public static ArrayList<Team> teamList;

private int teamOneId;
private String teamOneName;

private int teamTwoId;
private String teamTwoName;
//need to implement it for the interface
public void onTeamSelected(int teamOneId, String teamOneName, int teamTwoId, String teamTwoName)
{


System.out.println(teamOneId +" whooooooooo" + teamOneName);
System.out.println(teamTwoId +" whoooooooo " + teamTwoName);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Constants {

// API locations
public static final String rootAPI = "https://baseballsim.herokuapp.com/api/";
//public static final String rootAPI = "localhost:3000/console";
public static final String usersAPI = rootAPI + "users/";
public static final String authAPI = usersAPI + "token/";
public static final String playersAPI = rootAPI + "players/";
Expand Down
47 changes: 47 additions & 0 deletions heroku/src/main/java/kylemeyers22/heroku/utils/TeamVariables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package kylemeyers22.heroku.utils;


public class TeamVariables {
private int teamOneId;
private String teamOneName;

private int teamTwoId;
private String teamTwoName;

public void setTeamOneId(int teamOneId)
{
this.teamOneId = teamOneId;
}

public void setTeamTwoId(int teamTwoId)
{
this.teamTwoId= teamTwoId;
}

public void setTeamOneName(String teamOneName)
{
this.teamOneName = teamOneName;
}

public void setTeamTwoName(String teamTwoName)
{
this.teamTwoName = teamTwoName;
}

public int getTeamOneId ()
{
return this.teamOneId;
}
public int getTeamTwoId()
{
return this.teamTwoId;
}
public String getTeamOneName()
{
return this.teamOneName;
}
public String getTeamTwoName ()
{
return this.teamTwoName;
}
}
13 changes: 13 additions & 0 deletions heroku/src/main/res/layout/create_game.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CreateNewGameActivity">

</LinearLayout>

0 comments on commit 8da03cf

Please sign in to comment.