mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-08-18 11:03:26 +00:00
Backup and restore comment drafts, read posts, reminders.
This commit is contained in:
@ -32,6 +32,7 @@ import ml.docilealligator.infinityforreddit.BuildConfig;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.account.Account;
|
import ml.docilealligator.infinityforreddit.account.Account;
|
||||||
|
import ml.docilealligator.infinityforreddit.comment.CommentDraft;
|
||||||
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter;
|
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter;
|
||||||
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
|
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
||||||
@ -39,6 +40,8 @@ import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubr
|
|||||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
||||||
|
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||||
|
import ml.docilealligator.infinityforreddit.reminder.Reminder;
|
||||||
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
|
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
|
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
|
||||||
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
|
||||||
@ -141,6 +144,18 @@ public class BackupSettings {
|
|||||||
String commentFilterUsageJson = new Gson().toJson(commentFilterUsage);
|
String commentFilterUsageJson = new Gson().toJson(commentFilterUsage);
|
||||||
boolean res19 = saveDatabaseTableToFile(commentFilterUsageJson, databaseDirFile.getAbsolutePath(), "/comment_filter_usage.json");
|
boolean res19 = saveDatabaseTableToFile(commentFilterUsageJson, databaseDirFile.getAbsolutePath(), "/comment_filter_usage.json");
|
||||||
|
|
||||||
|
List<CommentDraft> commentDrafts = redditDataRoomDatabase.commentDraftDao().getCommentDraftsForBackup();
|
||||||
|
String commentDraftsJson = new Gson().toJson(commentDrafts);
|
||||||
|
boolean res20 = saveDatabaseTableToFile(commentDraftsJson, databaseDirFile.getAbsolutePath(), "/comment_drafts.json");
|
||||||
|
|
||||||
|
List<ReadPost> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsForBackup();
|
||||||
|
String readPostsJson = new Gson().toJson(readPosts);
|
||||||
|
boolean res21 = saveDatabaseTableToFile(readPostsJson, databaseDirFile.getAbsolutePath(), "/read_posts.json");
|
||||||
|
|
||||||
|
List<Reminder> reminders = redditDataRoomDatabase.reminderDao().getAllRemindersForBackup();
|
||||||
|
String remindersJson = new Gson().toJson(reminders);
|
||||||
|
boolean res22 = saveDatabaseTableToFile(remindersJson, databaseDirFile.getAbsolutePath(), "/reminders.json");
|
||||||
|
|
||||||
boolean zipRes = zipAndMoveToDestinationDir(context, cacheDir, contentResolver, destinationDirUri);
|
boolean zipRes = zipAndMoveToDestinationDir(context, cacheDir, contentResolver, destinationDirUri);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -152,7 +167,7 @@ public class BackupSettings {
|
|||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
boolean finalResult = res && res1 && res2 && res3 && res4 && res5 && res6 && res7 && res8
|
boolean finalResult = res && res1 && res2 && res3 && res4 && res5 && res6 && res7 && res8
|
||||||
&& res9 && res10 && res11 && res12 && res13 && res14 && res15 && res16 && res17
|
&& res9 && res10 && res11 && res12 && res13 && res14 && res15 && res16 && res17
|
||||||
&& res18 && res19 && zipRes;
|
&& res18 && res19 && res20 && res21 && res22 && zipRes;
|
||||||
if (finalResult) {
|
if (finalResult) {
|
||||||
backupSettingsListener.success();
|
backupSettingsListener.success();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import java.util.concurrent.Executor;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.account.Account;
|
import ml.docilealligator.infinityforreddit.account.Account;
|
||||||
|
import ml.docilealligator.infinityforreddit.comment.CommentDraft;
|
||||||
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter;
|
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter;
|
||||||
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
|
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
||||||
@ -39,6 +40,8 @@ import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubr
|
|||||||
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
||||||
|
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||||
|
import ml.docilealligator.infinityforreddit.reminder.Reminder;
|
||||||
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
|
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
|
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
|
||||||
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
|
||||||
@ -141,6 +144,9 @@ public class RestoreSettings {
|
|||||||
File postFilterUsageFile = new File(f.getAbsolutePath() + "/post_filter_usage.json");
|
File postFilterUsageFile = new File(f.getAbsolutePath() + "/post_filter_usage.json");
|
||||||
File commentFiltersFile = new File(f.getAbsolutePath() + "/comment_filters.json");
|
File commentFiltersFile = new File(f.getAbsolutePath() + "/comment_filters.json");
|
||||||
File commentFilterUsageFile = new File(f.getAbsolutePath() + "/comment_filter_usage.json");
|
File commentFilterUsageFile = new File(f.getAbsolutePath() + "/comment_filter_usage.json");
|
||||||
|
File commentDraftsFile = new File(f.getAbsolutePath() + "/comment_drafts.json");
|
||||||
|
File readPostsFile = new File(f.getAbsolutePath() + "/read_posts.json");
|
||||||
|
File remindersFile = new File(f.getAbsolutePath() + "/reminders.json");
|
||||||
|
|
||||||
if (anonymousSubscribedSubredditsFile.exists()) {
|
if (anonymousSubscribedSubredditsFile.exists()) {
|
||||||
List<SubscribedSubredditData> anonymousSubscribedSubreddits = getListFromFile(anonymousSubscribedSubredditsFile, new TypeToken<List<SubscribedSubredditData>>() {}.getType());
|
List<SubscribedSubredditData> anonymousSubscribedSubreddits = getListFromFile(anonymousSubscribedSubredditsFile, new TypeToken<List<SubscribedSubredditData>>() {}.getType());
|
||||||
@ -181,6 +187,24 @@ public class RestoreSettings {
|
|||||||
redditDataRoomDatabase.commentFilterUsageDao().insertAll(commentFilterUsage);
|
redditDataRoomDatabase.commentFilterUsageDao().insertAll(commentFilterUsage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (commentDraftsFile.exists()) {
|
||||||
|
List<CommentDraft> commentDrafts = getListFromFile(commentDraftsFile, new TypeToken<List<CommentDraft>>() {}.getType());
|
||||||
|
if (commentDrafts != null) {
|
||||||
|
redditDataRoomDatabase.commentDraftDao().insertAll(commentDrafts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (readPostsFile.exists()) {
|
||||||
|
List<ReadPost> readPosts = getListFromFile(readPostsFile, new TypeToken<List<ReadPost>>() {}.getType());
|
||||||
|
if (readPosts != null) {
|
||||||
|
redditDataRoomDatabase.readPostDao().insertAll(readPosts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (remindersFile.exists()) {
|
||||||
|
List<Reminder> reminders = getListFromFile(remindersFile, new TypeToken<List<Reminder>>() {}.getType());
|
||||||
|
if (reminders != null) {
|
||||||
|
redditDataRoomDatabase.reminderDao().insertAll(reminders);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -6,15 +6,22 @@ import androidx.room.Delete
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import ml.docilealligator.infinityforreddit.commentfilter.CommentFilterUsage
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CommentDraftDao {
|
interface CommentDraftDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insert(commentDraft: CommentDraft)
|
suspend fun insert(commentDraft: CommentDraft)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertAll(commentDrafts: List<CommentDraft>)
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun delete(commentDraft: CommentDraft)
|
suspend fun delete(commentDraft: CommentDraft)
|
||||||
|
|
||||||
@Query("SELECT * FROM comment_draft WHERE full_name = :fullName AND draft_type = :draftType")
|
@Query("SELECT * FROM comment_draft WHERE full_name = :fullName AND draft_type = :draftType")
|
||||||
fun getCommentDraftLiveData(fullName: String, draftType: DraftType): LiveData<CommentDraft>
|
fun getCommentDraftLiveData(fullName: String, draftType: DraftType): LiveData<CommentDraft>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM comment_draft")
|
||||||
|
fun getCommentDraftsForBackup(): List<CommentDraft>
|
||||||
}
|
}
|
||||||
@ -14,12 +14,18 @@ public interface ReadPostDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insert(ReadPost readPost);
|
void insert(ReadPost readPost);
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
void insertAll(List<ReadPost> readPosts);
|
||||||
|
|
||||||
@Query("SELECT * FROM read_posts WHERE username = :username AND (:before IS NULL OR time < :before) AND read_post_type = :readPostType ORDER BY time DESC LIMIT 25")
|
@Query("SELECT * FROM read_posts WHERE username = :username AND (:before IS NULL OR time < :before) AND read_post_type = :readPostType ORDER BY time DESC LIMIT 25")
|
||||||
ListenableFuture<List<ReadPost>> getAllReadPostsListenableFuture(String username, Long before, @ReadPostType int readPostType);
|
ListenableFuture<List<ReadPost>> getAllReadPostsListenableFuture(String username, Long before, @ReadPostType int readPostType);
|
||||||
|
|
||||||
@Query("SELECT * FROM read_posts WHERE username = :username AND (:before IS NULL OR time < :before) AND read_post_type = :readPostType ORDER BY time DESC LIMIT 25")
|
@Query("SELECT * FROM read_posts WHERE username = :username AND (:before IS NULL OR time < :before) AND read_post_type = :readPostType ORDER BY time DESC LIMIT 25")
|
||||||
List<ReadPost> getAllReadPosts(String username, Long before, @ReadPostType int readPostType);
|
List<ReadPost> getAllReadPosts(String username, Long before, @ReadPostType int readPostType);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM read_posts")
|
||||||
|
List<ReadPost> getAllReadPostsForBackup();
|
||||||
|
|
||||||
@Query("SELECT * FROM read_posts WHERE username = :username AND read_post_type != :excludedReadPostType AND read_post_type != 0 AND id IN (:postIds)")
|
@Query("SELECT * FROM read_posts WHERE username = :username AND read_post_type != :excludedReadPostType AND read_post_type != 0 AND id IN (:postIds)")
|
||||||
List<ReadPost> getAllReadPostsForMetadata(String username, @ReadPostType int excludedReadPostType, List<String> postIds);
|
List<ReadPost> getAllReadPostsForMetadata(String username, @ReadPostType int excludedReadPostType, List<String> postIds);
|
||||||
|
|
||||||
|
|||||||
@ -12,9 +12,15 @@ interface ReminderDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insert(reminder: Reminder)
|
suspend fun insert(reminder: Reminder)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertAll(reminders: List<Reminder>)
|
||||||
|
|
||||||
@Query("SELECT * FROM reminders")
|
@Query("SELECT * FROM reminders")
|
||||||
suspend fun getAllReminders(): List<Reminder>
|
suspend fun getAllReminders(): List<Reminder>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM reminders")
|
||||||
|
fun getAllRemindersForBackup(): List<Reminder>
|
||||||
|
|
||||||
@Query("SELECT * FROM reminders")
|
@Query("SELECT * FROM reminders")
|
||||||
fun getAllRemindersFlow(): Flow<List<Reminder>>
|
fun getAllRemindersFlow(): Flow<List<Reminder>>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user