Skip to content

Commit 45e9770

Browse files
committed
feat(settings): Animation setting inherits systemwide settings
Convert the "Use gaudy visual effects" boolean checkbox to a tri-state option (On/Off/Use system default) that defaults to following Android's system animation accessibility setting. Similar to ThemeManager, introduce a new AnimationManager and funnel all access to this option through there. I'm on the fence as to whether that isn't too much overkill, IMO it would make sense to merge them both into one "settings manager". Right now there is only one place where the setting is being read, in ViewSwitcher. However, there are many other places where the setting is supposed to be respected but isn't (sidebar, messagetopview thunderbird#10796) so I figured it's better to centralize the resolution outside of ViewSwitcher.
1 parent 89469b3 commit 45e9770

20 files changed

Lines changed: 159 additions & 25 deletions

File tree

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/GeneralSettings.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ enum class LockScreenNotificationVisibility {
8181
APP_NAME,
8282
NOTHING,
8383
}
84+
85+
enum class AnimationPreference {
86+
ON,
87+
OFF,
88+
FOLLOW_SYSTEM,
89+
}

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/display/visualSettings/DisplayVisualSettings.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package net.thunderbird.core.preference.display.visualSettings
22

3+
import net.thunderbird.core.preference.AnimationPreference
34
import net.thunderbird.core.preference.BodyContentType
45
import net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettings
56

67
const val DISPLAY_SETTINGS_DEFAULT_IS_USE_MESSAGE_VIEW_FIXED_WIDTH_FONT = false
78
const val DISPLAY_SETTINGS_DEFAULT_IS_AUTO_FIT_WIDTH = true
8-
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_ANIMATION = true
9+
val DISPLAY_SETTINGS_DEFAULT_ANIMATION_PREFERENCE = AnimationPreference.FOLLOW_SYSTEM
910
val DISPLAY_SETTINGS_DEFAULT_BODY_CONTENT_TYPE = BodyContentType.TEXT_HTML
1011
const val DISPLAY_SETTINGS_DEFAULT_DRAWER_EXPAND_ALL_FOLDER = false
1112
const val DISPLAY_SETTINGS_DEFAULT_MESSAGE_VIEW_ARCHIVE_ACTION_VISIBLE = false
@@ -15,7 +16,7 @@ const val DISPLAY_SETTINGS_DEFAULT_MESSAGE_VIEW_COPY_ACTION_VISIBLE = false
1516
const val DISPLAY_SETTINGS_DEFAULT_MESSAGE_VIEW_SPAM_ACTION_VISIBLE = false
1617

1718
data class DisplayVisualSettings(
18-
val isShowAnimations: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_ANIMATION,
19+
val animationPreference: AnimationPreference = DISPLAY_SETTINGS_DEFAULT_ANIMATION_PREFERENCE,
1920
val isUseMessageViewFixedWidthFont: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_USE_MESSAGE_VIEW_FIXED_WIDTH_FONT,
2021
val isAutoFitWidth: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_AUTO_FIT_WIDTH,
2122
val bodyContentType: BodyContentType = DISPLAY_SETTINGS_DEFAULT_BODY_CONTENT_TYPE,

core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/display/visualSettings/DefaultDisplayVisualSettingsPreferenceManager.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class DefaultDisplayVisualSettingsPreferenceManager(
6565
KEY_AUTO_FIT_WIDTH,
6666
DISPLAY_SETTINGS_DEFAULT_IS_AUTO_FIT_WIDTH,
6767
),
68-
isShowAnimations = storage.getBoolean(
68+
animationPreference = storage.getEnumOrDefault(
6969
KEY_ANIMATION,
70-
DISPLAY_SETTINGS_DEFAULT_IS_SHOW_ANIMATION,
70+
DISPLAY_SETTINGS_DEFAULT_ANIMATION_PREFERENCE,
7171
),
7272
bodyContentType = storage.getEnumOrDefault(
7373
KEY_MESSAGE_VIEW_BODY_CONTENT_TYPE,
@@ -103,7 +103,7 @@ class DefaultDisplayVisualSettingsPreferenceManager(
103103
logger.debug(TAG) { "writeConfig() called with: config = $config" }
104104
scope.launch(ioDispatcher) {
105105
mutex.withLock {
106-
storageEditor.putBoolean(KEY_ANIMATION, config.isShowAnimations)
106+
storageEditor.putEnum(KEY_ANIMATION, config.animationPreference)
107107
storageEditor.putBoolean(
108108
KEY_MESSAGE_VIEW_FIXED_WIDTH_FONT,
109109
config.isUseMessageViewFixedWidthFont,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id(ThunderbirdPlugins.Library.android)
3+
}
4+
5+
android {
6+
namespace = "net.thunderbird.core.ui.animation.manager"
7+
}
8+
9+
dependencies {
10+
implementation(projects.core.preference.api)
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package net.thunderbird.core.ui.animation.manager
2+
3+
import android.animation.ValueAnimator
4+
import net.thunderbird.core.preference.AnimationPreference
5+
import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsPreferenceManager
6+
7+
interface AnimationManager {
8+
fun shouldShowAnimations(): Boolean
9+
}
10+
11+
class DefaultAnimationManager(
12+
private val visualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager,
13+
) : AnimationManager {
14+
override fun shouldShowAnimations(): Boolean {
15+
return when (visualSettingsPreferenceManager.getConfig().animationPreference) {
16+
AnimationPreference.ON -> true
17+
AnimationPreference.OFF -> false
18+
AnimationPreference.FOLLOW_SYSTEM -> ValueAnimator.areAnimatorsEnabled()
19+
}
20+
}
21+
}

legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo69;
3131
import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo79;
3232
import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo89;
33+
import com.fsck.k9.preferences.upgrader.GeneralSettingsUpgraderTo111;
3334
import net.thunderbird.core.android.account.AccountDefaultsProvider;
3435
import net.thunderbird.core.android.account.SortType;
3536
import net.thunderbird.core.common.action.SwipeAction;
37+
import net.thunderbird.core.preference.AnimationPreference;
3638
import net.thunderbird.core.preference.AppTheme;
3739
import net.thunderbird.core.preference.BackgroundOps;
3840
import net.thunderbird.core.preference.GeneralSettingsManager;
@@ -42,6 +44,7 @@
4244
import net.thunderbird.core.preference.SplitViewMode;
4345
import net.thunderbird.core.preference.SubTheme;
4446
import net.thunderbird.core.preference.display.coreSettings.DisplayCoreSettingsKt;
47+
import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsKt;
4548
import net.thunderbird.core.preference.display.visualSettings.message.list.MessageListDateTimeFormat;
4649
import net.thunderbird.core.preference.interaction.PostRemoveNavigation;
4750
import net.thunderbird.core.preference.network.NetworkSettingsKt;
@@ -57,7 +60,6 @@
5760
import static net.thunderbird.core.preference.display.miscSettings.DisplayMiscSettingsKt.DISPLAY_SETTINGS_DEFAULT_SHOW_RECENT_CHANGES;
5861
import static net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsKt.DISPLAY_SETTINGS_DEFAULT_IS_AUTO_FIT_WIDTH;
5962
import static net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettingsKt.MESSAGE_LIST_SETTINGS_DEFAULT_IS_CHANGE_CONTACT_NAME_COLOR;
60-
import static net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsKt.DISPLAY_SETTINGS_DEFAULT_IS_SHOW_ANIMATION;
6163
import static net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettingsKt.MESSAGE_LIST_SETTINGS_DEFAULT_IS_SHOW_CONTACT_NAME;
6264
import static net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettingsKt.MESSAGE_LIST_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE;
6365
import static net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettingsKt.MESSAGE_LIST_SETTINGS_DEFAULT_IS_SHOW_CORRESPONDENT_NAMES;
@@ -85,7 +87,8 @@ class GeneralSettingsDescriptions {
8587
*/
8688

8789
s.put("animations", Settings.versions(
88-
new V(1, new BooleanSetting(DISPLAY_SETTINGS_DEFAULT_IS_SHOW_ANIMATION))
90+
new V(1, new BooleanSetting(true)),
91+
new V(111, new EnumSetting<>(AnimationPreference.class, AnimationPreference.FOLLOW_SYSTEM))
8992
));
9093
s.put("backgroundOperations", Settings.versions(
9194
new V(1, new EnumSetting<>(BackgroundOps.class, BackgroundOps.WHEN_CHECKED_AUTO_SYNC)),
@@ -361,6 +364,7 @@ class GeneralSettingsDescriptions {
361364
u.put(69, new GeneralSettingsUpgraderTo69());
362365
u.put(79, new GeneralSettingsUpgraderTo79());
363366
u.put(89, new GeneralSettingsUpgraderTo89());
367+
u.put(111, new GeneralSettingsUpgraderTo111());
364368

365369
UPGRADERS = Collections.unmodifiableMap(u);
366370
}

legacy/core/src/main/java/com/fsck/k9/preferences/Settings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Settings {
3535
*
3636
* @see SettingsExporter
3737
*/
38-
public static final int VERSION = 110;
38+
public static final int VERSION = 111;
3939

4040
static Map<String, Object> validate(int version, Map<String, TreeMap<Integer, SettingsDescription<?>>> settings,
4141
Map<String, String> importedSettings, boolean useDefaultValues) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fsck.k9.preferences.upgrader;
2+
3+
4+
import java.util.Map;
5+
6+
import com.fsck.k9.preferences.SettingsUpgrader;
7+
import net.thunderbird.core.preference.AnimationPreference;
8+
9+
10+
/**
11+
* Convert <em>animations</em> from boolean to {@link AnimationPreference} enum.
12+
*
13+
* {@code true} maps to {@link AnimationPreference#ON}, {@code false} maps to {@link AnimationPreference#OFF}.
14+
*/
15+
public class GeneralSettingsUpgraderTo111 implements SettingsUpgrader {
16+
17+
@Override
18+
public void upgrade(Map<String, Object> settings) {
19+
Object animations = settings.get("animations");
20+
if (animations instanceof Boolean) {
21+
boolean value = (Boolean) animations;
22+
settings.put("animations", value ? AnimationPreference.ON : AnimationPreference.OFF);
23+
}
24+
}
25+
}

legacy/core/src/main/res/values/arrays_general_settings_values.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@
152152
<item>follow_system</item>
153153
</string-array>
154154

155+
<string-array name="animation_values" translatable="false">
156+
<item>ON</item>
157+
<item>OFF</item>
158+
<item>FOLLOW_SYSTEM</item>
159+
</string-array>
160+
155161
<string-array name="message_theme_values" translatable="false">
156162
<item>light</item>
157163
<item>dark</item>

legacy/storage/src/main/java/com/fsck/k9/preferences/K9StoragePersister.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import net.thunderbird.core.preference.storage.StorageUpdater;
2424

2525
public class K9StoragePersister implements StoragePersister {
26-
private static final int DB_VERSION = 29;
26+
private static final int DB_VERSION = 30;
2727
private static final String DB_NAME = "preferences_storage";
2828

2929
private final Context context;

0 commit comments

Comments
 (0)