-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(settings): Animation setting inherits systemwide settings #10800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
untitaker
wants to merge
3
commits into
thunderbird:main
Choose a base branch
from
untitaker:global-animation-settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| plugins { | ||
| id(ThunderbirdPlugins.Library.android) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "net.thunderbird.core.ui.animation.manager" | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(projects.core.preference.api) | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ion/manager/src/main/kotlin/net/thunderbird/core/ui/animation/manager/AnimationManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package net.thunderbird.core.ui.animation.manager | ||
|
|
||
| import android.animation.ValueAnimator | ||
| import android.os.Build | ||
| import net.thunderbird.core.preference.AnimationPreference | ||
| import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsPreferenceManager | ||
|
|
||
| interface AnimationManager { | ||
| fun shouldShowAnimations(): Boolean | ||
| } | ||
|
|
||
| class DefaultAnimationManager( | ||
| private val visualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager, | ||
| ) : AnimationManager { | ||
| override fun shouldShowAnimations(): Boolean { | ||
| return when (visualSettingsPreferenceManager.getConfig().animationPreference) { | ||
| AnimationPreference.ON -> true | ||
| AnimationPreference.OFF -> false | ||
| AnimationPreference.FOLLOW_SYSTEM -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
| ValueAnimator.areAnimatorsEnabled() | ||
| } else { | ||
| true | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
legacy/core/src/main/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo111.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.fsck.k9.preferences.upgrader; | ||
|
|
||
|
|
||
| import java.util.Map; | ||
|
|
||
| import com.fsck.k9.preferences.SettingsUpgrader; | ||
| import net.thunderbird.core.preference.AnimationPreference; | ||
|
|
||
|
|
||
| /** | ||
| * Convert <em>animations</em> from boolean to {@link AnimationPreference} enum. | ||
| * | ||
| * {@code true} maps to {@link AnimationPreference#ON}, {@code false} maps to {@link AnimationPreference#OFF}. | ||
| */ | ||
| public class GeneralSettingsUpgraderTo111 implements SettingsUpgrader { | ||
|
|
||
| @Override | ||
| public void upgrade(Map<String, Object> settings) { | ||
| Object animations = settings.get("animations"); | ||
| if (animations instanceof Boolean) { | ||
| boolean value = (Boolean) animations; | ||
| settings.put("animations", value ? AnimationPreference.ON : AnimationPreference.OFF); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...y/core/src/test/java/com/fsck/k9/preferences/upgrader/GeneralSettingsUpgraderTo111Test.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.fsck.k9.preferences.upgrader | ||
|
|
||
| import assertk.assertThat | ||
| import assertk.assertions.doesNotContainKey | ||
| import assertk.assertions.isEqualTo | ||
| import kotlin.test.Test | ||
| import net.thunderbird.core.preference.AnimationPreference | ||
|
|
||
| class GeneralSettingsUpgraderTo111Test { | ||
|
|
||
| private val upgrader = GeneralSettingsUpgraderTo111() | ||
|
|
||
| @Test | ||
| fun `should convert animations=true to ON`() { | ||
| val settings = mutableMapOf<String, Any?>(ANIMATIONS_KEY to true) | ||
|
|
||
| upgrader.upgrade(settings) | ||
|
|
||
| assertThat(settings[ANIMATIONS_KEY]).isEqualTo(AnimationPreference.ON) | ||
| } | ||
|
|
||
| @Test | ||
| fun `should convert animations=false to OFF`() { | ||
| val settings = mutableMapOf<String, Any?>(ANIMATIONS_KEY to false) | ||
|
|
||
| upgrader.upgrade(settings) | ||
|
|
||
| assertThat(settings[ANIMATIONS_KEY]).isEqualTo(AnimationPreference.OFF) | ||
| } | ||
|
|
||
| @Test | ||
| fun `should not insert animations key when missing`() { | ||
| val settings = mutableMapOf<String, Any?>() | ||
|
|
||
| upgrader.upgrade(settings) | ||
|
|
||
| assertThat(settings).doesNotContainKey(ANIMATIONS_KEY) | ||
| } | ||
|
|
||
| @Test | ||
| fun `should leave existing AnimationPreference value unchanged`() { | ||
| val settings = mutableMapOf<String, Any?>(ANIMATIONS_KEY to AnimationPreference.FOLLOW_SYSTEM) | ||
|
|
||
| upgrader.upgrade(settings) | ||
|
|
||
| assertThat(settings[ANIMATIONS_KEY]).isEqualTo(AnimationPreference.FOLLOW_SYSTEM) | ||
| } | ||
|
|
||
| private companion object { | ||
| const val ANIMATIONS_KEY = "animations" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
legacy/storage/src/main/java/com/fsck/k9/preferences/migration/StorageMigrationTo30.kt
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Migrations must be covered by a test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.fsck.k9.preferences.migration | ||
|
|
||
| import android.database.sqlite.SQLiteDatabase | ||
|
|
||
| private const val ANIMATION_KEY = "animations" | ||
|
|
||
| /** | ||
| * Migrate the "animations" setting from boolean string to AnimationPreference enum name. | ||
| * | ||
| * - "true" -> "ON" (user explicitly enabled animations) | ||
| * - "false" -> "OFF" (user explicitly disabled animations) | ||
| * - missing -> no change (new default FOLLOW_SYSTEM will apply) | ||
| */ | ||
| class StorageMigrationTo30( | ||
| private val db: SQLiteDatabase, | ||
| private val migrationsHelper: StorageMigrationHelper, | ||
| ) { | ||
| fun migrateAnimationSetting() { | ||
| val currentValue = migrationsHelper.readValue(db, ANIMATION_KEY) | ||
| when (currentValue) { | ||
| "true" -> migrationsHelper.writeValue(db, ANIMATION_KEY, "ON") | ||
| "false" -> migrationsHelper.writeValue(db, ANIMATION_KEY, "OFF") | ||
| // If missing or already migrated, do nothing | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
legacy/storage/src/test/java/com/fsck/k9/preferences/migration/StorageMigrationTo30Test.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package com.fsck.k9.preferences.migration | ||
|
|
||
| import assertk.assertThat | ||
| import assertk.assertions.doesNotContainKey | ||
| import assertk.assertions.isEqualTo | ||
| import assertk.assertions.key | ||
| import com.fsck.k9.preferences.createPreferencesDatabase | ||
| import kotlin.test.Test | ||
| import net.thunderbird.core.logging.legacy.Log | ||
| import net.thunderbird.core.logging.testing.TestLogger | ||
| import org.junit.After | ||
| import org.junit.Before | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| class StorageMigrationTo30Test { | ||
| private val database = createPreferencesDatabase() | ||
| private val migrationHelper = DefaultStorageMigrationHelper() | ||
| private val migration = StorageMigrationTo30(database, migrationHelper) | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| Log.logger = TestLogger() | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| database.close() | ||
| } | ||
|
|
||
| @Test | ||
| fun `migration should convert animations=true to ON`() { | ||
| migrationHelper.insertValue(database, ANIMATIONS_KEY, "true") | ||
|
|
||
| migration.migrateAnimationSetting() | ||
|
|
||
| assertThat(migrationHelper.readAllValues(database)).key(ANIMATIONS_KEY).isEqualTo("ON") | ||
| } | ||
|
|
||
| @Test | ||
| fun `migration should convert animations=false to OFF`() { | ||
| migrationHelper.insertValue(database, ANIMATIONS_KEY, "false") | ||
|
|
||
| migration.migrateAnimationSetting() | ||
|
|
||
| assertThat(migrationHelper.readAllValues(database)).key(ANIMATIONS_KEY).isEqualTo("OFF") | ||
| } | ||
|
|
||
| @Test | ||
| fun `migration should not insert animations key when missing`() { | ||
| migration.migrateAnimationSetting() | ||
|
|
||
| assertThat(migrationHelper.readAllValues(database)).doesNotContainKey(ANIMATIONS_KEY) | ||
| } | ||
|
|
||
| @Test | ||
| fun `migration should leave already migrated ON value unchanged`() { | ||
| migrationHelper.insertValue(database, ANIMATIONS_KEY, "ON") | ||
|
|
||
| migration.migrateAnimationSetting() | ||
|
|
||
| assertThat(migrationHelper.readAllValues(database)).key(ANIMATIONS_KEY).isEqualTo("ON") | ||
| } | ||
|
|
||
| @Test | ||
| fun `migration should leave already migrated OFF value unchanged`() { | ||
| migrationHelper.insertValue(database, ANIMATIONS_KEY, "OFF") | ||
|
|
||
| migration.migrateAnimationSetting() | ||
|
|
||
| assertThat(migrationHelper.readAllValues(database)).key(ANIMATIONS_KEY).isEqualTo("OFF") | ||
| } | ||
|
|
||
| private companion object { | ||
| const val ANIMATIONS_KEY = "animations" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgraders must be covered by a test.