From 6ad725762ba11100b7373767d8c3c3feee88364c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 27 Mar 2020 09:51:53 +0800 Subject: Still implementing custom themes. --- .../Activity/CustomThemeListingActivity.java | 51 +++++++++++++++++++++- .../infinityforreddit/Activity/MainActivity.java | 2 +- .../Activity/MultiRedditListingActivity.java | 2 +- .../Activity/ViewSubredditDetailActivity.java | 2 +- .../AsyncTask/DeleteThemeAsyncTask.java | 27 +++++++++++- .../drawable-night/ic_add_bottom_app_bar_24dp.xml | 9 ---- .../res/drawable-night/ic_add_day_night_24dp.xml | 9 ++++ .../res/drawable/ic_add_bottom_app_bar_24dp.xml | 9 ---- .../main/res/drawable/ic_add_day_night_24dp.xml | 9 ++++ .../res/layout/activity_custom_theme_listing.xml | 2 +- .../res/layout/activity_multi_reddit_listing.xml | 2 +- .../res/layout/activity_view_subreddit_detail.xml | 2 +- app/src/main/res/layout/app_bar_main.xml | 2 +- .../res/layout/item_predefined_custom_theme.xml | 2 +- app/src/main/res/layout/item_user_custom_theme.xml | 2 +- app/src/main/res/values/strings.xml | 3 +- 16 files changed, 103 insertions(+), 32 deletions(-) delete mode 100644 app/src/main/res/drawable-night/ic_add_bottom_app_bar_24dp.xml create mode 100644 app/src/main/res/drawable-night/ic_add_day_night_24dp.xml delete mode 100644 app/src/main/res/drawable/ic_add_bottom_app_bar_24dp.xml create mode 100644 app/src/main/res/drawable/ic_add_day_night_24dp.xml (limited to 'app/src/main') 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 { 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); + } } diff --git a/app/src/main/res/drawable-night/ic_add_bottom_app_bar_24dp.xml b/app/src/main/res/drawable-night/ic_add_bottom_app_bar_24dp.xml deleted file mode 100644 index b6814bc2..00000000 --- a/app/src/main/res/drawable-night/ic_add_bottom_app_bar_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable-night/ic_add_day_night_24dp.xml b/app/src/main/res/drawable-night/ic_add_day_night_24dp.xml new file mode 100644 index 00000000..b6814bc2 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_add_day_night_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_add_bottom_app_bar_24dp.xml b/app/src/main/res/drawable/ic_add_bottom_app_bar_24dp.xml deleted file mode 100644 index ed95d188..00000000 --- a/app/src/main/res/drawable/ic_add_bottom_app_bar_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_add_day_night_24dp.xml b/app/src/main/res/drawable/ic_add_day_night_24dp.xml new file mode 100644 index 00000000..ed95d188 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_day_night_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_custom_theme_listing.xml b/app/src/main/res/layout/activity_custom_theme_listing.xml index 260453e6..37b8f878 100644 --- a/app/src/main/res/layout/activity_custom_theme_listing.xml +++ b/app/src/main/res/layout/activity_custom_theme_listing.xml @@ -45,7 +45,7 @@ android:layout_margin="@dimen/fab_margin" android:layout_gravity="bottom|end" app:backgroundTint="?attr/colorPrimaryLightTheme" - app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp" + app:srcCompat="@drawable/ic_add_day_night_24dp" app:tint="@android:color/white" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_multi_reddit_listing.xml b/app/src/main/res/layout/activity_multi_reddit_listing.xml index ea101e05..65285189 100644 --- a/app/src/main/res/layout/activity_multi_reddit_listing.xml +++ b/app/src/main/res/layout/activity_multi_reddit_listing.xml @@ -78,7 +78,7 @@ android:layout_margin="@dimen/fab_margin" android:layout_gravity="bottom|end" app:backgroundTint="?attr/colorPrimaryLightTheme" - app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp" + app:srcCompat="@drawable/ic_add_day_night_24dp" app:tint="@android:color/white" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml index 5f2c2294..3337fc67 100644 --- a/app/src/main/res/layout/activity_view_subreddit_detail.xml +++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml @@ -201,7 +201,7 @@ android:layout_margin="@dimen/fab_margin" android:visibility="gone" app:backgroundTint="?attr/colorPrimaryLightTheme" - app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp" + app:srcCompat="@drawable/ic_add_day_night_24dp" app:tint="@android:color/white" app:layout_anchor="@id/bottom_navigation_view_subreddit_detail_activity" /> diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index cc63287c..b1d9b330 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -132,7 +132,7 @@ android:layout_margin="@dimen/fab_margin" android:visibility="gone" app:backgroundTint="?attr/colorPrimaryLightTheme" - app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp" + app:srcCompat="@drawable/ic_add_day_night_24dp" app:tint="@android:color/white" app:layout_anchor="@id/bottom_navigation_main_activity" /> diff --git a/app/src/main/res/layout/item_predefined_custom_theme.xml b/app/src/main/res/layout/item_predefined_custom_theme.xml index cbc6bb20..37dcdb0c 100644 --- a/app/src/main/res/layout/item_predefined_custom_theme.xml +++ b/app/src/main/res/layout/item_predefined_custom_theme.xml @@ -29,6 +29,6 @@ android:layout_height="24dp" android:layout_gravity="center_vertical" android:layout_marginStart="32dp" - android:src="@drawable/ic_add_24dp" /> + android:src="@drawable/ic_add_day_night_24dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_user_custom_theme.xml b/app/src/main/res/layout/item_user_custom_theme.xml index e4ea128d..55891961 100644 --- a/app/src/main/res/layout/item_user_custom_theme.xml +++ b/app/src/main/res/layout/item_user_custom_theme.xml @@ -29,7 +29,7 @@ android:layout_height="24dp" android:layout_gravity="center_vertical" android:layout_marginStart="32dp" - android:src="@drawable/ic_add_24dp" + android:src="@drawable/ic_add_day_night_24dp" android:background="?attr/selectableItemBackgroundBorderless" /> Dark Theme Amoled Theme Manage Themes - Custom themes cannot be applied to settings page. + Custom themes cannot be applied to settings page (except toolbar, status bar and navigation bar). Cannot get the link @@ -617,6 +617,7 @@ Edit Theme Name Edit Theme Delete Theme + Are you sure to delete %1$s? Share Theme Change Name -- cgit v1.2.3