aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAndrei Shpakovskiy <50966785+AndreiShpakovskiy@users.noreply.github.com>2022-08-12 10:36:14 +0000
committerGitHub <noreply@github.com>2022-08-12 10:36:14 +0000
commita12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1 (patch)
treebf81972d9575e826e947903b24ddf28dae1a21db /app
parent41504e779b67c7240ae469875c8427d11f07d07a (diff)
downloadinfinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.tar
infinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.tar.gz
infinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.tar.bz2
infinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.tar.lz
infinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.tar.xz
infinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.tar.zst
infinity-for-reddit-a12e65aa0ea130d43b4f899b5cfdbb81dbce6ec1.zip
Manage theme insertion callbacks behaviour (#892)
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertCustomTheme.java50
1 files changed, 25 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertCustomTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertCustomTheme.java
index 7527e0d1..da0d97fd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertCustomTheme.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertCustomTheme.java
@@ -19,33 +19,33 @@ public class InsertCustomTheme {
CustomTheme customTheme, boolean checkDuplicate,
InsertCustomThemeListener insertCustomThemeListener) {
executor.execute(() -> {
- if (checkDuplicate) {
- if (redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name) != null) {
- handler.post(insertCustomThemeListener::duplicate);
- }
- }
CustomTheme previousTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name);
- if (customTheme.isLightTheme) {
- redditDataRoomDatabase.customThemeDao().unsetLightTheme();
- CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences);
- } else if (previousTheme != null && previousTheme.isLightTheme) {
- lightThemeSharedPreferences.edit().clear().apply();
- }
- if (customTheme.isDarkTheme) {
- redditDataRoomDatabase.customThemeDao().unsetDarkTheme();
- CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences);
- } else if (previousTheme != null && previousTheme.isDarkTheme) {
- darkThemeSharedPreferences.edit().clear().apply();
- }
- if (customTheme.isAmoledTheme) {
- redditDataRoomDatabase.customThemeDao().unsetAmoledTheme();
- CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences);
- } else if (previousTheme != null && previousTheme.isAmoledTheme) {
- amoledThemeSharedPreferences.edit().clear().apply();
- }
- redditDataRoomDatabase.customThemeDao().insert(customTheme);
- handler.post(insertCustomThemeListener::success);
+ if (checkDuplicate && previousTheme != null) {
+ handler.post(insertCustomThemeListener::duplicate);
+ } else {
+ if (customTheme.isLightTheme) {
+ redditDataRoomDatabase.customThemeDao().unsetLightTheme();
+ CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences);
+ } else if (previousTheme != null && previousTheme.isLightTheme) {
+ lightThemeSharedPreferences.edit().clear().apply();
+ }
+ if (customTheme.isDarkTheme) {
+ redditDataRoomDatabase.customThemeDao().unsetDarkTheme();
+ CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences);
+ } else if (previousTheme != null && previousTheme.isDarkTheme) {
+ darkThemeSharedPreferences.edit().clear().apply();
+ }
+ if (customTheme.isAmoledTheme) {
+ redditDataRoomDatabase.customThemeDao().unsetAmoledTheme();
+ CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences);
+ } else if (previousTheme != null && previousTheme.isAmoledTheme) {
+ amoledThemeSharedPreferences.edit().clear().apply();
+ }
+ redditDataRoomDatabase.customThemeDao().insert(customTheme);
+
+ handler.post(insertCustomThemeListener::success);
+ }
});
}