Add migration for persisted IMAP compression preference

This commit is contained in:
cketti 2022-04-07 05:36:14 +02:00
parent 7be4ea62fe
commit 814583a89e
3 changed files with 38 additions and 1 deletions

View file

@ -21,7 +21,7 @@ import timber.log.Timber;
public class K9StoragePersister implements StoragePersister {
private static final int DB_VERSION = 17;
private static final int DB_VERSION = 18;
private static final String DB_NAME = "preferences_storage";
private final Context context;

View file

@ -0,0 +1,36 @@
package com.fsck.k9.preferences.migrations
import android.database.sqlite.SQLiteDatabase
/**
* Rewrite the per-network type IMAP compression settings to a single setting.
*/
class StorageMigrationTo18(
private val db: SQLiteDatabase,
private val migrationsHelper: StorageMigrationsHelper
) {
fun rewriteImapCompressionSettings() {
val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids")
if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) {
return
}
val accountUuids = accountUuidsListValue.split(",")
for (accountUuid in accountUuids) {
rewriteImapCompressionSetting(accountUuid)
}
}
private fun rewriteImapCompressionSetting(accountUuid: String) {
val useCompressionWifi = migrationsHelper.readValue(db, "$accountUuid.useCompression.WIFI").toBoolean()
val useCompressionMobile = migrationsHelper.readValue(db, "$accountUuid.useCompression.MOBILE").toBoolean()
val useCompressionOther = migrationsHelper.readValue(db, "$accountUuid.useCompression.OTHER").toBoolean()
val useCompression = useCompressionWifi && useCompressionMobile && useCompressionOther
migrationsHelper.writeValue(db, "$accountUuid.useCompression", useCompression.toString())
migrationsHelper.writeValue(db, "$accountUuid.useCompression.WIFI", null)
migrationsHelper.writeValue(db, "$accountUuid.useCompression.MOBILE", null)
migrationsHelper.writeValue(db, "$accountUuid.useCompression.OTHER", null)
}
}

View file

@ -23,5 +23,6 @@ internal object StorageMigrations {
if (oldVersion < 15) StorageMigrationTo15(db, migrationsHelper).rewriteIdleRefreshInterval()
if (oldVersion < 16) StorageMigrationTo16(db, migrationsHelper).changeDefaultRegisteredNameColor()
if (oldVersion < 17) StorageMigrationTo17(db, migrationsHelper).rewriteNotificationLightSettings()
if (oldVersion < 18) StorageMigrationTo18(db, migrationsHelper).rewriteImapCompressionSettings()
}
}