From 3678e566963b41f4879dc6d00cd504e58d1d8630 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 5 Oct 2023 16:35:10 +0200 Subject: [PATCH] Extract `SettingsUpgrader` implementations to separate files (cherry picked from commit 67839f3f14888897efc658a4db7030baeca9566f) --- .../AccountSettingsDescriptions.java | 135 +++-------------- .../GeneralSettingsDescriptions.java | 142 ++---------------- .../com/fsck/k9/preferences/Settings.java | 2 +- .../upgrader/AccountSettingsUpgraderTo53.java | 34 +++++ .../upgrader/AccountSettingsUpgraderTo54.java | 26 ++++ .../upgrader/AccountSettingsUpgraderTo74.java | 23 +++ .../upgrader/AccountSettingsUpgraderTo80.java | 34 +++++ .../upgrader/AccountSettingsUpgraderTo81.java | 27 ++++ .../upgrader/GeneralSettingsUpgraderTo24.java | 29 ++++ .../upgrader/GeneralSettingsUpgraderTo31.java | 48 ++++++ .../upgrader/GeneralSettingsUpgraderTo58.java | 25 +++ .../upgrader/GeneralSettingsUpgraderTo69.java | 25 +++ .../upgrader/GeneralSettingsUpgraderTo79.java | 29 ++++ .../migrations/StorageMigrationTo11.kt | 4 +- 14 files changed, 330 insertions(+), 253 deletions(-) create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo53.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo54.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo74.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo80.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo81.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo24.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo31.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo58.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo69.java create mode 100644 app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo79.java diff --git a/app/core/src/main/java/com/fsck/k9/preferences/AccountSettingsDescriptions.java b/app/core/src/main/java/com/fsck/k9/preferences/AccountSettingsDescriptions.java index 58675c098a..8998067126 100644 --- a/app/core/src/main/java/com/fsck/k9/preferences/AccountSettingsDescriptions.java +++ b/app/core/src/main/java/com/fsck/k9/preferences/AccountSettingsDescriptions.java @@ -26,7 +26,6 @@ import com.fsck.k9.K9; import com.fsck.k9.NotificationLight; import com.fsck.k9.core.R; import com.fsck.k9.mailstore.StorageManager; -import com.fsck.k9.notification.NotificationLightDecoder; import com.fsck.k9.preferences.Settings.BooleanSetting; import com.fsck.k9.preferences.Settings.ColorSetting; import com.fsck.k9.preferences.Settings.EnumSetting; @@ -37,7 +36,13 @@ import com.fsck.k9.preferences.Settings.SettingsDescription; import com.fsck.k9.preferences.Settings.SettingsUpgrader; import com.fsck.k9.preferences.Settings.StringSetting; import com.fsck.k9.preferences.Settings.V; -import kotlin.collections.SetsKt; +import com.fsck.k9.preferences.upgrader.AccountSettingsUpgraderTo53; +import com.fsck.k9.preferences.upgrader.AccountSettingsUpgraderTo54; +import com.fsck.k9.preferences.upgrader.AccountSettingsUpgraderTo74; +import com.fsck.k9.preferences.upgrader.AccountSettingsUpgraderTo80; +import com.fsck.k9.preferences.upgrader.AccountSettingsUpgraderTo81; + +import static com.fsck.k9.preferences.upgrader.AccountSettingsUpgraderTo53.FOLDER_NONE; public class AccountSettingsDescriptions { @@ -59,7 +64,7 @@ public class AccountSettingsDescriptions { new V(13, new BooleanSetting(false)) )); s.put("archiveFolderName", Settings.versions( - new V(1, new StringSetting(SettingsUpgraderV53.FOLDER_NONE)), + new V(1, new StringSetting(FOLDER_NONE)), new V(53, new StringSetting(null)) )); s.put("autoExpandFolderName", Settings.versions( @@ -84,7 +89,7 @@ public class AccountSettingsDescriptions { R.array.display_count_values)) )); s.put("draftsFolderName", Settings.versions( - new V(1, new StringSetting(SettingsUpgraderV53.FOLDER_NONE)), + new V(1, new StringSetting(FOLDER_NONE)), new V(53, new StringSetting(null)) )); s.put("expungePolicy", Settings.versions( @@ -174,7 +179,7 @@ public class AccountSettingsDescriptions { new V(1, new EnumSetting<>(Searchable.class, Searchable.ALL)) )); s.put("sentFolderName", Settings.versions( - new V(1, new StringSetting(SettingsUpgraderV53.FOLDER_NONE)), + new V(1, new StringSetting(FOLDER_NONE)), new V(53, new StringSetting(null)) )); s.put("sortTypeEnum", Settings.versions( @@ -190,7 +195,7 @@ public class AccountSettingsDescriptions { new V(1, new BooleanSetting(false)) )); s.put("spamFolderName", Settings.versions( - new V(1, new StringSetting(SettingsUpgraderV53.FOLDER_NONE)), + new V(1, new StringSetting(FOLDER_NONE)), new V(53, new StringSetting(null)) )); s.put("stripSignature", Settings.versions( @@ -203,7 +208,7 @@ public class AccountSettingsDescriptions { new V(1, new BooleanSetting(true)) )); s.put("trashFolderName", Settings.versions( - new V(1, new StringSetting(SettingsUpgraderV53.FOLDER_NONE)), + new V(1, new StringSetting(FOLDER_NONE)), new V(53, new StringSetting(null)) )); s.put("useCompression.MOBILE", Settings.versions( @@ -285,11 +290,11 @@ public class AccountSettingsDescriptions { SETTINGS = Collections.unmodifiableMap(s); Map u = new HashMap<>(); - u.put(53, new SettingsUpgraderV53()); - u.put(54, new SettingsUpgraderV54()); - u.put(74, new SettingsUpgraderV74()); - u.put(80, new SettingsUpgraderV80()); - u.put(81, new SettingsUpgraderV81()); + u.put(53, new AccountSettingsUpgraderTo53()); + u.put(54, new AccountSettingsUpgraderTo54()); + u.put(74, new AccountSettingsUpgraderTo74()); + u.put(80, new AccountSettingsUpgraderTo80()); + u.put(81, new AccountSettingsUpgraderTo81()); UPGRADERS = Collections.unmodifiableMap(u); } @@ -468,110 +473,4 @@ public class AccountSettingsDescriptions { } } - /** - * Upgrades settings from version 52 to 53 - * - * Replace folder entries of "-NONE-" with {@code null}. - */ - private static class SettingsUpgraderV53 implements SettingsUpgrader { - private static final String FOLDER_NONE = "-NONE-"; - - @Override - public Set upgrade(Map settings) { - upgradeFolderEntry(settings, "archiveFolderName"); - upgradeFolderEntry(settings, "autoExpandFolderName"); - upgradeFolderEntry(settings, "draftsFolderName"); - upgradeFolderEntry(settings, "sentFolderName"); - upgradeFolderEntry(settings, "spamFolderName"); - upgradeFolderEntry(settings, "trashFolderName"); - - return null; - } - - private void upgradeFolderEntry(Map settings, String key) { - String archiveFolderName = (String) settings.get(key); - if (FOLDER_NONE.equals(archiveFolderName)) { - settings.put(key, null); - } - } - } - - /** - * Upgrades settings from version 53 to 54 - * - * Inserts folder selection entries with a value of "MANUAL" - */ - private static class SettingsUpgraderV54 implements SettingsUpgrader { - private static final String FOLDER_SELECTION_MANUAL = "MANUAL"; - - @Override - public Set upgrade(Map settings) { - settings.put("archiveFolderSelection", FOLDER_SELECTION_MANUAL); - settings.put("draftsFolderSelection", FOLDER_SELECTION_MANUAL); - settings.put("sentFolderSelection", FOLDER_SELECTION_MANUAL); - settings.put("spamFolderSelection", FOLDER_SELECTION_MANUAL); - settings.put("trashFolderSelection", FOLDER_SELECTION_MANUAL); - - return null; - } - } - - /** - * Upgrades settings from version 73 to 74 - * - * Rewrites 'idleRefreshMinutes' from '1' to '2' if necessary - */ - private static class SettingsUpgraderV74 implements SettingsUpgrader { - @Override - public Set upgrade(Map settings) { - Integer idleRefreshMinutes = (Integer) settings.get("idleRefreshMinutes"); - if (idleRefreshMinutes == 1) { - settings.put("idleRefreshMinutes", 2); - } - - return null; - } - } - - /** - * Upgrades settings from version 79 to 80 - * - * Rewrites 'led' and 'lecColor' to 'notificationLight'. - */ - private static class SettingsUpgraderV80 implements SettingsUpgrader { - private final NotificationLightDecoder notificationLightDecoder = DI.get(NotificationLightDecoder.class); - - @Override - public Set upgrade(Map settings) { - Boolean isLedEnabled = (Boolean) settings.get("led"); - Integer ledColor = (Integer) settings.get("ledColor"); - Integer chipColor = (Integer) settings.get("chipColor"); - - if (isLedEnabled != null && ledColor != null) { - int accountColor = chipColor != null ? chipColor : 0; - NotificationLight light = notificationLightDecoder.decode(isLedEnabled, ledColor, accountColor); - settings.put("notificationLight", light.name()); - } - - return SetsKt.setOf("led", "ledColor"); - } - } - - /** - * Rewrite the per-network type IMAP compression settings to a single setting. - */ - private static class SettingsUpgraderV81 implements SettingsUpgrader { - @Override - public Set upgrade(Map settings) { - Boolean useCompressionWifi = (Boolean) settings.get("useCompression.WIFI"); - Boolean useCompressionMobile = (Boolean) settings.get("useCompression.MOBILE"); - Boolean useCompressionOther = (Boolean) settings.get("useCompression.OTHER"); - - boolean useCompression = useCompressionWifi != null && useCompressionMobile != null && - useCompressionOther != null && useCompressionWifi && useCompressionMobile && useCompressionOther; - settings.put("useCompression", useCompression); - - return SetsKt.setOf("useCompression.WIFI", "useCompression.MOBILE", "useCompression.OTHER"); - } - } } diff --git a/app/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java b/app/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java index 1f2fb45007..53e5ea3a81 100644 --- a/app/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java +++ b/app/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java @@ -3,7 +3,6 @@ package com.fsck.k9.preferences; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -33,6 +32,11 @@ import com.fsck.k9.preferences.Settings.SettingsDescription; import com.fsck.k9.preferences.Settings.SettingsUpgrader; import com.fsck.k9.preferences.Settings.V; import com.fsck.k9.preferences.Settings.WebFontSizeSetting; +import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo24; +import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo31; +import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo58; +import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo69; +import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo79; import static com.fsck.k9.K9.LockScreenNotificationVisibility; @@ -289,11 +293,11 @@ public class GeneralSettingsDescriptions { SETTINGS = Collections.unmodifiableMap(s); Map u = new HashMap<>(); - u.put(24, new SettingsUpgraderV24()); - u.put(31, new SettingsUpgraderV31()); - u.put(58, new SettingsUpgraderV58()); - u.put(69, new SettingsUpgraderV69()); - u.put(79, new SettingsUpgraderV79()); + u.put(24, new GeneralSettingsUpgraderTo24()); + u.put(31, new GeneralSettingsUpgraderTo31()); + u.put(58, new GeneralSettingsUpgraderTo58()); + u.put(69, new GeneralSettingsUpgraderTo69()); + u.put(79, new GeneralSettingsUpgraderTo79()); UPGRADERS = Collections.unmodifiableMap(u); } @@ -321,132 +325,6 @@ public class GeneralSettingsDescriptions { return result; } - /** - * Upgrades the settings from version 23 to 24. - * - *

- * Set messageViewTheme to {@link SubTheme#USE_GLOBAL} if messageViewTheme has - * the same value as theme. - *

- */ - private static class SettingsUpgraderV24 implements SettingsUpgrader { - - @Override - public Set upgrade(Map settings) { - SubTheme messageViewTheme = (SubTheme) settings.get("messageViewTheme"); - AppTheme theme = (AppTheme) settings.get("theme"); - if ((theme == AppTheme.LIGHT && messageViewTheme == SubTheme.LIGHT) || - (theme == AppTheme.DARK && messageViewTheme == SubTheme.DARK)) { - settings.put("messageViewTheme", SubTheme.USE_GLOBAL); - } - - return null; - } - } - - /** - * Upgrades the settings from version 30 to 31. - * - *

- * Convert value from fontSizeMessageViewContent to - * fontSizeMessageViewContentPercent. - *

- */ - public static class SettingsUpgraderV31 implements SettingsUpgrader { - - @Override - public Set upgrade(Map settings) { - int oldSize = (Integer) settings.get("fontSizeMessageViewContent"); - - int newSize = convertFromOldSize(oldSize); - - settings.put("fontSizeMessageViewContentPercent", newSize); - - return new HashSet<>(Collections.singletonList("fontSizeMessageViewContent")); - } - - public static int convertFromOldSize(int oldSize) { - switch (oldSize) { - case 1: { - return 40; - } - case 2: { - return 75; - } - case 4: { - return 175; - } - case 5: { - return 250; - } - case 3: - default: { - return 100; - } - } - } - } - - /** - * Upgrades the settings from version 57 to 58. - * - *

- * Set theme to {@link AppTheme#FOLLOW_SYSTEM} if theme has the value {@link AppTheme#LIGHT}. - *

- */ - private static class SettingsUpgraderV58 implements SettingsUpgrader { - - @Override - public Set upgrade(Map settings) { - AppTheme theme = (AppTheme) settings.get("theme"); - if (theme == AppTheme.LIGHT) { - settings.put("theme", AppTheme.FOLLOW_SYSTEM); - } - - return null; - } - } - - /** - * Upgrades the settings from version 68 to 69. - * - *

- * Renames {@code hideSpecialAccounts} to {@code showUnifiedInbox}. - *

- */ - private static class SettingsUpgraderV69 implements SettingsUpgrader { - - @Override - public Set upgrade(Map settings) { - Boolean hideSpecialAccounts = (Boolean) settings.get("hideSpecialAccounts"); - boolean showUnifiedInbox = hideSpecialAccounts == null || !hideSpecialAccounts; - settings.put("showUnifiedInbox", showUnifiedInbox); - - return new HashSet<>(Collections.singleton("hideSpecialAccounts")); - } - } - - /** - * Upgrades the settings from version 78 to 79. - * - *

- * Change default value of {@code registeredNameColor} to have enough contrast in both the light and dark theme. - *

- */ - private static class SettingsUpgraderV79 implements SettingsUpgrader { - - @Override - public Set upgrade(Map settings) { - final Integer registeredNameColorValue = (Integer) settings.get("registeredNameColor"); - - if (registeredNameColorValue != null && registeredNameColorValue == 0xFF00008F) { - settings.put("registeredNameColor", 0xFF1093F5); - } - - return null; - } - } - private static class LanguageSetting extends PseudoEnumSetting { private final Context context = DI.get(Context.class); private final Map mapping; diff --git a/app/core/src/main/java/com/fsck/k9/preferences/Settings.java b/app/core/src/main/java/com/fsck/k9/preferences/Settings.java index dcff73e46e..3e617a5ec4 100644 --- a/app/core/src/main/java/com/fsck/k9/preferences/Settings.java +++ b/app/core/src/main/java/com/fsck/k9/preferences/Settings.java @@ -367,7 +367,7 @@ public class Settings { * * @see Settings#upgrade(int, Map, Map, Map) */ - interface SettingsUpgrader { + public interface SettingsUpgrader { /** * Upgrade the provided settings. * diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo53.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo53.java new file mode 100644 index 0000000000..b5eb199b65 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo53.java @@ -0,0 +1,34 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Replace folder entries of "-NONE-" with {@code null}. + */ +public class AccountSettingsUpgraderTo53 implements SettingsUpgrader { + public static final String FOLDER_NONE = "-NONE-"; + + @Override + public Set upgrade(Map settings) { + upgradeFolderEntry(settings, "archiveFolderName"); + upgradeFolderEntry(settings, "autoExpandFolderName"); + upgradeFolderEntry(settings, "draftsFolderName"); + upgradeFolderEntry(settings, "sentFolderName"); + upgradeFolderEntry(settings, "spamFolderName"); + upgradeFolderEntry(settings, "trashFolderName"); + + return null; + } + + private void upgradeFolderEntry(Map settings, String key) { + String archiveFolderName = (String) settings.get(key); + if (FOLDER_NONE.equals(archiveFolderName)) { + settings.put(key, null); + } + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo54.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo54.java new file mode 100644 index 0000000000..0d61fbb7ca --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo54.java @@ -0,0 +1,26 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Inserts folder selection entries with a value of "MANUAL" + */ +public class AccountSettingsUpgraderTo54 implements SettingsUpgrader { + private static final String FOLDER_SELECTION_MANUAL = "MANUAL"; + + @Override + public Set upgrade(Map settings) { + settings.put("archiveFolderSelection", FOLDER_SELECTION_MANUAL); + settings.put("draftsFolderSelection", FOLDER_SELECTION_MANUAL); + settings.put("sentFolderSelection", FOLDER_SELECTION_MANUAL); + settings.put("spamFolderSelection", FOLDER_SELECTION_MANUAL); + settings.put("trashFolderSelection", FOLDER_SELECTION_MANUAL); + + return null; + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo74.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo74.java new file mode 100644 index 0000000000..21adfdc6cc --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo74.java @@ -0,0 +1,23 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Rewrites 'idleRefreshMinutes' from '1' to '2' if necessary + */ +public class AccountSettingsUpgraderTo74 implements SettingsUpgrader { + @Override + public Set upgrade(Map settings) { + Integer idleRefreshMinutes = (Integer) settings.get("idleRefreshMinutes"); + if (idleRefreshMinutes == 1) { + settings.put("idleRefreshMinutes", 2); + } + + return null; + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo80.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo80.java new file mode 100644 index 0000000000..49643a3740 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo80.java @@ -0,0 +1,34 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.DI; +import com.fsck.k9.NotificationLight; +import com.fsck.k9.notification.NotificationLightDecoder; +import com.fsck.k9.preferences.Settings.SettingsUpgrader; +import kotlin.collections.SetsKt; + + +/** + * Rewrites 'led' and 'lecColor' to 'notificationLight'. + */ +public class AccountSettingsUpgraderTo80 implements SettingsUpgrader { + private final NotificationLightDecoder notificationLightDecoder = DI.get(NotificationLightDecoder.class); + + @Override + public Set upgrade(Map settings) { + Boolean isLedEnabled = (Boolean) settings.get("led"); + Integer ledColor = (Integer) settings.get("ledColor"); + Integer chipColor = (Integer) settings.get("chipColor"); + + if (isLedEnabled != null && ledColor != null) { + int accountColor = chipColor != null ? chipColor : 0; + NotificationLight light = notificationLightDecoder.decode(isLedEnabled, ledColor, accountColor); + settings.put("notificationLight", light.name()); + } + + return SetsKt.setOf("led", "ledColor"); + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo81.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo81.java new file mode 100644 index 0000000000..5cff958537 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/AccountSettingsUpgraderTo81.java @@ -0,0 +1,27 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; +import kotlin.collections.SetsKt; + + +/** + * Rewrite the per-network type IMAP compression settings to a single setting. + */ +public class AccountSettingsUpgraderTo81 implements SettingsUpgrader { + @Override + public Set upgrade(Map settings) { + Boolean useCompressionWifi = (Boolean) settings.get("useCompression.WIFI"); + Boolean useCompressionMobile = (Boolean) settings.get("useCompression.MOBILE"); + Boolean useCompressionOther = (Boolean) settings.get("useCompression.OTHER"); + + boolean useCompression = useCompressionWifi != null && useCompressionMobile != null && + useCompressionOther != null && useCompressionWifi && useCompressionMobile && useCompressionOther; + settings.put("useCompression", useCompression); + + return SetsKt.setOf("useCompression.WIFI", "useCompression.MOBILE", "useCompression.OTHER"); + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo24.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo24.java new file mode 100644 index 0000000000..2347eda2b3 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo24.java @@ -0,0 +1,29 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.AppTheme; +import com.fsck.k9.preferences.Settings.SettingsUpgrader; +import com.fsck.k9.preferences.SubTheme; + + +/** + * Set messageViewTheme to {@link SubTheme#USE_GLOBAL} if messageViewTheme has the same value as + * theme. + */ +public class GeneralSettingsUpgraderTo24 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + SubTheme messageViewTheme = (SubTheme) settings.get("messageViewTheme"); + AppTheme theme = (AppTheme) settings.get("theme"); + if ((theme == AppTheme.LIGHT && messageViewTheme == SubTheme.LIGHT) || + (theme == AppTheme.DARK && messageViewTheme == SubTheme.DARK)) { + settings.put("messageViewTheme", SubTheme.USE_GLOBAL); + } + + return null; + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo31.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo31.java new file mode 100644 index 0000000000..41bc8867a9 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo31.java @@ -0,0 +1,48 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Convert value from fontSizeMessageViewContent to fontSizeMessageViewContentPercent. + */ +public class GeneralSettingsUpgraderTo31 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + int oldSize = (Integer) settings.get("fontSizeMessageViewContent"); + + int newSize = convertFromOldSize(oldSize); + + settings.put("fontSizeMessageViewContentPercent", newSize); + + return new HashSet<>(Collections.singletonList("fontSizeMessageViewContent")); + } + + public static int convertFromOldSize(int oldSize) { + switch (oldSize) { + case 1: { + return 40; + } + case 2: { + return 75; + } + case 4: { + return 175; + } + case 5: { + return 250; + } + case 3: + default: { + return 100; + } + } + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo58.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo58.java new file mode 100644 index 0000000000..e7f06aff1f --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo58.java @@ -0,0 +1,25 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.AppTheme; +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Set theme to {@link AppTheme#FOLLOW_SYSTEM} if theme has the value {@link AppTheme#LIGHT}. + */ +public class GeneralSettingsUpgraderTo58 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + AppTheme theme = (AppTheme) settings.get("theme"); + if (theme == AppTheme.LIGHT) { + settings.put("theme", AppTheme.FOLLOW_SYSTEM); + } + + return null; + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo69.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo69.java new file mode 100644 index 0000000000..dd9812d613 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo69.java @@ -0,0 +1,25 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Renames {@code hideSpecialAccounts} to {@code showUnifiedInbox}. + */ +public class GeneralSettingsUpgraderTo69 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + Boolean hideSpecialAccounts = (Boolean) settings.get("hideSpecialAccounts"); + boolean showUnifiedInbox = hideSpecialAccounts == null || !hideSpecialAccounts; + settings.put("showUnifiedInbox", showUnifiedInbox); + + return new HashSet<>(Collections.singleton("hideSpecialAccounts")); + } +} diff --git a/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo79.java b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo79.java new file mode 100644 index 0000000000..5338f6feb4 --- /dev/null +++ b/app/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo79.java @@ -0,0 +1,29 @@ +package com.fsck.k9.preferences.upgrader; + + +import java.util.Map; +import java.util.Set; + +import com.fsck.k9.preferences.Settings.SettingsUpgrader; + + +/** + * Upgrades the settings from version 78 to 79. + * + *

+ * Change default value of {@code registeredNameColor} to have enough contrast in both the light and dark theme. + *

+ */ +public class GeneralSettingsUpgraderTo79 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + final Integer registeredNameColorValue = (Integer) settings.get("registeredNameColor"); + + if (registeredNameColorValue != null && registeredNameColorValue == 0xFF00008F) { + settings.put("registeredNameColor", 0xFF1093F5); + } + + return null; + } +} diff --git a/app/storage/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo11.kt b/app/storage/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo11.kt index 6492f3ba96..3b1d14b7d4 100644 --- a/app/storage/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo11.kt +++ b/app/storage/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo11.kt @@ -1,7 +1,7 @@ package com.fsck.k9.preferences.migrations import android.database.sqlite.SQLiteDatabase -import com.fsck.k9.preferences.GeneralSettingsDescriptions +import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo31 /** * Convert old value for message view content font size to new format. @@ -19,7 +19,7 @@ class StorageMigrationTo11( if (newFontSizeValue != null) return val oldFontSizeValue = migrationsHelper.readValue(db, "fontSizeMessageViewContent")?.toIntOrNull() ?: 3 - val fontSizeValue = GeneralSettingsDescriptions.SettingsUpgraderV31.convertFromOldSize(oldFontSizeValue) + val fontSizeValue = GeneralSettingsUpgraderTo31.convertFromOldSize(oldFontSizeValue) migrationsHelper.writeValue(db, "fontSizeMessageViewContentPercent", fontSizeValue.toString()) migrationsHelper.writeValue(db, "fontSizeMessageViewContent", null) } -- GitLab