diff options
Diffstat (limited to 'app/src/main/java')
4 files changed, 53 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java new file mode 100644 index 00000000..34098ef2 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java @@ -0,0 +1,33 @@ +package ml.docilealligator.infinityforreddit.asynctasks; + +import android.os.AsyncTask; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllReadPostsAsyncTask extends AsyncTask<Void, Void, Void> { + + public interface DeleteAllReadPostsAsyncTaskListener { + void success(); + } + + private RedditDataRoomDatabase redditDataRoomDatabase; + private DeleteAllReadPostsAsyncTaskListener deleteAllReadPostsAsyncTaskListener; + + public DeleteAllReadPostsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, + DeleteAllReadPostsAsyncTaskListener deleteAllReadPostsAsyncTaskListener) { + this.redditDataRoomDatabase = redditDataRoomDatabase; + this.deleteAllReadPostsAsyncTaskListener = deleteAllReadPostsAsyncTaskListener; + } + + @Override + protected Void doInBackground(Void... voids) { + redditDataRoomDatabase.readPostDao().deleteAllReadPosts(); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + deleteAllReadPostsAsyncTaskListener.success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java index d129e109..2390f59a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java @@ -20,4 +20,7 @@ public interface ReadPostDao { @Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts LIMIT 100) AND username = :username") void deleteOldestReadPosts(String username); + + @Query("DELETE FROM read_posts") + void deleteAllReadPosts(); } 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 4c3e602e..7b586b5c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java @@ -20,6 +20,7 @@ import javax.inject.Inject; import javax.inject.Named; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllPostLayoutsAsyncTask; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllReadPostsAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSortTypesAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSubredditsAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllThemesAsyncTask; @@ -78,6 +79,7 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { 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_FRONT_PAGE_SCROLLED_POSITIONS_IN_DATABASE); + Preference deleteReadPostsPreference = findPreference(SharedPreferencesUtils.DELETE_READ_POSTS_IN_DATABASE); Preference deleteAllLegacySettingsPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_LEGACY_SETTINGS); Preference resetAllSettingsPreference = findPreference(SharedPreferencesUtils.RESET_ALL_SETTINGS); @@ -168,6 +170,20 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { }); } + if (deleteReadPostsPreference != null) { + deleteReadPostsPreference.setOnPreferenceClickListener(preference -> { + new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.are_you_sure) + .setPositiveButton(R.string.yes, (dialogInterface, i) + -> new DeleteAllReadPostsAsyncTask(mRedditDataRoomDatabase, () -> { + Toast.makeText(activity, R.string.delete_all_read_posts_success, Toast.LENGTH_SHORT).show(); + }).execute()) + .setNegativeButton(R.string.no, null) + .show(); + return true; + }); + } + if (deleteAllLegacySettingsPreference != null) { deleteAllLegacySettingsPreference.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 674ea87d..7f5389b6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -110,6 +110,7 @@ public class SharedPreferencesUtils { 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_FRONT_PAGE_SCROLLED_POSITIONS_IN_DATABASE = "delete_front_page_scrolled_positions_in_database"; + public static final String DELETE_READ_POSTS_IN_DATABASE = "delete_read_posts_in_database"; public static final String DELETE_ALL_LEGACY_SETTINGS = "delete_all_legacy_settings"; public static final String RESET_ALL_SETTINGS = "reset_all_settings"; public static final String IMAGE_DOWNLOAD_LOCATION = "image_download_location"; |