X-Git-Url: http://www.average.org/gitweb/?p=WhereAmI.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fwhereami%2FAuthorize.java;h=804486f63de2e8d27f10a9e118ec93fbbe894529;hp=1bf5fad0f6bdbf1e74cff00a127007e691c099a9;hb=934cdd85cd8722dfab9e34f67d9a7a74e00e9876;hpb=50c044c1b04021f044bc954274c198653c6b3902 diff --git a/src/org/average/whereami/Authorize.java b/src/org/average/whereami/Authorize.java index 1bf5fad..804486f 100644 --- a/src/org/average/whereami/Authorize.java +++ b/src/org/average/whereami/Authorize.java @@ -6,13 +6,14 @@ package org.average.whereami; import java.io.IOException; import org.average.whereami.ClientCredentials; +import org.average.whereami.PersistentStore; import android.app.Activity; import android.os.Bundle; import android.graphics.Bitmap; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager; import android.util.Log; import android.view.View; @@ -28,12 +29,7 @@ import com.google.api.client.json.jackson.JacksonFactory; public class Authorize extends Activity { final String TAG = getClass().getName(); - - private SharedPreferences prefs; - private static final String ACCESS_TOKEN = "access_token"; - private static final String EXPIRES_IN = "expires_in"; - private static final String REFRESH_TOKEN = "refresh_token"; - private static final String SCOPE = "scope"; + SharedPreferences prefs; @Override public void onCreate(Bundle savedInstanceState) { @@ -72,17 +68,12 @@ public class Authorize extends Activity { ClientCredentials.CLIENT_SECRET, code, ClientCredentials.REDIRECT_URI).execute(); - storeTokens(accessTokenResponse); + PersistentStore store = new PersistentStore(prefs); + store.writeTokens(accessTokenResponse); finish(); - //view.setVisibility(View.INVISIBLE); - //startActivity(new Intent(Authorize.this, - // WhereAmI.class)); } else if (url.indexOf("error=")!=-1) { - clearTokens(); + new PersistentStore(prefs).clearTokens(); finish(); - //view.setVisibility(View.INVISIBLE); - //startActivity(new Intent(Authorize.this, - // WhereAmI.class)); } } catch (IOException e) { e.printStackTrace(); @@ -96,30 +87,6 @@ public class Authorize extends Activity { ClientCredentials.REDIRECT_URI.length()+7, url.length()); } - - private void storeTokens(AccessTokenResponse accessTokenResponse) { - Log.w(TAG, "Storing tokens: " + accessTokenResponse); - Editor editor = prefs.edit(); - editor.putString(ACCESS_TOKEN, - accessTokenResponse.accessToken); - editor.putLong( EXPIRES_IN, - accessTokenResponse.expiresIn); - editor.putString(REFRESH_TOKEN, - accessTokenResponse.refreshToken); - editor.putString(SCOPE, - accessTokenResponse.scope); - editor.commit(); - } - - private void clearTokens() { - Log.w(TAG, "Clear tokens"); - Editor editor = prefs.edit(); - editor.remove(ACCESS_TOKEN); - editor.remove(EXPIRES_IN); - editor.remove(REFRESH_TOKEN); - editor.remove(SCOPE); - editor.commit(); - } }); webview.loadUrl(authorizationUrl);