Add an option to delete all the post feed scrolled positions.

This commit is contained in:
Alex Ning 2020-07-31 00:04:57 +08:00
parent 61d3302a30
commit 109b4be8c3
4 changed files with 26 additions and 0 deletions

View File

@ -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)

View File

@ -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";

View File

@ -458,6 +458,7 @@
<string name="settings_delete_all_sort_type_data_in_database_title">Delete All Sort Types in Database</string>
<string name="settings_delete_all_post_layout_data_in_database_title">Delete All Post Layouts in Database</string>
<string name="settings_delete_all_themes_in_database_title">Delete All Themes in Database</string>
<string name="settings_delete_post_feed_scrolled_positions_in_database_title">Delete All Post Feed Scrolled Positions in Database</string>
<string name="settings_reset_all_settings_title">Reset All Settings</string>
<string name="settings_advanced_settings_summary">Clean the database and shared preferences</string>
<string name="settings_tab_info">Restart the app to see the changes</string>
@ -778,6 +779,7 @@
<string name="delete_all_sort_types_success">Delete all sort types successful</string>
<string name="delete_all_post_layouts_success">Delete all post layouts successful</string>
<string name="delete_all_themes_success">Delete all themes successful</string>
<string name="delete_all_post_feed_scrolled_positions_success">Delete all post feed scrolled positions successful</string>
<string name="reset_all_settings_success">Reset all settings successful</string>
<string name="theme_preview">Theme Preview</string>

View File

@ -22,6 +22,10 @@
app:key="delete_all_themes_in_database"
app:title="@string/settings_delete_all_themes_in_database_title" />
<Preference
app:key="delete_post_feed_scrolled_positions_in_database"
app:title="@string/settings_delete_post_feed_scrolled_positions_in_database_title" />
<Preference
app:key="reset_all_settings"
app:title="@string/settings_reset_all_settings_title" />