From 6a4b7b7cce798d05d8974c41b9461261e7b613a9 Mon Sep 17 00:00:00 2001 From: stom79 Date: Thu, 28 Dec 2017 17:02:30 +0100 Subject: [PATCH] Introduces instance in sharedpreferences --- .../mastodon/asynctasks/UpdateAccountInfoAsyncTask.java | 7 +++++++ .../main/java/fr/gouv/etalab/mastodon/helper/Helper.java | 3 +++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java index cd06466ea..858daf619 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java @@ -21,7 +21,9 @@ import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; +import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; +import java.net.URLDecoder; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; @@ -50,6 +52,10 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { Account account = new API(this.contextReference.get(), instance, null).verifyCredentials(); + try { + //At the state the instance can be encoded + instance = URLDecoder.decode(instance, "utf-8"); + } catch (UnsupportedEncodingException ignored) {} SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); if( token == null) { token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); @@ -61,6 +67,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask { boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.PREF_KEY_ID, account.getId()); + editor.putString(Helper.PREF_INSTANCE, instance); editor.apply(); if( userExists) new AccountDAO(this.contextReference.get(), db).updateAccount(account); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index bab9d4b4d..d99236322 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -168,6 +168,7 @@ public class Helper { public static final String OAUTH_SCOPES = "read write follow"; public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token"; public static final String PREF_KEY_ID = "userID"; + public static final String PREF_INSTANCE = "instance"; public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob"; public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab"; public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84; @@ -424,6 +425,7 @@ public class Helper { editor.putString(Helper.CLIENT_ID, null); editor.putString(Helper.CLIENT_SECRET, null); editor.putString(Helper.PREF_KEY_ID, null); + editor.putString(Helper.PREF_INSTANCE, null); editor.putString(Helper.ID, null); editor.apply(); } @@ -1045,6 +1047,7 @@ public class Helper { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken()); editor.putString(Helper.PREF_KEY_ID, account.getId()); + editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim()); editor.apply(); activity.recreate(); if( checkItem ) {