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 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/advanced_preferences.xml | 4 ++++ 4 files changed, 26 insertions(+) (limited to 'app') 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"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9d918d75..0dbcce20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -458,6 +458,7 @@ Delete All Sort Types in Database Delete All Post Layouts in Database Delete All Themes in Database + Delete All Post Feed Scrolled Positions in Database Reset All Settings Clean the database and shared preferences Restart the app to see the changes @@ -778,6 +779,7 @@ Delete all sort types successful Delete all post layouts successful Delete all themes successful + Delete all post feed scrolled positions successful Reset all settings successful Theme Preview diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml index 432623d3..224433ba 100644 --- a/app/src/main/res/xml/advanced_preferences.xml +++ b/app/src/main/res/xml/advanced_preferences.xml @@ -22,6 +22,10 @@ app:key="delete_all_themes_in_database" app:title="@string/settings_delete_all_themes_in_database_title" /> + + -- cgit v1.2.3