@@ -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 }
0 commit comments