From a100fca5afff2f07a4b672441ee2c398987d2b6a Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 10 Nov 2021 09:35:31 -0600 Subject: [PATCH] Back up string set preferences --- app/src/main/java/org/tasks/backup/BackupContainer.kt | 5 +++-- app/src/main/java/org/tasks/backup/TasksJsonExporter.kt | 4 +++- app/src/main/java/org/tasks/backup/TasksJsonImporter.kt | 4 ++++ app/src/main/java/org/tasks/preferences/Preferences.kt | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/tasks/backup/BackupContainer.kt b/app/src/main/java/org/tasks/backup/BackupContainer.kt index a7aeb3cb1..6b6cfd8bf 100644 --- a/app/src/main/java/org/tasks/backup/BackupContainer.kt +++ b/app/src/main/java/org/tasks/backup/BackupContainer.kt @@ -17,8 +17,9 @@ class BackupContainer( val intPrefs: Map?, val longPrefs: Map?, val stringPrefs: Map?, - val boolPrefs: Map?) { - + val boolPrefs: Map?, + val setPrefs: Map>?, +) { class TaskBackup( val task: Task, val alarms: List, diff --git a/app/src/main/java/org/tasks/backup/TasksJsonExporter.kt b/app/src/main/java/org/tasks/backup/TasksJsonExporter.kt index b54f220ec..becf77bbf 100755 --- a/app/src/main/java/org/tasks/backup/TasksJsonExporter.kt +++ b/app/src/main/java/org/tasks/backup/TasksJsonExporter.kt @@ -135,7 +135,9 @@ class TasksJsonExporter @Inject constructor( preferences.getPrefs(Integer::class.java), preferences.getPrefs(java.lang.Long::class.java), preferences.getPrefs(String::class.java), - preferences.getPrefs(java.lang.Boolean::class.java)) + preferences.getPrefs(java.lang.Boolean::class.java), + preferences.getPrefs(java.util.Set::class.java), + ) val out = OutputStreamWriter(os, UTF_8) val gson = if (BuildConfig.DEBUG) GsonBuilder().setPrettyPrinting().create() else Gson() out.write(gson.toJson(data)) diff --git a/app/src/main/java/org/tasks/backup/TasksJsonImporter.kt b/app/src/main/java/org/tasks/backup/TasksJsonImporter.kt index 7db3916c4..60cd01c59 100644 --- a/app/src/main/java/org/tasks/backup/TasksJsonImporter.kt +++ b/app/src/main/java/org/tasks/backup/TasksJsonImporter.kt @@ -207,6 +207,10 @@ class TasksJsonImporter @Inject constructor( .boolPrefs ?.filterNot { (key, _) -> ignoreKeys.contains(key) } ?.forEach { (key, value) -> preferences.setBoolean(key, value as Boolean) } + backupContainer + .setPrefs + ?.filterNot { (key, _) -> ignoreKeys.contains(key) } + ?.forEach { (key, value) -> preferences.setStringSet(key, value as HashSet)} if (version < Upgrader.V8_2) { val themeIndex = preferences.getInt(R.string.p_theme_color, 7) preferences.setInt( diff --git a/app/src/main/java/org/tasks/preferences/Preferences.kt b/app/src/main/java/org/tasks/preferences/Preferences.kt index ec1c71c4b..f13e6391b 100644 --- a/app/src/main/java/org/tasks/preferences/Preferences.kt +++ b/app/src/main/java/org/tasks/preferences/Preferences.kt @@ -243,10 +243,10 @@ class Preferences @JvmOverloads constructor( editor.apply() } - fun setStringSet(key: Int, newValue: HashSet) = + fun setStringSet(key: Int, newValue: Set) = setStringSet(context.getString(key), newValue) - private fun setStringSet(key: String, newValue: HashSet) { + fun setStringSet(key: String, newValue: Set) { val editor = prefs.edit() editor.putStringSet(key, newValue) editor.apply()