From 415d52a1441d06d2a4f4d24dcb701e73bc898b73 Mon Sep 17 00:00:00 2001 From: Sarah Fisher Date: Fri, 22 Nov 2019 09:18:16 -0800 Subject: [PATCH 1/5] Adding notes to the code --- .../com/javaawesome/tag/MainActivity.java | 50 ++++--------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/javaawesome/tag/MainActivity.java b/app/src/main/java/com/javaawesome/tag/MainActivity.java index e42e3f5..bf7fefb 100644 --- a/app/src/main/java/com/javaawesome/tag/MainActivity.java +++ b/app/src/main/java/com/javaawesome/tag/MainActivity.java @@ -6,8 +6,6 @@ import androidx.core.app.ActivityCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; - -import android.Manifest; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -18,12 +16,10 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.provider.Settings; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.Toast; - import com.amazonaws.amplify.generated.graphql.CreatePlayerMutation; import com.amazonaws.amplify.generated.graphql.CreateSessionMutation; import com.amazonaws.amplify.generated.graphql.ListPlayersQuery; @@ -72,14 +68,19 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + //Transfer service registers a listener with Android OS for network connectivity changes + //If the network goes offline, the active transfers are paused + //Active transfers resume when the nextwork comes back online + //Works in the foreground and the background getApplicationContext().startService(new Intent(getApplicationContext(), TransferService.class)); + //If the app does not have course or fine location permission request them if (this.checkSelfPermission(ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED || this.checkSelfPermission(ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}, 10); } - // initialize aws mobile client and check if you are logged in or not + //Initialize AWS mobile client and check if the player is logged in AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback() { @Override public void onResult(UserStateDetails result) { @@ -95,19 +96,19 @@ public void onError(Exception e) { } }); - // connect to AWS + //Connect to AWS awsAppSyncClient = AWSAppSyncClient.builder() .context(getApplicationContext()) .awsConfiguration(new AWSConfiguration(getApplicationContext())) .build(); - // initialize client for google location services + //Initialize client for google location services fusedLocationClient = LocationServices.getFusedLocationProviderClient(this); + //Initialize a new Linked List of game sessions sessions = new LinkedList<>(); - // initialize recycler view to display nearby game sessions - // TODO: have recycler view filter sessions by distance to user + //Initialize a recycler view to display game sessions within the defined distance of the player's location recyclerNearbySessions = findViewById(R.id.recycler_nearby_sessions); recyclerNearbySessions.setLayoutManager(new LinearLayoutManager(this)); this.sessionAdapter = new SessionAdapter(this.sessions, this); @@ -117,9 +118,8 @@ public void onError(Exception e) { @Override protected void onResume() { super.onResume(); - Log.i(TAG, "onresume called"); + Log.i(TAG, "onResume called"); if (checkGpsStatus()) { -// getCurrentUserLocation(); checkIfPlayerAlreadyExistInDatabase(); } else { buildAlertMessageNoGps(); @@ -203,34 +203,6 @@ public void joinExistingGameSession(ListSessionsQuery.Item session) { this.startActivity(goToMapIntent); } -// @Override -// public void addPlayerToChosenGame(final ListSessionsQuery.Item session) { -//// Query -// CreatePlayerInput playerInput = CreatePlayerInput.builder() -// .playerSessionId(session.id()) -// .isIt(false) -// .lat(currentUserLocation.latitude) -// .lon(currentUserLocation.longitude) -// .username(AWSMobileClient.getInstance().getUsername()) -// .build(); -// CreatePlayerMutation createPlayerMutation = CreatePlayerMutation.builder().input(playerInput).build(); -// awsAppSyncClient.mutate(createPlayerMutation).enqueue((new GraphQLCall.Callback() { -// @Override -// public void onResponse(@Nonnull Response response) { -// String userID = response.data().createPlayer().id(); -// Log.i(TAG, "player mutation happened! ... inside of a session mutation"); -// Intent goToMapIntent = new Intent(MainActivity.this, MapsActivity.class); -// goToMapIntent.putExtra("sessionId", session.id()); -// goToMapIntent.putExtra("userID", userID); -// Log.i("veach", session.id() + "\n" +userID); -// } -// @Override -// public void onFailure(@Nonnull ApolloException e) { -// Log.i(TAG, "mutation of player failed, boohoo!"); -// } -// })); -// } - // get all sessions private void queryAllSessions() { Log.i(TAG, "query all sessions"); From 7fa87d7fc15f72e2e2c3f94cc1bb3bbfd57a5f18 Mon Sep 17 00:00:00 2001 From: Sarah Fisher Date: Fri, 22 Nov 2019 09:31:39 -0800 Subject: [PATCH 2/5] Continuing to add comments. Saving to pull in new Dev version --- .../main/java/com/javaawesome/tag/MainActivity.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/javaawesome/tag/MainActivity.java b/app/src/main/java/com/javaawesome/tag/MainActivity.java index bf7fefb..9b5291f 100644 --- a/app/src/main/java/com/javaawesome/tag/MainActivity.java +++ b/app/src/main/java/com/javaawesome/tag/MainActivity.java @@ -119,14 +119,17 @@ public void onError(Exception e) { protected void onResume() { super.onResume(); Log.i(TAG, "onResume called"); + //If checkGpsStatus returns true to verify that the player's phone has GPS is turned on if (checkGpsStatus()) { + //Check if the player is already in the database checkIfPlayerAlreadyExistInDatabase(); } else { + //Ask the player if they want to turn on their GPS to play buildAlertMessageNoGps(); } } - // Create new game session and go to map page + //Create a new game session and go to map page public void goToMap(View view) { // TODO: check if player already exist in the database EditText sessionName = findViewById(R.id.editText_session_name); @@ -165,16 +168,11 @@ public void goToUserPage(View view){ this.startActivity(goToUserPage); } - //////// TEST BUTTON ///// - public void onTestyClick(View view) { - startActivity(new Intent(MainActivity.this, NotificationActivity.class)); - } - // Direct users to sign in page private void signInUser() { AWSMobileClient.getInstance().showSignIn(MainActivity.this, // customize the built in sign in page - SignInUIOptions.builder().backgroundColor(16763080).logo(R.drawable.zombieicon).build(), + SignInUIOptions.builder().backgroundColor(16763080).logo(R.mipmap.ic_launcher_round).build(), new Callback() { @Override public void onResult(UserStateDetails result) { From 0f2ae3638afd9348bee9dbb0c9ee2ef0415138cb Mon Sep 17 00:00:00 2001 From: Sarah Fisher Date: Fri, 22 Nov 2019 11:01:06 -0800 Subject: [PATCH 3/5] Saving comments to pull in Dev update --- .../com/javaawesome/tag/MainActivity.java | 49 ++++++++++--------- .../com/javaawesome/tag/MapsActivity.java | 46 +++++++---------- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/javaawesome/tag/MainActivity.java b/app/src/main/java/com/javaawesome/tag/MainActivity.java index 9b5291f..c78a8d3 100644 --- a/app/src/main/java/com/javaawesome/tag/MainActivity.java +++ b/app/src/main/java/com/javaawesome/tag/MainActivity.java @@ -129,7 +129,7 @@ protected void onResume() { } } - //Create a new game session and go to map page + //Create a new game session and transfer the player to the games' map page public void goToMap(View view) { // TODO: check if player already exist in the database EditText sessionName = findViewById(R.id.editText_session_name); @@ -154,29 +154,31 @@ public void onResponse(@Nonnull Response response) { @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "error in creating new game session" + e.getMessage()); + Log.e(TAG, "Error in creating new game session" + e.getMessage()); } }); + + //Send prompt to player that a session name is required before creating the new game }else{ Toast.makeText(getBaseContext(), "Please enter a session title.",Toast.LENGTH_LONG).show(); } } - ///////////// Go to user page /////////////////// + //Go to user page when the zombie icon is clicked public void goToUserPage(View view){ Intent goToUserPage = new Intent(this, UserProfile.class); this.startActivity(goToUserPage); } - // Direct users to sign in page + //Show the signin page if the player is not signed in when they open the app private void signInUser() { AWSMobileClient.getInstance().showSignIn(MainActivity.this, - // customize the built in sign in page + //Customize the built-in signin page with the defined theme color and icon SignInUIOptions.builder().backgroundColor(16763080).logo(R.mipmap.ic_launcher_round).build(), new Callback() { @Override public void onResult(UserStateDetails result) { - Log.i(TAG, "successfully show signed in page"); + Log.i(TAG, "Successfully show signed in page"); } @Override @@ -186,13 +188,13 @@ public void onError(Exception e) { }); } - // sign out user and show them sign in page + //Sign out the player and show them the signin page public void signoutCurrentUser(View view) { AWSMobileClient.getInstance().signOut(); signInUser(); } - // onclick method for button to join existing game sessions + //onclick method for player to join an existing game session @Override public void joinExistingGameSession(ListSessionsQuery.Item session) { Intent goToMapIntent = new Intent(this, MapsActivity.class); @@ -201,7 +203,7 @@ public void joinExistingGameSession(ListSessionsQuery.Item session) { this.startActivity(goToMapIntent); } - // get all sessions + //Get all sessions from the database private void queryAllSessions() { Log.i(TAG, "query all sessions"); awsAppSyncClient.query(ListSessionsQuery.builder().build()) @@ -209,7 +211,7 @@ private void queryAllSessions() { .enqueue(getAllSessionsCallBack); } - // Callback to update the list of sessions and recycler view that displays them + //Callback to update the list of sessions and recycler view that displays them private GraphQLCall.Callback getAllSessionsCallBack = new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull final Response response) { @@ -231,9 +233,9 @@ public void onFailure(@Nonnull ApolloException e) { } }; - // get current user location + //Get current player location private void getCurrentUserLocation() { - Log.i(TAG, "called getCurrentUserLocation"); + Log.i(TAG, "Called getCurrentUserLocation"); fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener() { @Override public void onSuccess(final Location location) { @@ -244,7 +246,7 @@ public void onSuccess(final Location location) { public void run() { currentUserLocation = new LatLng(location.getLatitude(), location.getLongitude()); queryAllSessions(); - Log.i(TAG, "playerId in getcurrentUserlocation " + playerId); + Log.i(TAG, "PlayerId in getcurrentUserlocation " + playerId); if (playerId == null) { createPlayer(); } @@ -260,9 +262,7 @@ public void onFailure(@NonNull Exception e) { }); } - // TODO: Build onDestroy that deletes user data from DB - - + //Check if the player's username is already in the database private void checkIfPlayerAlreadyExistInDatabase() { awsAppSyncClient.query(ListPlayersQuery.builder().build()) .responseFetcher(AppSyncResponseFetchers.NETWORK_ONLY) @@ -285,12 +285,12 @@ public void onResponse(@Nonnull Response response) { @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "error in checking if a player already exists in database"); + Log.e(TAG, "Error in checking if a player already exists in database"); } }); } - // Make a Player + //Make a new player using their location, username, and start them as not it (human) private void createPlayer() { CreatePlayerInput input = CreatePlayerInput.builder() .lat(currentUserLocation.latitude) @@ -302,23 +302,24 @@ private void createPlayer() { awsAppSyncClient.mutate(createPlayerMutation).enqueue(new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull Response response) { - Log.i(TAG, "created a player"); + Log.i(TAG, "Created a player"); playerId = response.data().createPlayer().id(); } @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "error in creating new player"); + Log.e(TAG, "Error in creating new player"); } }); } - // Checks if Gps Location is turned on or not on the user's phone + //Checks if GPS Location is turned on or not on the user's phone private boolean checkGpsStatus() { locationManager = (LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } + //Prompt the player that their GPS is not enabled and to turn it on to play private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Your GPS is disabled, do you want to enable it?") @@ -337,7 +338,7 @@ public void onClick(final DialogInterface dialog, final int id) { alert.show(); } - // filter out list of sessions to a smaller list that consist of sessions nearby the player's location + //Filter the sessions fed to the recyclerView so the player only sees games within a defined distance from their location private List filterSessionsBasedOnDistance(List allSessions) { List filteredSessions = new LinkedList<>(); for (ListSessionsQuery.Item session : allSessions) { @@ -351,4 +352,8 @@ private List filterSessionsBasedOnDistance(List() { @Override public void onResponse(@Nonnull Response response) { - Log.i(TAG, "update success"); + Log.i(TAG, "Update successful"); } @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "update not successful"); + Log.e(TAG, "Update not successful"); } }); } + //Associate the player with the game session private void associateUserWithSession() { - Log.i(TAG, "player being sent " + (player == null ? "null" : player.toString())); + Log.i(TAG, "Player being sent " + (player == null ? "null" : player.toString())); UpdatePlayerInput updatePlayerInput = UpdatePlayerInput.builder() .id(playerID) .playerSessionId(sessionId) @@ -182,22 +175,21 @@ private void associateUserWithSession() { .enqueue(new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull Response response) { - Log.i(TAG, "update success"); + Log.i(TAG, "Update successful"); queryForSelectedSession(sessionId); } @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "update not successful"); + Log.e(TAG, "Update not successful"); } }); } - // ===== Subscribe to Data real-time ====== + //Subscribe to the database data close to real-time // https://aws-amplify.github.io/docs/android/api private void subscribe() { - OnUpdatePlayerSubscription subscription = OnUpdatePlayerSubscription.builder().build(); subscriptionWatcher = awsAppSyncClient.subscribe(subscription); subscriptionWatcher.execute(subCallback); @@ -206,12 +198,12 @@ private void subscribe() { private AppSyncSubscriptionCall.Callback subCallback = new AppSyncSubscriptionCall.Callback() { @Override public void onResponse(@Nonnull final Response response) { - Log.i(TAG, "************* !!!! *******" + response.data().toString()); + Log.i(TAG, "Subscription subCallback " + response.data().toString()); Handler h = new Handler(Looper.getMainLooper()) { @Override public void handleMessage (Message inputMessage) { - // Iterate over the players on the map + //Iterate over the players in the session //TODO: if session matches; then if player in players update location, else make a new player and add their marker. OnUpdatePlayerSubscription.OnUpdatePlayer updatePlayer = response.data().onUpdatePlayer(); From 3841ab7160cf554ba536e58fa6011a249e798a26 Mon Sep 17 00:00:00 2001 From: Sarah Fisher Date: Fri, 22 Nov 2019 11:33:03 -0800 Subject: [PATCH 4/5] Committing message updates before moving to Dev --- .../main/java/com/javaawesome/tag/MapsActivity.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/src/main/java/com/javaawesome/tag/MapsActivity.java b/app/src/main/java/com/javaawesome/tag/MapsActivity.java index 18fad1e..6d9c33d 100644 --- a/app/src/main/java/com/javaawesome/tag/MapsActivity.java +++ b/app/src/main/java/com/javaawesome/tag/MapsActivity.java @@ -254,18 +254,6 @@ public void handleMessage (Message inputMessage) { players.add(newPlayer); } } -// for(Player player : players) { -// if(response.data().onUpdatePlayer().id().equals(player.getId())) { -// // if true (we have a match) update players lat/long -// List bananasList = new LinkedList<>(); -// bananasList.add(new LatLng(response.data().onUpdatePlayer().lat(), -// response.data().onUpdatePlayer().lon())); -// player.setLocations(bananasList); // sets location for the player -// //Might have been causing the starting point to move -//// player.getCircle().setCenter(player.getLastLocation()); -//// player.getMarker().setPosition(player.getLastLocation()); -// } -// } } }; h.obtainMessage().sendToTarget(); From 46e3b6f5ab3f36158a35a1742c46d3ec9f0973e7 Mon Sep 17 00:00:00 2001 From: Sarah Fisher Date: Sun, 24 Nov 2019 10:42:18 -0800 Subject: [PATCH 5/5] Comments and zombie code --- .../com/javaawesome/tag/MainActivity.java | 8 -- .../com/javaawesome/tag/MapsActivity.java | 123 ++++++------------ 2 files changed, 43 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/com/javaawesome/tag/MainActivity.java b/app/src/main/java/com/javaawesome/tag/MainActivity.java index 908529a..20c435b 100644 --- a/app/src/main/java/com/javaawesome/tag/MainActivity.java +++ b/app/src/main/java/com/javaawesome/tag/MainActivity.java @@ -118,7 +118,6 @@ public void onError(Exception e) { @Override protected void onResume() { super.onResume(); - Log.i(TAG, "onResume called"); //If checkGpsStatus returns true to verify that the player's phone has GPS is turned on if (checkGpsStatus()) { //Check if the player is already in the database @@ -133,7 +132,6 @@ protected void onResume() { public void goToMap(View view) { // TODO: check if player already exist in the database EditText sessionName = findViewById(R.id.editText_session_name); - Log.i(TAG, "goToMap: "+sessionName.getText()); if(sessionName.getText().length()>0) { CreateSessionInput input = CreateSessionInput.builder() .title(sessionName.getText().toString()) @@ -205,7 +203,6 @@ public void joinExistingGameSession(ListSessionsQuery.Item session) { //Get all sessions from the database private void queryAllSessions() { - Log.i(TAG, "query all sessions"); awsAppSyncClient.query(ListSessionsQuery.builder().build()) .responseFetcher(AppSyncResponseFetchers.NETWORK_ONLY) .enqueue(getAllSessionsCallBack); @@ -235,7 +232,6 @@ public void onFailure(@Nonnull ApolloException e) { //Get current player location private void getCurrentUserLocation() { - Log.i(TAG, "Called getCurrentUserLocation"); fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener() { @Override public void onSuccess(final Location location) { @@ -246,7 +242,6 @@ public void onSuccess(final Location location) { public void run() { currentUserLocation = new LatLng(location.getLatitude(), location.getLongitude()); queryAllSessions(); - Log.i(TAG, "PlayerId in getcurrentUserlocation " + playerId); if (playerId == null) { createPlayer(); } @@ -269,12 +264,10 @@ private void checkIfPlayerAlreadyExistInDatabase() { .enqueue(new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull Response response) { - Log.i(TAG, "this is playerID " + playerId); String playerName = AWSMobileClient.getInstance().getUsername(); List players = response.data().listPlayers().items(); for(ListPlayersQuery.Item player : players){ if(player.username().equals(playerName)){ - Log.i(TAG, "Username match " + playerName + " " + player.id()); playerId = player.id(); getCurrentUserLocation(); return; @@ -304,7 +297,6 @@ private void createPlayer() { @Override public void onResponse(@Nonnull Response response) { playerId = response.data().createPlayer().id(); - Log.i(TAG, "created a player"+ playerId); } diff --git a/app/src/main/java/com/javaawesome/tag/MapsActivity.java b/app/src/main/java/com/javaawesome/tag/MapsActivity.java index 5745f1a..e3db218 100644 --- a/app/src/main/java/com/javaawesome/tag/MapsActivity.java +++ b/app/src/main/java/com/javaawesome/tag/MapsActivity.java @@ -204,15 +204,15 @@ public void onResponse(@Nonnull final Response @Override public void handleMessage (Message inputMessage) { //Iterate over the players in the session - //TODO: if session matches; then if player in players update location, else make a new player and add their marker. + //TODO: If session matches; if the player exists in the session update their location, if they don't, make a new player and add their marker to the session OnUpdatePlayerSubscription.OnUpdatePlayer updatePlayer = response.data().onUpdatePlayer(); - Log.i(TAG, "updated user is " + updatePlayer.toString() + " session id is " + sessionId); - //checking if the updated player is in this session + Log.i(TAG, "Updated user is " + updatePlayer.toString() + " Session ID is " + sessionId); + //Check if the updated player is in the session if(updatePlayer.session().id().equals(sessionId)){ boolean contains = false; - //checking if the updated player is in the current player list + //Check if the updated player is in the current player list for(Player player : players){ // if we have a match update players lat/long @@ -226,7 +226,7 @@ public void handleMessage (Message inputMessage) { } } - //if the player is in the session, but not in the player list, then make a new player and add them to the players list and add a marker + //If the player is in the session, but not in the player list, make a new player and add them to the players list and add a marker to the session if(contains == false){ Marker marker = mMap.addMarker(new MarkerOptions() .position(new LatLng(updatePlayer.lat(), updatePlayer.lon())) @@ -250,7 +250,7 @@ public void handleMessage (Message inputMessage) { potatoes.add(new LatLng(updatePlayer.lat(), updatePlayer.lon())); newPlayer.setLocations(potatoes); - //adding player to the list of players in the game + //Add player to the list of players in the game players.add(newPlayer); } } @@ -270,14 +270,14 @@ public void onCompleted() { } }; - // ============= - + //Stop tracking the player's location onStop @Override protected void onStop() { super.onStop(); stopTrackingLocation(); } + //onResume, start subscription to watch for updates @Override protected void onResume() { super.onResume(); @@ -285,9 +285,10 @@ protected void onResume() { // startLocationUpdates(); } + //onDestroy, set player to false and session ID to null public void onDestroy() { super.onDestroy(); - Log.i(TAG, "Our session was destroyed... trying to set player to false"); + Log.i(TAG, "Our session was destroyed... set player to false"); UpdatePlayerInput updatePlayerInput = UpdatePlayerInput.builder() .id(playerID) .playerSessionId(null) @@ -308,20 +309,11 @@ public void onFailure(@Nonnull ApolloException e) { }); } - /** - * Manipulates the map once available. - * This callback is triggered when the map is ready to be used. - * This is where we can add markers or lines, add listeners or move the camera. In this case, - * we just add a marker near Sydney, Australia. - * If Google Play services is not installed on the device, the user will be prompted to install - * it inside the SupportMapFragment. This method will only be triggered once the user has - * installed Google Play services and returned to the app. - */ - + //Manipulates the map and triggers the callback when the map is ready. Now available to add markers, listeners, etc. If Google Play services is not installed on the device, the user will be prompted to install it inside the SupportMapFragment. This method will only be triggered once the user has installed Google Play services and returned to the app. @Override public void onMapReady(GoogleMap googleMap) { - Log.i(TAG, "map is ready"); + Log.i(TAG, "Map is ready"); mMap = googleMap; mMap.setMyLocationEnabled(true); @@ -331,17 +323,19 @@ public void onMapReady(GoogleMap googleMap) { startLocationUpdates(); } + //Turn off location tracking public void stopTrackingLocation() { mFusedLocationClient.removeLocationUpdates(mLocationCallback); } - // Starts pulling location updates from the DB. 3 second delay to let the aws callbacks load first. + //Start pulling location updates from the DB with a 3 second delay to let the aws callbacks load first. private void startLocationUpdates() { try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); } + mFusedLocationClient.requestLocationUpdates(getLocationRequest(), mLocationCallback, Looper.getMainLooper()); mMap.setMyLocationEnabled(true); } @@ -357,7 +351,7 @@ public boolean onMyLocationButtonClick() { return false; } - // Called in startLocationUpdates to pull location updates from the DB + //Called in startLocationUpdates to pull location updates from the DB private LocationRequest getLocationRequest() { Log.i(TAG, "getting location request"); LocationRequest locationRequest = new LocationRequest(); @@ -367,7 +361,7 @@ private LocationRequest getLocationRequest() { return locationRequest; } - // Creates markers and circles for each player in the list for that session + //Create markers and circles for each player in the list for that session private void initializeMarkersAndCirclesForPlayers(List players) { Log.i(TAG, "made it to initialized markers"); for(Player player: players) { @@ -393,7 +387,8 @@ private void initializeMarkersAndCirclesForPlayers(List players) { player.setMarker(marker); } - // Add a marker in center of game camera and move the camera + + //Add a marker in center of game camera and move the camera mMap.moveCamera(CameraUpdateFactory.zoomTo(16)); mMap.moveCamera(CameraUpdateFactory.newLatLng(startingPoint)); Circle gameBounds = mMap.addCircle(new CircleOptions() @@ -404,9 +399,9 @@ private void initializeMarkersAndCirclesForPlayers(List players) { .strokeWidth(5)); } - + //Update the markers and circles for all players in the session private void updateMarkerAndCircleForAllPlayers(List players) { - Log.i(TAG, "updating markers"); + Log.i(TAG, "Updating markers"); Log.i(TAG, "How many players? " + players.size()); if(itPlayers == null){ @@ -430,18 +425,10 @@ private void updateMarkerAndCircleForAllPlayers(List players) { if (checkForTag(player)) { Log.i(TAG, "In the updateMarkerAndCircleForAllPlayers"); playersJustGotTagged.add(player); - -// player.getMarker().setIcon(zombiepin); -// player.getCircle().setStrokeColor(itColor); - -// mMap.addCircle(player.getCircle()); } -// else { -// player.getMarker().setIcon(playerpin); -// player.getCircle().setStrokeColor(notItColor); -// } } - //TODO add the player instance is it update, only updates the player list so far + + //TODO: Add the player instance is it update, only updates the player list so far for(Player player : players){ if(player.getIt()){ player.getMarker().setIcon(zombiepin); @@ -454,7 +441,7 @@ private void updateMarkerAndCircleForAllPlayers(List players) { for(Player p : players){ if(p.getId().equals(playerID)){ - Log.i(TAG, "Player Ids match"); + Log.i(TAG, "Player IDs match"); player.setIt(p.getIt()); } } @@ -462,8 +449,8 @@ private void updateMarkerAndCircleForAllPlayers(List players) { itPlayers.addAll(playersJustGotTagged); } - // Equation is from https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters - // convert to two location points to distance between them in meters + //Equation is from https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters + //Convert to two location points to distance between them in meters private double distanceBetweenLatLongPoints(double lat1, double long1, double lat2, double long2) { // radius of the Earth in km double R = 6378.137; @@ -477,19 +464,15 @@ private double distanceBetweenLatLongPoints(double lat1, double long1, double la return d * 1000; } - // check if the player is tagged by the it player - // check if the distance between the it player and the other player is less than the specified tag distance + //Check if the player is tagged by the it player + //Check if the distance between the it player and the other player is less than the specified tag distance private boolean isTagged(Player player, Player itPlayer) { double distanceBetweenPlayers = distanceBetweenLatLongPoints(itPlayer.getLastLocation().latitude, itPlayer.getLastLocation().longitude, player.getLastLocation().latitude, player.getLastLocation().longitude); - Log.i(TAG, "distance between players is " + distanceBetweenPlayers + " meters"); - -// if (distanceBetweenPlayers < tagDistance) { if (distanceBetweenPlayers < tagDistance && itPlayer != player) { - Log.i(TAG, "*************player is set to true*************"); player.setIt(true); return true; } else { @@ -497,27 +480,21 @@ private boolean isTagged(Player player, Player itPlayer) { } } + //Check to see if the player has been tagged/is it private boolean checkForTag(Player player) { - Log.i(TAG, "Made it into checkForTag"); if (player.isIt()) { return false; } for(Player itPlayer : itPlayers) { Log.i(TAG, itPlayer.toString()); if (isTagged(player, itPlayer)) { -// Toast.makeText(this, "" + player.getUsername() + " is now it!!!", Toast.LENGTH_SHORT); - //TODO: If future views added to app, may need to change "this"? - - //TODO: this activity traps the user, so disabled for now. -// startActivity(new Intent(MapsActivity.this, NotificationActivity.class)); return true; - } } return false; } - // query for the session associated with the sessionId that was passed from MainActivity + //Query for the session associated with the sessionId that was passed from MainActivity private void queryForSelectedSession(String sessionId) { GetSessionQuery getSessionQuery = GetSessionQuery.builder().id(sessionId).build(); awsAppSyncClient.query(getSessionQuery) @@ -525,9 +502,8 @@ private void queryForSelectedSession(String sessionId) { .enqueue(getSessionCallBack); } - // Make a Player + //Make a Player private void createPlayer() { - Log.i(TAG, "Making a player with " + sessionId + " " + startingPoint.toString()); CreatePlayerInput input = CreatePlayerInput.builder() .playerSessionId(sessionId) .lat(startingPoint.latitude) @@ -540,7 +516,6 @@ private void createPlayer() { awsAppSyncClient.mutate(createPlayerMutation).enqueue(new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull Response response) { - Log.i(TAG, "made it to creating a new player"); playerID = response.data().createPlayer().id(); player = new Player(); player.setId(playerID); @@ -553,12 +528,12 @@ public void onResponse(@Nonnull Response response) { @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "couldn't make a new player"); + Log.e(TAG, "Couldn't make a new player"); } }); } - // Query for Player + //Query for Player private void queryForPlayerObject() { GetPlayerQuery query = GetPlayerQuery.builder().id(playerID).build(); awsAppSyncClient.query(query) @@ -566,11 +541,10 @@ private void queryForPlayerObject() { .enqueue(new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull Response response) { - Log.i(TAG, "made it to making a query for player object"); - // make a player instance + //Make a player instance player = new Player(response.data().getPlayer()); - // Making stuff on the map for the player + //Making stuff on the map for the player Handler markerHandler = new Handler(Looper.getMainLooper()){ @Override public void handleMessage (Message inputMessage) { @@ -582,7 +556,7 @@ public void handleMessage (Message inputMessage) { .radius(tagDistance) .fillColor(Color.TRANSPARENT) .strokeWidth(3)); - // change color of marker depending on if player is it or not + //Change color of marker depending on if player is it or not if (player.isIt()) { marker.setIcon(zombiepin); circle.setStrokeColor(itColor); @@ -597,7 +571,7 @@ public void handleMessage (Message inputMessage) { player.setCircle(circle); player.setMarker(marker); - //adding player to the list of players in the game + //Add player to the list of players in the game players.add(player); } }; @@ -606,45 +580,34 @@ public void handleMessage (Message inputMessage) { @Override public void onFailure(@Nonnull ApolloException e) { - Log.e(TAG, "failed to get query for player object"); + Log.e(TAG, "Failed to get query for player object"); } }); } - // Callback to get current game session + //Callback to get current game session private GraphQLCall.Callback getSessionCallBack = new GraphQLCall.Callback() { @Override public void onResponse(@Nonnull final Response response) { currentSession = response.data().getSession(); - Log.i(TAG, "Current session is "+ currentSession.toString()); startingPoint = new LatLng(currentSession.lat(), currentSession.lon()); - Log.i(TAG, "Starting point is " + startingPoint); - //once the session ID and starting loc are in place, then make the first player. + //Once the session ID and starting location are in place, make the first player. queryForPlayerObject(); -// if (playerID == null) { -// createPlayer(); -// } else { -// queryForPlayerObject(); -// } - - Log.i(TAG, "Made it to the after the if/else within getSessionCallBack"); - //converting from GetSessionItems to players + + //Convert GetSessionItems to players players = playerConverter(currentSession.players().items()); Handler h = new Handler(Looper.getMainLooper()){ @Override public void handleMessage(Message inputMessage){ - Log.i(TAG, "Made it to handleMessage"); - //lat and long for the session - + //Lat and Long for the session try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } initializeMarkersAndCirclesForPlayers(players); - } }; h.obtainMessage().sendToTarget();