Skip to content

Commit

Permalink
fix #12 GooglePlusSocialNetwork.isConnected()
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkrasov committed Jun 25, 2014
1 parent da3f3c7 commit 7f6a6a3
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public class GooglePlusSocialNetwork extends SocialNetwork
private static final String TAG = GooglePlusSocialNetwork.class.getSimpleName();
// max 16 bit to use in startActivityForResult
private static final int REQUEST_AUTH = UUID.randomUUID().hashCode() & 0xFFFF;

/**
* mPlusClient.isConntected() works really strange, it returs false right after init and then true,
* so let's handle state by ourselves
*/
private static final String SAVE_STATE_KEY_IS_CONNECTED = "GooglePlusSocialNetwork.SAVE_STATE_KEY_OAUTH_TOKEN";
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;

private boolean mConnectRequested;

private Handler mHandler = new Handler();

public GooglePlusSocialNetwork(Fragment fragment) {
Expand All @@ -48,7 +50,7 @@ public GooglePlusSocialNetwork(Fragment fragment) {

@Override
public boolean isConnected() {
return mPlusClient.isConnected();
return mSharedPreferences.getBoolean(SAVE_STATE_KEY_IS_CONNECTED, false);
}

@Override
Expand Down Expand Up @@ -77,6 +79,8 @@ public void logout() {
mConnectRequested = false;

if (mPlusClient.isConnected()) {
mSharedPreferences.edit().remove(SAVE_STATE_KEY_IS_CONNECTED).commit();

mPlusClient.clearDefaultAccount();
mPlusClient.disconnect();
mPlusClient.connect();
Expand Down Expand Up @@ -207,6 +211,7 @@ public void onConnected(Bundle bundle) {
if (mConnectRequested) {
if (mPlusClient.getCurrentPerson() != null) {
if (mLocalListeners.get(REQUEST_LOGIN) != null) {
mSharedPreferences.edit().putBoolean(SAVE_STATE_KEY_IS_CONNECTED, true).commit();
((OnLoginCompleteListener) mLocalListeners.get(REQUEST_LOGIN)).onLoginSuccess(getID());
}

Expand Down

0 comments on commit 7f6a6a3

Please sign in to comment.