From 815e40567a0a6a357d8a15c6d488cd85b296873e Mon Sep 17 00:00:00 2001 From: Steven Wexler Date: Fri, 31 Jul 2015 00:48:39 -0400 Subject: [PATCH] Attempt to fix offline screen --- src/android/GooglePlus.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/android/GooglePlus.java b/src/android/GooglePlus.java index aca6876f..2907cf24 100644 --- a/src/android/GooglePlus.java +++ b/src/android/GooglePlus.java @@ -36,6 +36,9 @@ public class GooglePlus extends CordovaPlugin implements ConnectionCallbacks, On public static final String ARGUMENT_WEB_KEY = "webApiKey"; public static final String ARGUMENT_SCOPE = "scope"; + private String recoveringEmail; + private JSONObject recoveringResult; + // Wraps our service connection to Google Play services and provides access to the users sign in state and Google APIs private GoogleApiClient mGoogleApiClient; private String apiKey, webKey, scope; @@ -123,6 +126,7 @@ private GoogleApiClient buildGoogleApiClient() { @SuppressWarnings({ "unchecked", "rawtypes" }) private void resolveToken(final String email, final JSONObject result) { final Context context = this.cordova.getActivity().getApplicationContext(); + final GooglePlus self = this; cordova.getThreadPool().execute(new Runnable() { public void run() { @@ -151,8 +155,10 @@ public void run() { catch (UserRecoverableAuthException userAuthEx) { // Start the user recoverable action using the intent returned by // getIntent() - cordova.getActivity().startActivityForResult(userAuthEx.getIntent(), - Activity.RESULT_OK); + self.cordova.setActivityResultCallback(self); + self.recoveringEmail = email; + self.recoveringResult = result; + cordova.getActivity().startActivityForResult(userAuthEx.getIntent(), 10); return; } catch (IOException e) { @@ -263,7 +269,9 @@ public void onConnectionFailed(ConnectionResult result) { @Override public void onActivityResult(int requestCode, final int resultCode, final Intent intent) { super.onActivityResult(requestCode, resultCode, intent); - if (resultCode == Activity.RESULT_OK) { + if (mGoogleApiClient.isConnected() && resultCode == Activity.RESULT_OK) { + this.resolveToken(recoveringEmail, recoveringResult); + } else if (resultCode == Activity.RESULT_OK) { mGoogleApiClient.connect(); } else { this.savedCallbackContext.error("user cancelled");