Fix preference backup

pull/1569/head
Alex Baker 3 years ago
parent 03f12b2032
commit 2166ca17da

@ -14,10 +14,10 @@ class BackupContainer(
val caldavAccounts: List<CaldavAccount>?,
val caldavCalendars: List<CaldavCalendar>?,
val taskListMetadata: List<TaskListMetadata>?,
val intPrefs: Map<String, Int>?,
val longPrefs: Map<String, Long>?,
val intPrefs: Map<String, Integer>?,
val longPrefs: Map<String, java.lang.Long>?,
val stringPrefs: Map<String, String>?,
val boolPrefs: Map<String, Boolean>?) {
val boolPrefs: Map<String, java.lang.Boolean>?) {
class TaskBackup(
val task: Task,

@ -132,10 +132,10 @@ class TasksJsonExporter @Inject constructor(
caldavDao.getAccounts(),
caldavDao.getCalendars(),
taskListMetadataDao.getAll(),
preferences.getPrefs(Int::class.java),
preferences.getPrefs(Long::class.java),
preferences.getPrefs(Integer::class.java),
preferences.getPrefs(java.lang.Long::class.java),
preferences.getPrefs(String::class.java),
preferences.getPrefs(Boolean::class.java))
preferences.getPrefs(java.lang.Boolean::class.java))
val out = OutputStreamWriter(os, UTF_8)
val gson = if (BuildConfig.DEBUG) GsonBuilder().setPrettyPrinting().create() else Gson()
out.write(gson.toJson(data))

@ -52,8 +52,7 @@ class TasksJsonImporter @Inject constructor(
suspend fun importTasks(context: Context, backupFile: Uri?, progressDialog: ProgressDialog?): ImportResult {
val handler = Handler(context.mainLooper)
val gson = Gson()
val `is`: InputStream?
`is` = try {
val `is`: InputStream? = try {
context.contentResolver.openInputStream(backupFile!!)
} catch (e: FileNotFoundException) {
throw IllegalStateException(e)
@ -195,11 +194,11 @@ class TasksJsonImporter @Inject constructor(
backupContainer
.intPrefs
?.filterNot { (key, _) -> ignoreKeys.contains(key) }
?.forEach { (key, value) -> preferences.setInt(key, value) }
?.forEach { (key, value) -> preferences.setInt(key, value as Int) }
backupContainer
.longPrefs
?.filterNot { (key, _) -> ignoreKeys.contains(key) }
?.forEach { (key, value) -> preferences.setLong(key, value) }
?.forEach { (key, value) -> preferences.setLong(key, value as Long) }
backupContainer
.stringPrefs
?.filterNot { (key, _) -> ignoreKeys.contains(key) }
@ -207,7 +206,7 @@ class TasksJsonImporter @Inject constructor(
backupContainer
.boolPrefs
?.filterNot { (key, _) -> ignoreKeys.contains(key) }
?.forEach { (key, value) -> preferences.setBoolean(key, value) }
?.forEach { (key, value) -> preferences.setBoolean(key, value as Boolean) }
if (version < Upgrader.V8_2) {
val themeIndex = preferences.getInt(R.string.p_theme_color, 7)
preferences.setInt(

@ -422,14 +422,8 @@ class Preferences @JvmOverloads constructor(
syncFlags.forEach { setBoolean(it, value) }
}
fun <T> getPrefs(c: Class<T>): Map<String, T> {
val result: MutableMap<String, T> = HashMap()
val entries: Iterable<Map.Entry<String, *>> = prefs.all.entries.filter { e: Map.Entry<String?, Any?> -> c.isInstance(e.value) }
for ((key, value) in entries) {
result[key] = value as T
}
return result
}
fun <T> getPrefs(c: Class<T>): Map<String, T> =
prefs.all.filter { (_, value) -> c.isInstance(value) } as Map<String, T>
val isFlipperEnabled: Boolean
get() = BuildConfig.DEBUG && getBoolean(R.string.p_flipper, false)

Loading…
Cancel
Save