aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-03-28 12:18:25 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-03-28 12:18:25 +0000
commit188d58b5dafbb5795a24a57073ff421da113b0a6 (patch)
treecfa072094267d3bae6a6532bd039f030d375dae0
parent01b2a0405734b4f40256015b8423b07bcd6699f4 (diff)
downloadinfinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.tar
infinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.tar.gz
infinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.tar.bz2
infinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.tar.lz
infinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.tar.xz
infinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.tar.zst
infinity-for-reddit-188d58b5dafbb5795a24a57073ff421da113b0a6.zip
Fix some issues of custom themes.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java19
2 files changed, 16 insertions, 7 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
index 45902fd8..678dee79 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
@@ -9,6 +9,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
@@ -268,7 +269,8 @@ public class CustomThemeListingActivity extends BaseActivity implements
new InsertCustomThemeAsyncTask.InsertCustomThemeAsyncTaskListener() {
@Override
public void success() {
- Snackbar.make(coordinatorLayout, R.string.import_theme_success, Snackbar.LENGTH_SHORT).show();
+ Toast.makeText(CustomThemeListingActivity.this, R.string.import_theme_success, Toast.LENGTH_SHORT).show();
+ EventBus.getDefault().post(new RecreateActivityEvent());
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
index 0eba4b1d..f6443841 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
@@ -39,23 +39,30 @@ public class InsertCustomThemeAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
+ if (checkDuplicate) {
+ if (redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name) != null) {
+ isDuplicate = true;
+ return null;
+ }
+ }
+ CustomTheme previousTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name);
if (customTheme.isLightTheme) {
redditDataRoomDatabase.customThemeDao().unsetLightTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences);
+ } else if (previousTheme.isLightTheme) {
+ lightThemeSharedPreferences.edit().clear().apply();
}
if (customTheme.isDarkTheme) {
redditDataRoomDatabase.customThemeDao().unsetDarkTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences);
+ } else if (previousTheme.isDarkTheme) {
+ darkThemeSharedPreferences.edit().clear().apply();
}
if (customTheme.isAmoledTheme) {
redditDataRoomDatabase.customThemeDao().unsetAmoledTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences);
- }
- if (checkDuplicate) {
- if (redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name) != null) {
- isDuplicate = true;
- return null;
- }
+ } else if (previousTheme.isAmoledTheme) {
+ amoledThemeSharedPreferences.edit().clear().apply();
}
redditDataRoomDatabase.customThemeDao().insert(customTheme);
return null;