2
2
3
3
import android .animation .Animator ;
4
4
import android .annotation .SuppressLint ;
5
+ import android .app .Dialog ;
5
6
import android .os .Bundle ;
6
7
import android .os .CountDownTimer ;
7
8
import android .os .Handler ;
@@ -56,7 +57,7 @@ public class MainActivity extends AppCompatActivity implements Constants {
56
57
boolean appRunning = false ;
57
58
58
59
long timeLimit ;
59
-
60
+ Dialog dialog ;
60
61
Map map ;
61
62
ViewPager bottomPager ;
62
63
private boolean areOverlaysShown = true ;
@@ -70,6 +71,7 @@ public class MainActivity extends AppCompatActivity implements Constants {
70
71
ArrayList <LatLng > levelLatLng ;
71
72
72
73
Thread timer ;
74
+ private boolean blocked = false ;
73
75
74
76
@ Override
75
77
protected void onCreate (Bundle savedInstanceState ) {
@@ -106,6 +108,11 @@ protected int getHorizontalSnapPreference() {
106
108
}
107
109
};
108
110
coupleId = new SharedPrefManager (this ).getCoupleId ();
111
+
112
+ dialog = new Dialog (MainActivity .this );
113
+ dialog .setContentView (R .layout .dialog_complete );
114
+ dialog .setCancelable (false );
115
+ dialog .setCanceledOnTouchOutside (false );
109
116
}
110
117
111
118
@@ -130,30 +137,31 @@ public void onCoupleFetched(Couple couple) {
130
137
attachCoupleListener ();
131
138
ViewUtils .removeDialog ();
132
139
startTimer ();
133
-
134
- if (!currentCouple .isEnabled ()) {
135
- if (ViewUtils .completeShowing ) {
136
- ViewUtils .removeDialog ();
137
- ViewUtils .completeShowing = false ;
138
- }
139
- } else {
140
- ViewUtils .showCompleteDialog (MainActivity .this );
141
- }
142
-
143
-
140
+ // if (!currentCouple.isEnabled()) {
141
+ // dialog.show();
142
+ // blocked = true;
143
+ // } else {
144
+ // if(blocked){
145
+ // dialog.cancel();
146
+ // blocked = false;
147
+ // }
148
+ // }
144
149
FirebaseDatabase .getInstance ().getReference ().child ("settings" ).child ("gameRunning" ).addValueEventListener (new ValueEventListener () {
145
150
@ Override
146
151
public void onDataChange (@ NonNull DataSnapshot dataSnapshot ) {
147
152
Log .i (TAG , "onDataChange: " );
148
153
if (dataSnapshot != null && dataSnapshot .getValue () != null ) {
149
154
boolean gameRunning = dataSnapshot .getValue (Boolean .class );
150
155
if (gameRunning ) {
156
+
151
157
if (ViewUtils .completeShowing ) {
152
158
ViewUtils .removeDialog ();
153
159
ViewUtils .completeShowing = false ;
154
160
}
155
161
} else {
156
- ViewUtils .showCompleteDialog (MainActivity .this );
162
+
163
+ if (!ViewUtils .completeShowing )
164
+ ViewUtils .showCompleteDialog (MainActivity .this );
157
165
}
158
166
}
159
167
}
@@ -175,8 +183,6 @@ public void onErrorOccured(String message) {
175
183
new CoupleManager (MainActivity .this ).syncWithServer (this );
176
184
ViewUtils .showToast (MainActivity .this , "Some error occured!" , ViewUtils .DURATION_SHORT );
177
185
}
178
-
179
-
180
186
levelRecycler .setLayoutManager (linearLayoutManagerThree );
181
187
levelRecycler .setHasFixedSize (true );
182
188
levelRecycler .setLayoutFrozen (true );
@@ -212,7 +218,6 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
212
218
if (dataSnapshot != null && dataSnapshot .getValue () != null )
213
219
setCurrentCouple (dataSnapshot .getValue (Couple .class ));
214
220
}
215
-
216
221
@ Override
217
222
public void onCancelled (@ NonNull DatabaseError databaseError ) {
218
223
@@ -258,14 +263,15 @@ public void setCurrentCouple(Couple currentCouple) {
258
263
bottomPager .setCurrentItem (currentCouple .getCurrentLevel () - 1 , true );
259
264
refreshMap ();
260
265
261
- if (!currentCouple .isEnabled ()) {
262
- ViewUtils .showCompleteDialog (MainActivity .this );
263
- } else {
264
- if (ViewUtils .completeShowing ) {
265
- ViewUtils .removeDialog ();
266
- ViewUtils .completeShowing = false ;
267
- }
268
- }
266
+ // if (!currentCouple.isEnabled() && !blocked) {
267
+ // dialog.show();
268
+ // blocked = true;
269
+ // } else {
270
+ // if (blocked) {
271
+ // dialog.cancel();
272
+ // blocked = false;
273
+ // }
274
+ // }
269
275
270
276
currentLevel = currentCouple .getCurrentLevel ();
271
277
new Handler ().postDelayed (new Runnable () {
@@ -422,6 +428,18 @@ protected void onPause() {
422
428
map .disableGPS ();
423
429
appRunning = false ;
424
430
Log .i (TAG , "onPause: " );
431
+ new CoupleManager (MainActivity .this ).getCouple ().setOnFetchedListener (new CoupleManager .OnFetchedListener () {
432
+ @ Override
433
+ public void onCoupleFetched (Couple couple ) {
434
+ couple .setEnabled (false );
435
+ couplesRef .child (couple .getId ()).setValue (couple );
436
+ }
437
+
438
+ @ Override
439
+ public void onErrorOccured (String message ) {
440
+
441
+ }
442
+ });
425
443
}
426
444
427
445
@ Override
0 commit comments