Skip to content

Commit fe5a8a1

Browse files
committed
Updating Collect all the stars 2 - per review comments from @samtstern.
1 parent 43dcf7d commit fe5a8a1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

BasicSamples/CollectAllTheStars2/src/main/java/com/google/example/games/catt2/MainActivity.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public void onClick(View view) {
393393
updateUi();
394394
break;
395395
case R.id.button_next_world:
396-
if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
396+
if (isConnected()) {
397397
BaseGameUtils.makeSimpleDialog(this, getString(R.string.please_sign_in)).show();
398398
return;
399399
}
@@ -403,7 +403,7 @@ public void onClick(View view) {
403403
}
404404
break;
405405
case R.id.button_prev_world:
406-
if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
406+
if (isConnected()) {
407407
BaseGameUtils.makeSimpleDialog(this, getString(R.string.please_sign_in)).show();
408408
return;
409409
}
@@ -413,7 +413,7 @@ public void onClick(View view) {
413413
}
414414
break;
415415
default:
416-
if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
416+
if (isConnected()) {
417417
BaseGameUtils.makeSimpleDialog(this, getString(R.string.please_sign_in)).show();
418418
return;
419419
}
@@ -426,6 +426,10 @@ public void onClick(View view) {
426426
}
427427
}
428428

429+
private boolean isConnected() {
430+
return mGoogleApiClient == null || !mGoogleApiClient.isConnected();
431+
}
432+
429433
/**
430434
* Gets a screenshot to use with snapshots. Note that in practice you probably do not want to
431435
* use this approach because tablet screen sizes can become pretty large and because the image
@@ -474,8 +478,7 @@ protected Integer doInBackground(Void... params) {
474478
if (snapshotMetadata != null && snapshotMetadata.getUniqueName() != null) {
475479
Log.i(TAG, "Opening snapshot by metadata: " + snapshotMetadata);
476480
result = Games.Snapshots.open(mGoogleApiClient,snapshotMetadata).await();
477-
}
478-
else {
481+
} else {
479482
Log.i(TAG, "Opening snapshot by name: " + currentSaveName);
480483
result = Games.Snapshots.open(mGoogleApiClient, currentSaveName, true).await();
481484
}
@@ -527,7 +530,7 @@ protected void onPostExecute(Integer status) {
527530
Toast.LENGTH_SHORT).show();
528531
}
529532

530-
if (mLoadingDialog != null) {
533+
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
531534
mLoadingDialog.dismiss();
532535
mLoadingDialog = null;
533536
}
@@ -800,7 +803,7 @@ protected Snapshots.LoadSnapshotsResult doInBackground(Void... params) {
800803
@Override
801804
protected void onPostExecute(Snapshots.LoadSnapshotsResult snapshotResults) {
802805

803-
if (mLoadingDialog != null) {
806+
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
804807
mLoadingDialog.dismiss();
805808
mLoadingDialog = null;
806809
}

BasicSamples/CollectAllTheStars2/src/main/java/com/google/example/games/catt2/SelectSnapshotActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
9494
SnapshotMetadata selected = (SnapshotMetadata) adapterView.getItemAtPosition(position);
9595
Intent intent = new Intent(Intent.ACTION_DEFAULT);
9696

97-
intent.putExtra(SNAPSHOT_METADATA, ( selected).freeze());
97+
intent.putExtra(SNAPSHOT_METADATA, selected.freeze());
9898

9999
if (mConflictId != null) {
100100
intent.putExtra(CONFLICT_ID, mConflictId);

0 commit comments

Comments
 (0)