From 109b4be8c3002df503f86ac94d57f1a1be005cec Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 31 Jul 2020 00:04:57 +0800 Subject: Add an option to delete all the post feed scrolled positions. --- .../Settings/AdvancedPreferenceFragment.java | 19 +++++++++++++++++++ .../Utils/SharedPreferencesUtils.java | 1 + 2 files changed, 20 insertions(+) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java index de92c7fe..43779da2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java @@ -53,6 +53,9 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { @Named("dark_theme") SharedPreferences darkThemeSharedPreferences; @Inject + @Named("post_feed_scrolled_position_cache") + SharedPreferences postFeedScrolledPositionSharedPreferences; + @Inject @Named("amoled_theme") SharedPreferences amoledThemeSharedPreferences; private Activity activity; @@ -68,6 +71,7 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { Preference deleteSortTypePreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE); Preference deletePostLaoutPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE); Preference deleteAllThemesPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_THEMES_IN_DATABASE); + Preference deletePostFeedScrolledPositionsPreference = findPreference(SharedPreferencesUtils.DELETE_POST_FEED_SCROLLED_POSITIONS_IN_DATABASE); Preference resetAllSettingsPreference = findPreference(SharedPreferencesUtils.RESET_ALL_SETTINGS); if (deleteSubredditsPreference != null) { @@ -142,6 +146,21 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { }); } + if (deletePostFeedScrolledPositionsPreference != null) { + deletePostFeedScrolledPositionsPreference.setOnPreferenceClickListener(preference -> { + new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.are_you_sure) + .setPositiveButton(R.string.yes, (dialogInterface, i) + -> { + postFeedScrolledPositionSharedPreferences.edit().clear().apply(); + Toast.makeText(activity, R.string.delete_all_post_feed_scrolled_positions_success, Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton(R.string.no, null) + .show(); + return true; + }); + } + if (resetAllSettingsPreference != null) { resetAllSettingsPreference.setOnPreferenceClickListener(preference -> { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 783ab80c..50294522 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -119,6 +119,7 @@ public class SharedPreferencesUtils { public static final String DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE = "delete_all_sort_type_data_in_database"; public static final String DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE = "delete_all_post_layout_data_in_database"; public static final String DELETE_ALL_THEMES_IN_DATABASE = "delete_all_themes_in_database"; + public static final String DELETE_POST_FEED_SCROLLED_POSITIONS_IN_DATABASE = "delete_post_feed_scrolled_positions_in_database"; public static final String RESET_ALL_SETTINGS = "reset_all_settings"; public static final String MAIN_PAGE_TAB_1_TITLE = "main_page_tab_1_title"; public static final String MAIN_PAGE_TAB_2_TITLE = "main_page_tab_2_title"; -- cgit v1.2.3