Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<activity android:name=".picturePreview"/>
<activity android:name=".ShowMeYourFace"/>

<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
51 changes: 50 additions & 1 deletion app/src/main/java/com/javaawesome/tag/MapsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected void onCreate(Bundle savedInstanceState) {
sessionId = getIntent().getStringExtra("sessionId");
Log.i(TAG, "Session ID for map is: " + sessionId + "the player Id is " + playerID);

queryForSelectedSession(sessionId);
associateUserWithSession();

// Pull user ID from MainActivity
// If player comes from the recyclerView it will come through as null so we will create a new player
Expand Down Expand Up @@ -168,6 +168,31 @@ public void onFailure(@Nonnull ApolloException e) {
});
}

private void associateUserWithSession() {
Log.i(TAG, "player being sent " + (player == null ? "null" : player.toString()));
UpdatePlayerInput updatePlayerInput = UpdatePlayerInput.builder()
.id(playerID)
.playerSessionId(sessionId)
.build();

UpdatePlayerMutation updatePlayerMutation = UpdatePlayerMutation.builder()
.input(updatePlayerInput).build();

awsAppSyncClient.mutate(updatePlayerMutation)
.enqueue(new GraphQLCall.Callback<UpdatePlayerMutation.Data>() {
@Override
public void onResponse(@Nonnull Response<UpdatePlayerMutation.Data> response) {
Log.i(TAG, "update success");
queryForSelectedSession(sessionId);
}

@Override
public void onFailure(@Nonnull ApolloException e) {
Log.e(TAG, "update not successful");
}
});
}

// ===== Subscribe to Data real-time ======
// https://aws-amplify.github.io/docs/android/api

Expand Down Expand Up @@ -280,6 +305,29 @@ protected void onResume() {
// startLocationUpdates();
}

public void onDestroy() {
super.onDestroy();
Log.i(TAG, "Our session was destroyed... trying to set player to false");
UpdatePlayerInput updatePlayerInput = UpdatePlayerInput.builder()
.id(playerID)
.playerSessionId(null)
.isIt(false)
.build();
UpdatePlayerMutation updatePlayerMutation = UpdatePlayerMutation.builder()
.input(updatePlayerInput).build();
awsAppSyncClient.mutate(updatePlayerMutation)
.enqueue(new GraphQLCall.Callback<UpdatePlayerMutation.Data>() {
@Override
public void onResponse(@Nonnull Response<UpdatePlayerMutation.Data> response) {
Log.i(TAG, "onDestroy successful");
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Log.e(TAG, "onDestroy not successful");
}
});
}

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
Expand Down Expand Up @@ -391,6 +439,7 @@ private void updateMarkerAndCircleForAllPlayers(List<Player> players) {

if (itPlayers.isEmpty()) {
itPlayers.add(players.get(0));
players.get(0).setIt(true);
}
}

Expand Down
11 changes: 5 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
android:id="@+id/goToMapButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
android:onClick="goToMap"
android:text="@string/start_new_game_button"
app:layout_constraintBottom_toTopOf="@+id/recycler_nearby_sessions"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText_session_name" />
Expand All @@ -63,11 +62,10 @@
android:id="@+id/recyclerChooseCurrentGamePrompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/choose_current_game_prompt"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/recycler_nearby_sessions"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/goToMapButton" />
Expand All @@ -76,14 +74,15 @@
android:id="@+id/recycler_nearby_sessions"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:elevation="12dp"
android:clipToPadding="false"
android:elevation="12dp"
app:layout_constraintBottom_toTopOf="@+id/userPageButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/goToMapButton" />
app:layout_constraintTop_toBottomOf="@id/recyclerChooseCurrentGamePrompt" />

<Button
android:id="@+id/userPageButton"
Expand Down