From e666e6774e87fcaeb0405ee5bca941928af7dee6 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Tue, 14 May 2024 19:27:36 -0400 Subject: Back up and restore comment filters. --- .../infinityforreddit/asynctasks/BackupSettings.java | 13 ++++++++++++- .../infinityforreddit/asynctasks/RestoreSettings.java | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java index 2e353b06..1a6baf22 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java @@ -32,6 +32,8 @@ import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; @@ -124,6 +126,14 @@ public class BackupSettings { String postFilterUsageJson = new Gson().toJson(postFilterUsage); boolean res17 = saveDatabaseTableToFile(postFilterUsageJson, databaseDirFile.getAbsolutePath(), "/post_filter_usage.json"); + List commentFilters = redditDataRoomDatabase.commentFilterDao().getAllCommentFilters(); + String commentFiltersJson = new Gson().toJson(commentFilters); + boolean res18 = saveDatabaseTableToFile(commentFiltersJson, databaseDirFile.getAbsolutePath(), "/comment_filters.json"); + + List commentFilterUsage = redditDataRoomDatabase.commentFilterUsageDao().getAllCommentFilterUsageForBackup(); + String commentFilterUsageJson = new Gson().toJson(commentFilterUsage); + boolean res19 = saveDatabaseTableToFile(commentFilterUsageJson, databaseDirFile.getAbsolutePath(), "/comment_filter_usage.json"); + boolean zipRes = zipAndMoveToDestinationDir(context, contentResolver, destinationDirUri); try { @@ -134,7 +144,8 @@ public class BackupSettings { handler.post(() -> { boolean finalResult = res && res1 && res2 && res3 && res4 && res5 && res6 && res7 && res8 - && res9 && res10 && res11 && res12 && res13 && res14 && res15 && res16 && res17 && zipRes; + && res9 && res10 && res11 && res12 && res13 && res14 && res15 && res16 && res17 + && res18 && res19 && zipRes; if (finalResult) { backupSettingsListener.success(); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/RestoreSettings.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/RestoreSettings.java index a14e93d3..10671ecc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/RestoreSettings.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/RestoreSettings.java @@ -32,6 +32,8 @@ import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; @@ -132,6 +134,8 @@ public class RestoreSettings { File customThemesFile = new File(f.getAbsolutePath() + "/custom_themes.json"); File postFiltersFile = new File(f.getAbsolutePath() + "/post_filters.json"); File postFilterUsageFile = new File(f.getAbsolutePath() + "/post_filter_usage.json"); + File commentFiltersFile = new File(f.getAbsolutePath() + "/comment_filters.json"); + File commentFilterUsageFile = new File(f.getAbsolutePath() + "/comment_filter_usage.json"); if (anonymousSubscribedSubredditsFile.exists()) { List anonymousSubscribedSubreddits = getListFromFile(anonymousSubscribedSubredditsFile, new TypeToken>() {}.getType()); @@ -163,6 +167,15 @@ public class RestoreSettings { redditDataRoomDatabase.postFilterUsageDao().insertAll(postFilterUsage); } } + if (commentFiltersFile.exists()) { + List commentFilters = getListFromFile(commentFiltersFile, new TypeToken>() {}.getType()); + redditDataRoomDatabase.commentFilterDao().insertAll(commentFilters); + + if (commentFilterUsageFile.exists()) { + List commentFilterUsage = getListFromFile(commentFilterUsageFile, new TypeToken>() {}.getType()); + redditDataRoomDatabase.commentFilterUsageDao().insertAll(commentFilterUsage); + } + } } } } else { -- cgit v1.2.3