Skip to content

Commit 61c32b4

Browse files
committed
Fixed merge conflict
2 parents 973bbce + a058636 commit 61c32b4

26 files changed

+438
-152
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ captures/
4040
*.jks
4141

4242
.DS_Store
43+
44+
/app/google-services.json

app/src/main/java/website/bloop/app/BloopApplication.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import website.bloop.app.api.Player;
1919

2020
/**
21-
*
21+
* Application to store the Google services instance, as well as the Bloop services instance.
22+
* Includes misc other methods to make player getting and similar easier for other classes/methods.
23+
* Functions similarly to a singleton.
2224
*/
2325
public class BloopApplication extends Application {
2426
private static BloopApplication mInstance = null;

app/src/main/java/website/bloop/app/BloopFirebaseInstanceIDService.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
import static website.bloop.app.BloopApplication.BLOOP_PREFERENCE_FILE;
1010

11+
/**
12+
* Firebase ID service which is used for push notifications and registering this app instance
13+
* with Firebase.
14+
*/
1115
public class BloopFirebaseInstanceIDService extends FirebaseInstanceIdService {
1216

1317
private static final String TAG = "BloopFirebaseIIDService";

app/src/main/java/website/bloop/app/BloopFirebaseMessagingService.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* TODO: Add a class header comment!
77
*/
88

9+
/**
10+
* Push notification logic with Firebase.
11+
*/
912
public class BloopFirebaseMessagingService extends FirebaseMessagingService {
1013

1114
private static final String TAG = "BloopFirebaseMsgService";

app/src/main/java/website/bloop/app/LocationModel.java

-30
This file was deleted.

app/src/main/java/website/bloop/app/activities/BloopActivity.java

+123-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package website.bloop.app.activities;
22

3-
import android.app.Activity;
43
import android.content.Context;
54
import android.content.Intent;
65
import android.content.SharedPreferences;
@@ -10,14 +9,15 @@
109
import android.support.design.widget.FloatingActionButton;
1110
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
1211
import android.support.v4.view.animation.PathInterpolatorCompat;
13-
import android.support.v7.app.AlertDialog;
1412
import android.support.v7.app.AppCompatActivity;
1513
import android.support.v7.widget.Toolbar;
1614
import android.util.Log;
1715
import android.view.Menu;
1816
import android.view.MenuInflater;
1917
import android.view.MenuItem;
18+
import android.view.View;
2019
import android.widget.RelativeLayout;
20+
import android.widget.Toast;
2121

2222
import com.google.android.gms.common.api.GoogleApiClient;
2323
import com.google.android.gms.games.Games;
@@ -37,19 +37,24 @@
3737
import website.bloop.app.R;
3838
import website.bloop.app.api.BloopAPIService;
3939
import website.bloop.app.api.CapturedFlag;
40+
import website.bloop.app.api.NearbyFlag;
4041
import website.bloop.app.api.PlayerLocation;
42+
import website.bloop.app.dialogs.FlagCapturedDialogFragment;
4143
import website.bloop.app.fragments.BootprintMapFragment;
4244
import website.bloop.app.sound.BloopSoundPlayer;
4345
import website.bloop.app.views.BigButtonView;
46+
import website.bloop.app.views.FlagView;
4447
import website.bloop.app.views.SonarView;
4548

4649
/**
47-
*
50+
* Main game activity, which shows bloop animations and sounds, as well as controls
51+
* game interaction such as capturing bloops or checking the leaderboards.
4852
*/
4953
public class BloopActivity extends AppCompatActivity {
5054
private static final String PREF_SOUND = "MutePREF";
5155
private static final String PREF_SOUND_VAL = "muted";
5256
private static final String TAG = "BloopActivity";
57+
private static final String FLAG_CAPTURED_DIALOG_TAG = "FlagDialog";
5358
private static final long LOCATION_UPDATE_MS = 5000;
5459
private static final int REQUEST_LEADERBOARD = 1000;
5560

@@ -82,8 +87,7 @@ public class BloopActivity extends AppCompatActivity {
8287
private long mLastBloopTime;
8388
private Runnable mBloopRunnable;
8489

85-
private long mNearbyFlagId;
86-
private String mNearbyFlagOwner;
90+
private NearbyFlag mNearbyFlag;
8791

8892
private GoogleApiClient mGoogleApiClient;
8993
private BloopAPIService mService;
@@ -117,7 +121,7 @@ protected void onCreate(Bundle savedInstanceState) {
117121
// hide flag by default
118122
mPlaceFlagButtonMarginBottom = getResources().getDimension(R.dimen.fab_margin);
119123
// TODO: this doesn't actually animate the fab far enough
120-
mPlaceFlagButton.setTranslationY(mPlaceFlagButton.getHeight() + mPlaceFlagButtonMarginBottom);
124+
mPlaceFlagButton.setVisibility(View.INVISIBLE);
121125

122126
mService.checkHasPlacedFlag(mApplication.getPlayerId())
123127
.subscribeOn(Schedulers.newThread())
@@ -154,6 +158,9 @@ protected void onCreate(Bundle savedInstanceState) {
154158
mute = mutePref.getBoolean(PREF_SOUND_VAL, false);
155159
}
156160

161+
/**
162+
* Hide the fab and blocking the ability to place a flag.
163+
*/
157164
private void hidePlaceFlag() {
158165
mPlaceFlagButton
159166
.animate()
@@ -163,7 +170,20 @@ private void hidePlaceFlag() {
163170
.start();
164171
}
165172

173+
/**
174+
* Show the fab and add the ability to place a flag.
175+
*/
166176
private void showPlaceFlag() {
177+
// if we have set the visibility to invisible (as we do in onCreate), we should put this
178+
// below the screen
179+
if (mPlaceFlagButton.getVisibility() == View.INVISIBLE) {
180+
mPlaceFlagButton.setTranslationY(
181+
mPlaceFlagButton.getHeight() + mPlaceFlagButtonMarginBottom
182+
);
183+
184+
mPlaceFlagButton.setVisibility(View.VISIBLE);
185+
}
186+
167187
mPlaceFlagButton
168188
.animate()
169189
.translationY(0)
@@ -172,13 +192,17 @@ private void showPlaceFlag() {
172192
.start();
173193
}
174194

195+
/**
196+
* Draw a different bloop over the main bloops to prompt the user to click and capture a flag.
197+
*/
175198
private void captureFlag() {
176-
if (mNearbyFlagId != 0) {
177-
CapturedFlag flag = new CapturedFlag(mNearbyFlagId, mApplication.getPlayerId());
178-
179-
String requestedFlagOwner = mNearbyFlagOwner;
199+
if (mNearbyFlag != null) {
200+
CapturedFlag flag = new CapturedFlag(
201+
mNearbyFlag.getFlagId(),
202+
mApplication.getPlayerId()
203+
);
180204

181-
Activity self = this;
205+
// TODO: slowly mute the boop sounds so the bloop is better
182206

183207
mService.captureFlag(flag)
184208
.subscribeOn(Schedulers.newThread())
@@ -189,22 +213,65 @@ private void captureFlag() {
189213
mBloopSoundPlayer.bloop();
190214
}
191215

192-
final AlertDialog.Builder builder = new AlertDialog.Builder(self);
193-
builder.setTitle(String.format(getString(R.string.you_captured_x_flag_format_string), requestedFlagOwner))
194-
.setMessage("Add one more to that collection")
195-
.setNeutralButton(
196-
getString(R.string.dismiss_capture_flag_dialog_text),
197-
(dialogInterface, i) -> dialogInterface.dismiss())
198-
.show();
216+
final FlagView flagView = new FlagView(getBaseContext());
217+
flagView.setFlagColor(mNearbyFlag.getColor());
218+
219+
final FlagCapturedDialogFragment flagCapturedDialog = new FlagCapturedDialogFragment();
220+
final Bundle flagCapturedDialogBundle = new Bundle();
221+
flagCapturedDialogBundle.putString(
222+
FlagCapturedDialogFragment.ARG_TITLE,
223+
String.format(getString(R.string.you_captured_x_flag_format_string), mNearbyFlag.getPlayerName())
224+
);
225+
226+
flagCapturedDialogBundle.putInt(
227+
FlagCapturedDialogFragment.ARG_FLAG_COLOR,
228+
mNearbyFlag.getColor()
229+
);
230+
231+
flagCapturedDialogBundle.putString(
232+
FlagCapturedDialogFragment.ARG_POINTS_TEXT,
233+
"Flag capture: +1 point"
234+
);
235+
236+
final int playerScore = 1; // TODO: from API
237+
238+
flagCapturedDialogBundle.putString(
239+
FlagCapturedDialogFragment.ARG_TOTAL_SCORE,
240+
"Score: " + playerScore
241+
);
242+
243+
Games.Leaderboards.submitScore(
244+
mGoogleApiClient,
245+
getString(R.string.leaderboard_bloop_high_scores),
246+
playerScore
247+
);
248+
249+
flagCapturedDialog.setArguments(flagCapturedDialogBundle);
250+
flagCapturedDialog.show(getSupportFragmentManager(), "FlagDialog");
251+
199252
mBigButtonView.hide();
200253
}, throwable -> {
254+
Log.e(TAG, throwable.getMessage());
201255
mBigButtonView.hide();
202256
});
203257
}
204258
}
205259

260+
private void deleteFlag() {
261+
mService.deleteFlag(mApplication.getPlayerId())
262+
.subscribeOn(Schedulers.newThread())
263+
.observeOn(AndroidSchedulers.mainThread())
264+
.subscribe(ownFlag -> {
265+
Toast.makeText(this, "Flag deleted", Toast.LENGTH_SHORT).show();
266+
}, throwable -> {
267+
Log.e(TAG, throwable.getMessage());
268+
});
269+
270+
showPlaceFlag();
271+
}
272+
206273
/**
207-
* Shows an activity that describes the open source libraries used in this project
274+
* Shows an activity that describes the open source libraries used in this project.
208275
*/
209276
private void startAboutLibraries() {
210277
new LibsBuilder()
@@ -214,6 +281,10 @@ private void startAboutLibraries() {
214281
.start(this);
215282
}
216283

284+
/**
285+
* Request location permissions so we can track location.
286+
* @return
287+
*/
217288
private Observable<Boolean> requestLocationPermissions() {
218289
return RxPermissions.getInstance(this)
219290
.request(android.Manifest.permission.ACCESS_FINE_LOCATION)
@@ -222,6 +293,9 @@ private Observable<Boolean> requestLocationPermissions() {
222293
});
223294
}
224295

296+
/**
297+
* Main location tracking logic.
298+
*/
225299
private void startTrackingLocation() {
226300
Log.d(TAG, "Location tracking started");
227301

@@ -233,24 +307,31 @@ private void startTrackingLocation() {
233307
// this should never be called if the permission hasn't been granted.
234308
//noinspection MissingPermission
235309
mLocationDisposable = mRxLocation.location().updates(locationRequest)
236-
//TODO: we might want to clean this data before passing it on
237310
.doOnEach(location -> mCurrentLocation = location.getValue())
238311
.doOnEach(location -> mBootprintMapFragment.updateMapCenter(location.getValue()))
239312
.doOnEach(location -> mBootprintMapFragment.updatePlayerLocation(location.getValue()))
240313
.doOnEach(location -> updateBloopFrequency())
241314
.subscribe();
242315
}
243316

317+
/**
318+
* Lets a user customize and place a flag at their current location.
319+
* Passes intent to FlagCreationActivity.
320+
*/
244321
private void placeFlag() {
245322
if (mCurrentLocation != null) {
246-
// TODO organize bloop and placing flag better
247323

248324
final Intent placeFlagIntent = new Intent(this, FlagCreationActivity.class);
249325
placeFlagIntent.putExtra(FlagCreationActivity.FLAG_LOCATION, mCurrentLocation);
250326
startActivity(placeFlagIntent);
327+
328+
hidePlaceFlag();
251329
}
252330
}
253331

332+
/**
333+
* Check with server to compute closest flag and update how often bloops are animated on-screen.
334+
*/
254335
private void updateBloopFrequency() {
255336
if (mCurrentLocation != null) {
256337
mService.getNearestFlag(
@@ -265,13 +346,11 @@ private void updateBloopFrequency() {
265346
// if player name is present, that means that there is a flag a
266347
// capturable distance away
267348
// TODO: alert the user that they can capture this flag
268-
mNearbyFlagId = nearbyFlag.getFlagId();
269-
mNearbyFlagOwner = nearbyFlag.getPlayerName();
349+
mNearbyFlag = nearbyFlag;
270350

271351
mBigButtonView.show();
272352
} else {
273-
mNearbyFlagId = 0; // this is the "null" value of the flag id
274-
mNearbyFlagOwner = null;
353+
mNearbyFlag = null;
275354
mBigButtonView.hide();
276355
}
277356

@@ -280,6 +359,9 @@ private void updateBloopFrequency() {
280359
}
281360
}
282361

362+
/**
363+
* Actually reschedule the "timer" to redraw a bloop on screen.
364+
*/
283365
private void rescheduleBloops() {
284366
double timeSinceLastBloop = (double) (System.currentTimeMillis() - mLastBloopTime);
285367

@@ -323,6 +405,9 @@ public void run() {
323405
}
324406
}
325407

408+
/**
409+
* BLOOP!!!
410+
*/
326411
private void bloop() {
327412
mSonarView.bloop();
328413
if (!mute) {
@@ -332,6 +417,11 @@ private void bloop() {
332417
mLastBloopTime = System.currentTimeMillis();
333418
}
334419

420+
/**
421+
* Inflate options dropdown, as well as set mute checkbox to preexisting value, if one available.
422+
* @param menu
423+
* @return
424+
*/
335425
public boolean onCreateOptionsMenu(Menu menu) {
336426
MenuInflater inflater = getMenuInflater();
337427
inflater.inflate(R.menu.bloop_activity_menu, menu);
@@ -343,6 +433,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
343433
return true;
344434
}
345435

436+
/**
437+
* Show leaderboards, mute audio, show library information.
438+
* @param item
439+
* @return
440+
*/
346441
@Override
347442
public boolean onOptionsItemSelected(MenuItem item) {
348443
// Handle item selection
@@ -356,6 +451,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
356451
REQUEST_LEADERBOARD
357452
);
358453
return true;
454+
case R.id.item_delete:
455+
deleteFlag();
456+
return true;
359457
case R.id.item_mute:
360458
SharedPreferences.Editor ed = mutePref.edit();
361459
if (!mute) {

0 commit comments

Comments
 (0)