25
25
import java .util .List ;
26
26
27
27
public class MainActivity extends AppCompatActivity implements Repository .EntityChangeListener ,
28
- WelcomeFragment .WelcomeFragmentListener , MainMenuFragment .MainMenuFragmentListener {
28
+ WelcomeFragment .WelcomeFragmentListener , MainMenuFragment .MainMenuFragmentListener , GameFragment . GameFragmentListener {
29
29
30
30
public static final String USER_PREFERENCES = MainActivity .class .getPackage ().getName ().concat ("_userPrefs" );
31
31
public static final String KEY_SAVED_USER_NAME = "userName" ;
32
32
public static final String KEY_USER = "user" ;
33
33
public static final String KEY_LEVELS = "levels" ;
34
34
public static final String TAG_WELCOME_FRAGMENT = "welcome_fragment" ;
35
35
public static final String TAG_MAIN_MENU_FRAGMENT = "main_menu_fragment" ;
36
+ public static final String TAG_GAME_FRAGMENT = "game_fragment" ;
36
37
private static final String COLLECTION_NAME = "users" ;
37
38
public static final int LAUNCH_SECOND_ACTIVITY = 1 ;
38
39
39
-
40
40
private ActivityMainBinding binding ;
41
41
42
42
/** Member vars for the game */
@@ -47,10 +47,10 @@ public class MainActivity extends AppCompatActivity implements Repository.Entity
47
47
/** Member vars for fragments of this activity */
48
48
private WelcomeFragment welcomeFragment ;
49
49
private MainMenuFragment mainMenuFragment ;
50
+ private GameFragment gameFragment ;
50
51
51
52
private Repository mRepository ;
52
53
53
-
54
54
@ Override
55
55
protected void onCreate (Bundle savedInstanceState ) {
56
56
super .onCreate (savedInstanceState );
@@ -98,6 +98,20 @@ private void initMainMenuFragment(){
98
98
99
99
}
100
100
101
+ private void initGameFragment (){
102
+ Timber .i ("Initializing GameFragment" );
103
+ Bundle bundle = new Bundle ();
104
+ bundle .putParcelable (KEY_USER , mUser );
105
+ bundle .putParcelableArrayList (KEY_LEVELS , (ArrayList <? extends Parcelable >) mLevels );
106
+ FragmentManager fragmentManager = getSupportFragmentManager ();
107
+ FragmentTransaction ft = fragmentManager .beginTransaction ();
108
+ gameFragment = new GameFragment ();
109
+ gameFragment .setArguments (bundle );
110
+ ft .replace (R .id .container_game , gameFragment , TAG_GAME_FRAGMENT );
111
+ ft .addToBackStack (TAG_GAME_FRAGMENT );
112
+ ft .commit ();
113
+ }
114
+
101
115
/** This method is defined in the WelcomeFragment to let retrieve data from it */
102
116
@ Override
103
117
public void onSetupFinished (User user , List <Level > levels ) {
@@ -111,7 +125,21 @@ public void onSetupFinished(User user, List<Level> levels) {
111
125
/** This method is defined in the MainMenuFragment to let retrieve data from it */
112
126
@ Override
113
127
public void onStartGameClicked () {
128
+ //todo: start gameFragment with fields
129
+ if (!mainMenuFragment .isHidden ()) showHideFragment (mainMenuFragment );
130
+ initGameFragment ();
131
+ }
132
+ /** This method is defined in the MainMenuFragment to let retrieve data from it */
133
+ @ Override
134
+ public void onLeaderboardClicked () {
135
+ //todo: start LeaderBoardActivity with fields
136
+
137
+ }
114
138
139
+ /** This method is defined in the GameFragment to let retrieve data from it */
140
+ @ Override
141
+ public void onSubmitClicked () {
142
+ //todo: get the Question: points, answered and Level:
115
143
}
116
144
117
145
/** This ends the WelcomeFragment permanently */
0 commit comments