diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-03-27 01:51:53 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-03-27 01:51:53 +0000 |
commit | 6ad725762ba11100b7373767d8c3c3feee88364c (patch) | |
tree | 7ddb1fc3267e9910ca73a2d982190afc010c571a /app/src/main/java/ml/docilealligator | |
parent | 3dca261deaa2674b1faca52fec213f6cc960a61f (diff) | |
download | infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.tar infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.tar.gz infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.tar.bz2 infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.tar.lz infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.tar.xz infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.tar.zst infinity-for-reddit-6ad725762ba11100b7373767d8c3c3feee88364c.zip |
Still implementing custom themes.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
5 files changed, 77 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 6bc3a927..eb918960 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java @@ -18,6 +18,9 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + import javax.inject.Inject; import javax.inject.Named; @@ -28,11 +31,13 @@ import ml.docilealligator.infinityforreddit.AsyncTask.ChangeThemeNameAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.DeleteThemeAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Fragment.CustomThemeOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SelectBaseThemeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils; public class CustomThemeListingActivity extends BaseActivity implements CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener { @@ -51,6 +56,15 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh RedditDataRoomDatabase redditDataRoomDatabase; @Inject CustomThemeWrapper customThemeWrapper; + @Inject + @Named("light_theme") + SharedPreferences lightThemeSharedPreferences; + @Inject + @Named("dark_theme") + SharedPreferences darkThemeSharedPreferences; + @Inject + @Named("amoled_theme") + SharedPreferences amoledThemeSharedPreferences; public CustomThemeViewModel customThemeViewModel; @Override @@ -62,6 +76,8 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh ButterKnife.bind(this); + EventBus.getDefault().register(this); + applyCustomTheme(); setSupportActionBar(toolbar); @@ -125,7 +141,7 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh if (imm != null) { imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); } - new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldName, themeNameEditText.getText().toString()); + new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldName, themeNameEditText.getText().toString()).execute(); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { if (imm != null) { @@ -142,6 +158,37 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh @Override public void delete(String name) { - new DeleteThemeAsyncTask(redditDataRoomDatabase, name).execute(); + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.delete_theme) + .setMessage(getString(R.string.delete_theme_dialog_message, name)) + .setPositiveButton(R.string.yes, (dialogInterface, i) + -> new DeleteThemeAsyncTask(redditDataRoomDatabase, name, (isLightTheme, isDarkTheme, isAmoledTheme) -> { + if (isLightTheme) { + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences( + CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), lightThemeSharedPreferences); + } + if (isDarkTheme) { + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences( + CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), darkThemeSharedPreferences); + } + if (isAmoledTheme) { + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences( + CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), amoledThemeSharedPreferences); + } + EventBus.getDefault().post(new RecreateActivityEvent()); + }).execute()) + .setNegativeButton(R.string.no, null) + .show(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + EventBus.getDefault().unregister(this); + } + + @Subscribe + public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { + recreate(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index b65fc134..1a38677a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -305,7 +305,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyTabLayoutTheme(tabLayout); bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); - applyFABTheme(fab, R.drawable.ic_add_bottom_app_bar_24dp); + applyFABTheme(fab, R.drawable.ic_add_day_night_24dp); } private void getCurrentAccountAndBindView() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index e5069e16..a4ccc4b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -258,6 +258,6 @@ public class MultiRedditListingActivity extends BaseActivity { mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); - applyFABTheme(fab, R.drawable.ic_add_bottom_app_bar_24dp); + applyFABTheme(fab, R.drawable.ic_add_day_night_24dp); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index d34b133b..13aca8a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -360,7 +360,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp multiRedditBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); messageBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); profileBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - applyFABTheme(fab, R.drawable.ic_add_bottom_app_bar_24dp); + applyFABTheme(fab, R.drawable.ic_add_day_night_24dp); unsubscribedColor = mCustomThemeWrapper.getUnsubscribed(); subscribedColor = mCustomThemeWrapper.getSubscribed(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteThemeAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteThemeAsyncTask.java index 7b8caec2..c166087c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteThemeAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteThemeAsyncTask.java @@ -2,20 +2,43 @@ package ml.docilealligator.infinityforreddit.AsyncTask; import android.os.AsyncTask; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class DeleteThemeAsyncTask extends AsyncTask<Void, Void, Void> { private RedditDataRoomDatabase redditDataRoomDatabase; private String themeName; + private DeleteThemeAsyncTaskListener deleteThemeAsyncTaskListener; + private boolean isLightTheme = false; + private boolean isDarkTheme = false; + private boolean isAmoledTheme = false; - public DeleteThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String themeName) { + public interface DeleteThemeAsyncTaskListener { + void success(boolean isLightTheme, boolean isDarkTheme, boolean isAmoledTheme); + } + + public DeleteThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String themeName, + DeleteThemeAsyncTaskListener deleteThemeAsyncTaskListener) { this.redditDataRoomDatabase = redditDataRoomDatabase; this.themeName = themeName; + this.deleteThemeAsyncTaskListener = deleteThemeAsyncTaskListener; } @Override protected Void doInBackground(Void... voids) { - redditDataRoomDatabase.customThemeDao().deleteCustomTheme(themeName); + CustomTheme customTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(themeName); + if (customTheme != null) { + isLightTheme = customTheme.isLightTheme; + isDarkTheme = customTheme.isDarkTheme; + isAmoledTheme = customTheme.isAmoledTheme; + redditDataRoomDatabase.customThemeDao().deleteCustomTheme(themeName); + } return null; } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + deleteThemeAsyncTaskListener.success(isLightTheme, isDarkTheme, isAmoledTheme); + } } |