summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2020-07-25 11:36:46 +0200
committerThomas <tschneider.ac@gmail.com>2020-07-25 11:36:46 +0200
commitabe8812e6ef8b7c058b71caff27be0e49fe85aaa (patch)
tree3ce5d9a56b4321e6e66285a3707318f1775b58e7 /app/src/main/java
parent46c678a3e2e6af8f443ee5b7576f9140a6025c31 (diff)
some changes
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java8
-rw-r--r--app/src/main/java/app/fedilab/android/activities/LoginActivity.java8
-rw-r--r--app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java6
-rw-r--r--app/src/main/java/app/fedilab/android/asynctasks/UpdateAccountInfoByIDAsyncTask.java38
-rw-r--r--app/src/main/java/app/fedilab/android/client/API.java4
5 files changed, 32 insertions, 32 deletions
diff --git a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java
index 4add19dd3..a8ef126d9 100644
--- a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java
@@ -317,11 +317,7 @@ public abstract class BaseMainActivity extends BaseActivity
} catch (Exception ignored) {
}
}
- if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
- new Thread(() -> {
- new API(BaseMainActivity.this).refreshToken(account);
- }).start();
- }
+
//Here, the user is authenticated
appBar = findViewById(R.id.appBar);
Toolbar toolbar = findViewById(R.id.toolbar);
@@ -1339,7 +1335,7 @@ public abstract class BaseMainActivity extends BaseActivity
new TimelineCacheDAO(BaseMainActivity.this, db).removeAfterDate(dateString);
});
if (Helper.isLoggedIn(BaseMainActivity.this)) {
- new UpdateAccountInfoByIDAsyncTask(BaseMainActivity.this, social, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ new UpdateAccountInfoByIDAsyncTask(BaseMainActivity.this, account, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
mutedAccount = new TempMuteDAO(BaseMainActivity.this, db).getAllTimeMuted(account);
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java
index 513ad4f91..31e70a77f 100644
--- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java
@@ -153,14 +153,14 @@ public class LoginActivity extends BaseActivity {
JSONObject resobj;
try {
resobj = new JSONObject(response);
- String token = resobj.get("access_token").toString();
+ String token = resobj.getString("access_token");
String refresh_token = null;
if (resobj.has("refresh_token"))
- refresh_token = resobj.get("refresh_token").toString();
+ refresh_token = resobj.getString("refresh_token");
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
- editor.apply();
+ editor.commit();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, instance, socialNetwork).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException e) {
@@ -701,7 +701,7 @@ public class LoginActivity extends BaseActivity {
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
+ public boolean onOptionsItemSelected(@NotNull MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
diff --git a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java
index 230ff009c..0c191a166 100644
--- a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java
@@ -178,14 +178,14 @@ public class WebviewConnectActivity extends BaseActivity {
JSONObject resobj;
try {
resobj = new JSONObject(response);
- String token = resobj.get("access_token").toString();
+ String token = resobj.getString("access_token");
String refresh_token = null;
if (resobj.has("refresh_token"))
- refresh_token = resobj.get("refresh_token").toString();
+ refresh_token = resobj.getString("refresh_token");
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences1.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
- editor.apply();
+ editor.commit();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(WebviewConnectActivity.this, token, clientId, clientSecret, refresh_token, instance, social).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException ignored) {
diff --git a/app/src/main/java/app/fedilab/android/asynctasks/UpdateAccountInfoByIDAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/UpdateAccountInfoByIDAsyncTask.java
index c2bcc67aa..1dd680374 100644
--- a/app/src/main/java/app/fedilab/android/asynctasks/UpdateAccountInfoByIDAsyncTask.java
+++ b/app/src/main/java/app/fedilab/android/asynctasks/UpdateAccountInfoByIDAsyncTask.java
@@ -15,7 +15,6 @@
package app.fedilab.android.asynctasks;
import android.content.Context;
-import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
@@ -33,6 +32,8 @@ import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.CustomEmojiDAO;
import app.fedilab.android.sqlite.Sqlite;
+import static app.fedilab.android.activities.BaseMainActivity.social;
+
/**
* Created by Thomas on 17/05/2017.
* Manage the synchronization with the authenticated account and update the db not
@@ -43,24 +44,25 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
private OnUpdateAccountInfoInterface listener;
private WeakReference<Context> contextReference;
- private UpdateAccountInfoAsyncTask.SOCIAL social;
+ private Account accountOld;
- public UpdateAccountInfoByIDAsyncTask(Context context, UpdateAccountInfoAsyncTask.SOCIAL social, OnUpdateAccountInfoInterface onUpdateAccountInfoInterface) {
+ public UpdateAccountInfoByIDAsyncTask(Context context, Account account, OnUpdateAccountInfoInterface onUpdateAccountInfoInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onUpdateAccountInfoInterface;
- this.social = social;
+ this.accountOld = account;
}
@Override
protected Void doInBackground(Void... params) {
- SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
- String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
+
Account account = null;
- if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED)
+ if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
account = new API(this.contextReference.get()).verifyCredentials();
- else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
+ if( social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED){
+ account.setSocial("PIXELFED");
+ }
+ }else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials();
account.setSocial("PEERTUBE");
} else if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
@@ -70,15 +72,17 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
return null;
account.setInstance(Helper.getLiveInstance(contextReference.get()));
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
- boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account);
- if (userExists) {
- Account accountDb = new AccountDAO(this.contextReference.get(), db).getUniqAccount(userId, instance);
+ if (accountOld != null) {
+ account.setInstance(accountOld.getInstance());
+ account.setToken(accountOld.getToken());
+ account.setRefresh_token(accountOld.getRefresh_token());
+ account.setClient_id(accountOld.getClient_id());
+ account.setClient_secret(accountOld.getClient_secret());
+ new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
+ }
- if (accountDb != null) {
- account.setInstance(accountDb.getInstance());
- account.setToken(accountDb.getToken());
- new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
- }
+ if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
+ new API(contextReference.get()).refreshToken(account);
}
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
try {
diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java
index 7477b5bf8..70efb6739 100644
--- a/app/src/main/java/app/fedilab/android/client/API.java
+++ b/app/src/main/java/app/fedilab/android/client/API.java
@@ -2552,9 +2552,9 @@ public class API {
try {
String response;
if (account.getSocial().compareTo("PEERTUBE") == 0) {
- response = new HttpsConnection(context, instance).post(getAbsoluteUrl("/users/token"), 60, params, account.getToken());
+ response = new HttpsConnection(context, instance).post(getAbsoluteUrl("/users/token"), 60, params, null);
} else {
- response = new HttpsConnection(context, instance).post("https://" + instance + "/oauth/token", 60, params, account.getToken());
+ response = new HttpsConnection(context, instance).post("https://" + instance + "/oauth/token", 60, params, null);
}
JSONObject resobj = new JSONObject(response);
String newToken = resobj.getString("access_token");