diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 779949dbc..a0e2e2cb3 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -839,6 +839,13 @@ public class K9 extends Application { language = nlanguage; } + /** + * Possible values for the different theme settings. + * + *

Important: + * Do not change the order of the items! The ordinal value (position) is used when saving the + * settings.

+ */ public enum Theme { LIGHT, DARK, diff --git a/src/com/fsck/k9/preferences/GlobalSettings.java b/src/com/fsck/k9/preferences/GlobalSettings.java index 5afc8294a..fea82c57e 100644 --- a/src/com/fsck/k9/preferences/GlobalSettings.java +++ b/src/com/fsck/k9/preferences/GlobalSettings.java @@ -19,6 +19,7 @@ import com.fsck.k9.FontSizes; import com.fsck.k9.K9; import com.fsck.k9.K9.NotificationHideSubject; import com.fsck.k9.K9.SplitViewMode; +import com.fsck.k9.K9.Theme; import com.fsck.k9.R; import com.fsck.k9.Account.SortType; import com.fsck.k9.helper.DateFormatter; @@ -185,10 +186,11 @@ public class GlobalSettings { new V(1, new BooleanSetting(false)) )); s.put("theme", Settings.versions( - new V(1, new ThemeSetting(K9.Theme.LIGHT.ordinal())) + new V(1, new ThemeSetting(K9.Theme.LIGHT)) )); s.put("messageViewTheme", Settings.versions( - new V(16, new ThemeSetting(K9.Theme.LIGHT.ordinal())) + new V(16, new ThemeSetting(K9.Theme.LIGHT)), + new V(24, new SubThemeSetting(K9.Theme.USE_GLOBAL)) )); s.put("useGalleryBugWorkaround", Settings.versions( new V(1, new GalleryBugWorkaroundSetting()) @@ -233,11 +235,18 @@ public class GlobalSettings { s.put("splitViewMode", Settings.versions( new V(23, new EnumSetting(SplitViewMode.class, SplitViewMode.NEVER)) )); + s.put("messageComposeTheme", Settings.versions( + new V(24, new SubThemeSetting(K9.Theme.USE_GLOBAL)) + )); + s.put("fixedMessageViewTheme", Settings.versions( + new V(24, new BooleanSetting(true)) + )); SETTINGS = Collections.unmodifiableMap(s); Map u = new HashMap(); u.put(12, new SettingsUpgraderV12()); + u.put(24, new SettingsUpgraderV24()); UPGRADERS = Collections.unmodifiableMap(u); } @@ -286,6 +295,28 @@ public class GlobalSettings { } } + /** + * Upgrades the settings from version 23 to 24. + * + *

+ * Set messageViewTheme to {@link K9.Theme#USE_GLOBAL} if messageViewTheme has + * the same value as theme. + *

+ */ + public static class SettingsUpgraderV24 implements SettingsUpgrader { + + @Override + public Set upgrade(Map settings) { + K9.Theme messageViewTheme = (K9.Theme) settings.get("messageViewTheme"); + K9.Theme theme = (K9.Theme) settings.get("theme"); + if (theme != null && messageViewTheme != null && theme == messageViewTheme) { + settings.put("messageViewTheme", K9.Theme.USE_GLOBAL); + } + + return null; + } + } + /** * The gallery bug work-around setting. * @@ -355,7 +386,7 @@ public class GlobalSettings { private static final String THEME_LIGHT = "light"; private static final String THEME_DARK = "dark"; - public ThemeSetting(int defaultValue) { + public ThemeSetting(K9.Theme defaultValue) { super(defaultValue); } @@ -390,7 +421,62 @@ public class GlobalSettings { @Override public String toPrettyString(Object value) { - return (((Integer)value).intValue() == K9.Theme.LIGHT.ordinal()) ? THEME_LIGHT : THEME_DARK; + switch ((K9.Theme) value) { + case DARK: { + return THEME_DARK; + } + default: { + return THEME_LIGHT; + } + } + } + + @Override + public String toString(Object value) { + return Integer.toString(((K9.Theme) value).ordinal()); + } + } + + /** + * The message view theme setting. + */ + public static class SubThemeSetting extends ThemeSetting { + private static final String THEME_USE_GLOBAL = "use_global"; + + public SubThemeSetting(Theme defaultValue) { + super(defaultValue); + } + + @Override + public Object fromString(String value) throws InvalidSettingValueException { + try { + Integer theme = Integer.parseInt(value); + if (theme == K9.Theme.USE_GLOBAL.ordinal()) { + return K9.Theme.USE_GLOBAL; + } + + return super.fromString(value); + } catch (NumberFormatException e) { + throw new InvalidSettingValueException(); + } + } + + @Override + public Object fromPrettyString(String value) throws InvalidSettingValueException { + if (THEME_USE_GLOBAL.equals(value)) { + return K9.Theme.USE_GLOBAL; + } + + return super.fromPrettyString(value); + } + + @Override + public String toPrettyString(Object value) { + if (((K9.Theme) value) == K9.Theme.USE_GLOBAL) { + return THEME_USE_GLOBAL; + } + + return super.toPrettyString(value); } } diff --git a/src/com/fsck/k9/preferences/Settings.java b/src/com/fsck/k9/preferences/Settings.java index 5ed29b360..053d81ddc 100644 --- a/src/com/fsck/k9/preferences/Settings.java +++ b/src/com/fsck/k9/preferences/Settings.java @@ -35,7 +35,7 @@ public class Settings { * * @see SettingsExporter */ - public static final int VERSION = 23; + public static final int VERSION = 24; public static Map validate(int version, Map> settings,