Merge pull request #4663 from k9mail/message_view_content_font_size_migration

Convert old value for message view content font size to new format
This commit is contained in:
cketti 2020-04-14 22:27:02 +02:00 committed by GitHub
commit a05181eb2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 10 deletions

View file

@ -3,7 +3,6 @@ package com.fsck.k9;
import android.util.TypedValue; import android.util.TypedValue;
import android.widget.TextView; import android.widget.TextView;
import com.fsck.k9.preferences.GeneralSettingsDescriptions;
import com.fsck.k9.preferences.Storage; import com.fsck.k9.preferences.Storage;
import com.fsck.k9.preferences.StorageEditor; import com.fsck.k9.preferences.StorageEditor;
@ -28,7 +27,6 @@ public class FontSizes {
private static final String MESSAGE_VIEW_ADDITIONAL_HEADERS = "fontSizeMessageViewAdditionalHeaders"; private static final String MESSAGE_VIEW_ADDITIONAL_HEADERS = "fontSizeMessageViewAdditionalHeaders";
private static final String MESSAGE_VIEW_SUBJECT = "fontSizeMessageViewSubject"; private static final String MESSAGE_VIEW_SUBJECT = "fontSizeMessageViewSubject";
private static final String MESSAGE_VIEW_DATE = "fontSizeMessageViewDate"; private static final String MESSAGE_VIEW_DATE = "fontSizeMessageViewDate";
private static final String MESSAGE_VIEW_CONTENT = "fontSizeMessageViewContent";
private static final String MESSAGE_VIEW_CONTENT_PERCENT = "fontSizeMessageViewContentPercent"; private static final String MESSAGE_VIEW_CONTENT_PERCENT = "fontSizeMessageViewContentPercent";
private static final String MESSAGE_COMPOSE_INPUT = "fontSizeMessageComposeInput"; private static final String MESSAGE_COMPOSE_INPUT = "fontSizeMessageComposeInput";
@ -136,13 +134,7 @@ public class FontSizes {
} }
private void loadMessageViewContentPercent(Storage storage) { private void loadMessageViewContentPercent(Storage storage) {
int fallbackValue = 100; setMessageViewContentAsPercent(storage.getInt(MESSAGE_VIEW_CONTENT_PERCENT, 100));
if (!storage.contains(MESSAGE_VIEW_CONTENT_PERCENT)) {
int oldValue = storage.getInt(MESSAGE_VIEW_CONTENT, 3);
fallbackValue = GeneralSettingsDescriptions.SettingsUpgraderV31.convertFromOldSize(oldValue);
}
setMessageViewContentAsPercent(storage.getInt(MESSAGE_VIEW_CONTENT_PERCENT, fallbackValue));
} }
public int getAccountName() { public int getAccountName() {

View file

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

View file

@ -0,0 +1,26 @@
package com.fsck.k9.preferences.migrations
import android.database.sqlite.SQLiteDatabase
import com.fsck.k9.preferences.GeneralSettingsDescriptions
/**
* Convert old value for message view content font size to new format.
*
* This change in formats has been made a long time ago. But never in a migration. So it's possible there are still
* installations out there that have the old version in the database. And they would work just fine, because this
* conversion was done when loading font size values.
*/
class StorageMigrationTo11(
private val db: SQLiteDatabase,
private val migrationsHelper: StorageMigrationsHelper
) {
fun upgradeMessageViewContentFontSize() {
val newFontSizeValue = migrationsHelper.readValue(db, "fontSizeMessageViewContentPercent")
if (newFontSizeValue != null) return
val oldFontSizeValue = migrationsHelper.readValue(db, "fontSizeMessageViewContent")?.toIntOrNull() ?: 3
val fontSizeValue = GeneralSettingsDescriptions.SettingsUpgraderV31.convertFromOldSize(oldFontSizeValue)
migrationsHelper.writeValue(db, "fontSizeMessageViewContentPercent", fontSizeValue.toString())
migrationsHelper.writeValue(db, "fontSizeMessageViewContent", null)
}
}

View file

@ -16,5 +16,6 @@ internal object StorageMigrations {
if (oldVersion < 8) StorageMigrationTo8(db, migrationsHelper).rewriteTheme() if (oldVersion < 8) StorageMigrationTo8(db, migrationsHelper).rewriteTheme()
if (oldVersion < 9) StorageMigrationTo9(db, migrationsHelper).disablePush() if (oldVersion < 9) StorageMigrationTo9(db, migrationsHelper).disablePush()
if (oldVersion < 10) StorageMigrationTo10(db, migrationsHelper).removeSavedFolderSettings() if (oldVersion < 10) StorageMigrationTo10(db, migrationsHelper).removeSavedFolderSettings()
if (oldVersion < 11) StorageMigrationTo11(db, migrationsHelper).upgradeMessageViewContentFontSize()
} }
} }