aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-08 12:19:38 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-08 12:19:38 +0000
commit85597a82d065374955153c0481663fac2b0c3264 (patch)
tree34160d0db12a8b9ffdd532b2112c27b427683996 /app/src/main/java/ml
parente542ac51388b9293297bb74b851dcb5ded621a3e (diff)
downloadinfinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.tar
infinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.tar.gz
infinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.tar.bz2
infinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.tar.lz
infinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.tar.xz
infinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.tar.zst
infinity-for-reddit-85597a82d065374955153c0481663fac2b0c3264.zip
Switch between all logged-in reddit accounts is available.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SwitchAccountAsyncTask.java32
2 files changed, 41 insertions, 5 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 2f6c313b..5f5272f7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -191,7 +191,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
new AccountRecyclerViewAdapter.ItemSelectedListener() {
@Override
public void accountSelected(Account account) {
-
+ new SwitchAccountAsyncTask(mRedditDataRoomDatabase, account.getUsername(), () -> relaunchActivity()).execute();
}
@Override
@@ -349,13 +349,17 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
}
}
+ private void relaunchActivity() {
+ Intent intent = getIntent();
+ finish();
+ startActivity(intent);
+ overridePendingTransition(0, 0);
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == LOGIN_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
- Intent intent = getIntent();
- finish();
- startActivity(intent);
- overridePendingTransition(0, 0);
+ relaunchActivity();
}
super.onActivityResult(requestCode, resultCode, data);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SwitchAccountAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SwitchAccountAsyncTask.java
new file mode 100644
index 00000000..f5b9c37b
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SwitchAccountAsyncTask.java
@@ -0,0 +1,32 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.os.AsyncTask;
+
+class SwitchAccountAsyncTask extends AsyncTask<Void, Void, Void> {
+ interface SwitchAccountAsyncTaskListener {
+ void switched();
+ }
+
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+ private String newAccountName;
+ private SwitchAccountAsyncTaskListener switchAccountAsyncTaskListener;
+
+ SwitchAccountAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String newAccountName,
+ SwitchAccountAsyncTaskListener switchAccountAsyncTaskListener) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ this.newAccountName = newAccountName;
+ this.switchAccountAsyncTaskListener = switchAccountAsyncTaskListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ redditDataRoomDatabase.accountDao().markAllAccountsNonCurrent();
+ redditDataRoomDatabase.accountDao().markAccountCurrent(newAccountName);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ switchAccountAsyncTaskListener.switched();
+ }
+}