aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-12-09 07:15:17 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-12-09 07:15:17 +0000
commitc3b2ffa65308ca14969a82e490f0c662f1794425 (patch)
tree2d017df2b9888ebebe8124da0de8e4adf0102dff /app/src/main
parentfa5008ea5e304693423ce4850234aea51faca15b (diff)
downloadinfinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.tar
infinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.tar.gz
infinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.tar.bz2
infinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.tar.lz
infinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.tar.xz
infinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.tar.zst
infinity-for-reddit-c3b2ffa65308ca14969a82e490f0c662f1794425.zip
Add an option to delete all read posts.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteAllReadPostsAsyncTask.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/values/strings.xml2
-rw-r--r--app/src/main/res/xml/advanced_preferences.xml4
6 files changed, 59 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";
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3aa406a4..7e7ed640 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -446,6 +446,7 @@
<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_front_page_scrolled_positions_in_database_title">Delete All Front Page Scrolled Positions in Database</string>
+ <string name="settings_delete_read_posts_in_database_title">Delete All Read Posts in Database</string>
<string name="settings_delete_all_legacy_settings_title">Delete All Legacy Settings</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>
@@ -820,6 +821,7 @@
<string name="delete_all_post_layouts_success">Delete all post layouts successfully</string>
<string name="delete_all_themes_success">Delete all themes successfully</string>
<string name="delete_all_front_page_scrolled_positions_success">Delete all scrolled positions in front page successfully</string>
+ <string name="delete_all_read_posts_success">Delete all read posts successfully</string>
<string name="delete_all_legacy_settings_success">Delete all legacy settings successfully</string>
<string name="reset_all_settings_success">Reset all settings successfully</string>
diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml
index 0d6c02e5..6992530d 100644
--- a/app/src/main/res/xml/advanced_preferences.xml
+++ b/app/src/main/res/xml/advanced_preferences.xml
@@ -27,6 +27,10 @@
app:title="@string/settings_delete_front_page_scrolled_positions_in_database_title" />
<Preference
+ app:key="delete_read_posts_in_database"
+ app:title="@string/settings_delete_read_posts_in_database_title" />
+
+ <Preference
app:key="delete_all_legacy_settings"
app:title="@string/settings_delete_all_legacy_settings_title" />