Introduces instance in sharedpreferences
This commit is contained in:
parent
62e48bb8e7
commit
6a4b7b7cce
|
@ -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<Void, Void, Void> {
|
|||
@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<Void, Void, Void> {
|
|||
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);
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in New Issue