Back up string set preferences

pull/1684/head
Alex Baker 3 years ago
parent c52ab2a47c
commit a100fca5af

@ -17,8 +17,9 @@ class BackupContainer(
val intPrefs: Map<String, Integer>?,
val longPrefs: Map<String, java.lang.Long>?,
val stringPrefs: Map<String, String>?,
val boolPrefs: Map<String, java.lang.Boolean>?) {
val boolPrefs: Map<String, java.lang.Boolean>?,
val setPrefs: Map<String, java.util.Set<*>>?,
) {
class TaskBackup(
val task: Task,
val alarms: List<Alarm>,

@ -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))

@ -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<String>)}
if (version < Upgrader.V8_2) {
val themeIndex = preferences.getInt(R.string.p_theme_color, 7)
preferences.setInt(

@ -243,10 +243,10 @@ class Preferences @JvmOverloads constructor(
editor.apply()
}
fun setStringSet(key: Int, newValue: HashSet<String>) =
fun setStringSet(key: Int, newValue: Set<String>) =
setStringSet(context.getString(key), newValue)
private fun setStringSet(key: String, newValue: HashSet<String>) {
fun setStringSet(key: String, newValue: Set<String>) {
val editor = prefs.edit()
editor.putStringSet(key, newValue)
editor.apply()

Loading…
Cancel
Save