diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-10 15:15:59 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-10 15:15:59 +0000 |
commit | 34a9cee965e76efea629fba348395f5a8d20353d (patch) | |
tree | c46d8453082182891edd0b41306376aae1bbf7c5 | |
parent | 75c9a52cf7c91c37bb3b350db1ce8b664822b250 (diff) | |
download | infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.tar infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.tar.gz infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.tar.bz2 infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.tar.lz infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.tar.xz infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.tar.zst infinity-for-reddit-34a9cee965e76efea629fba348395f5a8d20353d.zip |
Fix only backing up post history shared preferences. Show the password of the backup zip.
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java | 44 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 |
2 files changed, 24 insertions, 22 deletions
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 e4f18e22..044353f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java @@ -45,27 +45,38 @@ public class BackupSettings { SharedPreferences postHistorySharedPreferences, BackupSettingsListener backupSettingsListener) { executor.execute(() -> { - boolean res = saveSharedPreferencesToFile(context, defaultSharedPreferences, + String backupDir = context.getExternalCacheDir() + "/Backup/" + BuildConfig.VERSION_NAME; + File backupDirFile = new File(backupDir); + if (new File(backupDir).exists()) { + try { + FileUtils.deleteDirectory(backupDirFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + backupDirFile.mkdirs(); + + boolean res = saveSharedPreferencesToFile(context, defaultSharedPreferences, backupDir, SharedPreferencesUtils.DEFAULT_PREFERENCES_FILE); - boolean res1 = saveSharedPreferencesToFile(context, lightThemeSharedPreferences, + boolean res1 = saveSharedPreferencesToFile(context, lightThemeSharedPreferences, backupDir, CustomThemeSharedPreferencesUtils.LIGHT_THEME_SHARED_PREFERENCES_FILE); - boolean res2 = saveSharedPreferencesToFile(context, darkThemeSharedPreferences, + boolean res2 = saveSharedPreferencesToFile(context, darkThemeSharedPreferences, backupDir, CustomThemeSharedPreferencesUtils.DARK_THEME_SHARED_PREFERENCES_FILE); - boolean res3 = saveSharedPreferencesToFile(context, amoledThemeSharedPreferences, + boolean res3 = saveSharedPreferencesToFile(context, amoledThemeSharedPreferences, backupDir, CustomThemeSharedPreferencesUtils.AMOLED_THEME_SHARED_PREFERENCES_FILE); - boolean res4 = saveSharedPreferencesToFile(context, sortTypeSharedPreferences, + boolean res4 = saveSharedPreferencesToFile(context, sortTypeSharedPreferences, backupDir, SharedPreferencesUtils.SORT_TYPE_SHARED_PREFERENCES_FILE); - boolean res5 = saveSharedPreferencesToFile(context, postLayoutSharedPreferences, + boolean res5 = saveSharedPreferencesToFile(context, postLayoutSharedPreferences, backupDir, SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE); - boolean res6 = saveSharedPreferencesToFile(context, postFeedScrolledPositionSharedPreferences, + boolean res6 = saveSharedPreferencesToFile(context, postFeedScrolledPositionSharedPreferences, backupDir, SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE); - boolean res7 = saveSharedPreferencesToFile(context, mainActivityTabsSharedPreferences, + boolean res7 = saveSharedPreferencesToFile(context, mainActivityTabsSharedPreferences, backupDir, SharedPreferencesUtils.MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE); - boolean res8 = saveSharedPreferencesToFile(context, nsfwAndSpoilerSharedPreferencs, + boolean res8 = saveSharedPreferencesToFile(context, nsfwAndSpoilerSharedPreferencs, backupDir, SharedPreferencesUtils.NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE); - boolean res9 = saveSharedPreferencesToFile(context, bottomAppBarSharedPreferences, + boolean res9 = saveSharedPreferencesToFile(context, bottomAppBarSharedPreferences, backupDir, SharedPreferencesUtils.BOTTOM_APP_BAR_SHARED_PREFERENCES_FILE); - boolean res10 = saveSharedPreferencesToFile(context, postHistorySharedPreferences, + boolean res10 = saveSharedPreferencesToFile(context, postHistorySharedPreferences, backupDir, SharedPreferencesUtils.POST_HISTORY_SHARED_PREFERENCES_FILE); boolean zipRes = zipAndMoveToDestinationDir(context, contentResolver, destinationDirUri); @@ -92,21 +103,12 @@ public class BackupSettings { } private static boolean saveSharedPreferencesToFile(Context context, SharedPreferences sharedPreferences, - String fileName) { + String backupDir, String fileName) { boolean result = false; ObjectOutputStream output = null; try { - String backupDir = context.getExternalCacheDir() + "/Backup/" + BuildConfig.VERSION_NAME; - if (!new File(backupDir).exists()) { - new File(backupDir).mkdirs(); - } else { - File backupDirFile = new File(backupDir); - FileUtils.deleteDirectory(backupDirFile); - backupDirFile.mkdirs(); - } - output = new ObjectOutputStream(new FileOutputStream(new File(backupDir + "/" + fileName + ".txt"))); output.writeObject(sharedPreferences.getAll()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b10909a0..e41edd82 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1062,7 +1062,7 @@ <string name="anonymous_front_page_no_subscriptions">Start by joining a subreddit!</string> - <string name="backup_settings_success">Successfully exported settings to the destination directory</string> + <string name="backup_settings_success">Successfully exported settings to the destination directory. The password of the generated zip file is 123321. Please don\'t modify the zip file.</string> <string name="create_zip_in_destination_directory_failed">Could not create backup zip in the destination directory</string> <string name="backup_some_settings_failed">Could not backup some settings but others were successfully exported to the destination directory</string> <string name="restore_settings_success">Successfully restored settings. Restart the app to see the changes.</string> |