From eeeb55988d6c6222e4f077d7e0f1eb1d9791bc0c Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 30 Nov 2026 19:39:34 +0100 Subject: [PATCH] Plain launcher icon option (#451) --- app/src/main/AndroidManifest.xml | 42 ++++++- .../data/appname/LauncherNameManager.kt | 109 ------------------ .../calendula/data/backup/SettingsBackup.kt | 16 ++- .../data/backup/SettingsBackupEngine.kt | 18 ++- .../calendula/data/backup/SettingsImport.kt | 5 +- .../data/launcher/LauncherManager.kt | 76 ++++++++++++ .../ui/settings/AppearanceSettings.kt | 88 +++++++++++--- .../ui/settings/SettingsViewModel.kt | 36 +++--- .../drawable/ic_launcher_foreground_plain.xml | 37 ++++++ .../mipmap-anydpi-v26/ic_launcher_plain.xml | 6 + .../ic_launcher_plain_round.xml | 6 + app/src/main/res/values/strings.xml | 4 + .../data/appname/LauncherNameManagerTest.kt | 51 -------- .../data/backup/SettingsBackupTest.kt | 13 ++- .../data/launcher/LauncherAliasTest.kt | 61 ++++++++++ docs/SETTINGS_BACKUP.md | 3 +- floret-kit | 2 +- 17 files changed, 363 insertions(+), 210 deletions(-) delete mode 100644 app/src/main/java/de/jeanlucmakiola/calendula/data/appname/LauncherNameManager.kt create mode 100644 app/src/main/java/de/jeanlucmakiola/calendula/data/launcher/LauncherManager.kt create mode 100644 app/src/main/res/drawable/ic_launcher_foreground_plain.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain_round.xml delete mode 100644 app/src/test/java/de/jeanlucmakiola/calendula/data/appname/LauncherNameManagerTest.kt create mode 100644 app/src/test/java/de/jeanlucmakiola/calendula/data/launcher/LauncherAliasTest.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 27cd8113..6f0754f8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -256,11 +256,11 @@ - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain.xml new file mode 100644 index 00000000..1332d584 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain_round.xml new file mode 100644 index 00000000..1332d584 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_plain_round.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb53ffa0..def8acd1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -620,6 +620,10 @@ Show a jump-to-today button in the toolbar instead of a floating button App name Show Calendula as “Calendar” in your launcher. Only the launcher name changes; the icon may move to a new spot after switching. + App icon + The icon your launcher shows. After switching, the icon may move to a new spot. + Calendula + Plain Time format Automatic 12-hour (2:00 PM) diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/appname/LauncherNameManagerTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/appname/LauncherNameManagerTest.kt deleted file mode 100644 index c806dcea..00000000 --- a/app/src/test/java/de/jeanlucmakiola/calendula/data/appname/LauncherNameManagerTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package de.jeanlucmakiola.calendula.data.appname - -import android.content.pm.PackageManager -import com.google.common.truth.Truth.assertThat -import org.junit.jupiter.api.Test - -/** - * Pure decision logic behind the app-name toggle (issue #44). The framework seam - * ([LauncherNameManager.set]/[current], which call `PackageManager`) is covered - * on-device; these tests pin the read interpretation and the write ordering. - */ -class LauncherNameManagerTest { - - @Test - fun `enabled calendar alias reads as CALENDAR`() { - assertThat(launcherNameFor(PackageManager.COMPONENT_ENABLED_STATE_ENABLED)) - .isEqualTo(LauncherName.CALENDAR) - } - - @Test - fun `default and disabled calendar alias read as CALENDULA`() { - assertThat(launcherNameFor(PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) - .isEqualTo(LauncherName.CALENDULA) - assertThat(launcherNameFor(PackageManager.COMPONENT_ENABLED_STATE_DISABLED)) - .isEqualTo(LauncherName.CALENDULA) - } - - @Test - fun `write plan enables the target alias before disabling the other`() { - val toCalendar = aliasWritePlan(LauncherName.CALENDAR) - assertThat(toCalendar).containsExactly( - AliasStateChange(LauncherAlias.CALENDAR, enabled = true), - AliasStateChange(LauncherAlias.DEFAULT, enabled = false), - ).inOrder() - - val toCalendula = aliasWritePlan(LauncherName.CALENDULA) - assertThat(toCalendula).containsExactly( - AliasStateChange(LauncherAlias.DEFAULT, enabled = true), - AliasStateChange(LauncherAlias.CALENDAR, enabled = false), - ).inOrder() - } - - @Test - fun `write plan never disables both aliases in the same step`() { - // The first step is always an enable, so the launcher can never observe a - // zero-entry transient regardless of switch direction. - for (target in LauncherName.entries) { - assertThat(aliasWritePlan(target).first().enabled).isTrue() - } - } -} diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/backup/SettingsBackupTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/backup/SettingsBackupTest.kt index 959f1003..8d48baa1 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/data/backup/SettingsBackupTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/backup/SettingsBackupTest.kt @@ -3,7 +3,9 @@ package de.jeanlucmakiola.calendula.data.backup import androidx.datastore.preferences.core.MutablePreferences import androidx.datastore.preferences.core.mutablePreferencesOf import com.google.common.truth.Truth.assertThat -import de.jeanlucmakiola.calendula.data.appname.LauncherName +import de.jeanlucmakiola.calendula.data.launcher.LauncherEntry +import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon +import de.jeanlucmakiola.calendula.data.launcher.LauncherName import de.jeanlucmakiola.calendula.data.calendar.ManagedCalendarRow import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride @@ -55,7 +57,7 @@ class SettingsBackupTest { calendars = calendars, managed = listOf(ManagedCalendarRow(3, SpecialDateType.Birthday)), language = LanguageChoice("de"), - launcherName = LauncherName.CALENDAR, + launcher = LauncherEntry(LauncherName.CALENDAR, LauncherIcon.PLAIN), ) val decoded = decodeSettingsBackup(encodeSettingsBackup(backup, 1_700_000_000_000, "2.25.0")) return (decoded as BackupResult.Success).value @@ -358,6 +360,10 @@ class SettingsBackupTest { assertThat(backup.language).isEqualTo(LanguageChoice("de")) assertThat(backup.launcherName).isEqualTo(LauncherName.CALENDAR) + assertThat(backup.launcherIcon).isEqualTo(LauncherIcon.PLAIN) + val plan = planSettingsImport(backup, mutablePreferencesOf(), environment()) + assertThat(plan.launcherName).isEqualTo(LauncherName.CALENDAR) + assertThat(plan.launcherIcon).isEqualTo(LauncherIcon.PLAIN) } @Test @@ -366,7 +372,7 @@ class SettingsBackupTest { {"format":"calendula-settings","version":1,"exportedAt":1,"future":{"x":1}, "settings":{"multi_day_count":4,"some_new_key":true}, "calendars":[{"account_name":"a","account_type":"t","display_name":"d","colour":"red"}], - "app":{"launcher_name":"SOMETHING_NEW"}} + "app":{"launcher_name":"SOMETHING_NEW","launcher_icon":"SOMETHING_NEW"}} """.trimIndent() val backup = (decodeSettingsBackup(text) as BackupResult.Success).value @@ -374,6 +380,7 @@ class SettingsBackupTest { assertThat(backup.prefs.values).containsExactly(4) assertThat(backup.calendars).hasSize(1) assertThat(backup.launcherName).isNull() + assertThat(backup.launcherIcon).isNull() assertThat(backup.language).isNull() } diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/launcher/LauncherAliasTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/launcher/LauncherAliasTest.kt new file mode 100644 index 00000000..ce7f5c71 --- /dev/null +++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/launcher/LauncherAliasTest.kt @@ -0,0 +1,61 @@ +package de.jeanlucmakiola.calendula.data.launcher + +import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT +import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED +import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED +import com.google.common.truth.Truth.assertThat +import de.jeanlucmakiola.floret.android.activeLauncherAlias +import org.junit.jupiter.api.Test + +/** Which alias carries each name × icon combination (#44, #451). */ +class LauncherAliasTest { + + @Test + fun `each combination maps to its alias`() { + assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDULA, LauncherIcon.CALENDULA))) + .isEqualTo(LauncherAlias.DEFAULT) + assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDAR, LauncherIcon.CALENDULA))) + .isEqualTo(LauncherAlias.CALENDAR) + assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDULA, LauncherIcon.PLAIN))) + .isEqualTo(LauncherAlias.PLAIN) + assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDAR, LauncherIcon.PLAIN))) + .isEqualTo(LauncherAlias.CALENDAR_PLAIN) + } + + @Test + fun `every combination has exactly one alias`() { + val combinations = LauncherName.entries.flatMap { name -> + LauncherIcon.entries.map { LauncherEntry(name, it) } + } + assertThat(LauncherAlias.entries.map { it.entry }).containsExactlyElementsIn(combinations) + } + + @Test + fun `pre-451 component names are kept`() { + assertThat(LauncherAlias.DEFAULT.className).isEqualTo("DefaultNameAlias") + assertThat(LauncherAlias.CALENDAR.className).isEqualTo("CalendarNameAlias") + } + + @Test + fun `the default combination is the manifest default`() { + assertThat(LauncherAlias.of(LauncherEntry())).isEqualTo(LauncherAlias.DEFAULT) + } + + @Test + fun `a device switched to Calendar before 451 still reads as Calendar with the flower`() { + val states = mapOf( + LauncherAlias.DEFAULT to COMPONENT_ENABLED_STATE_DISABLED, + LauncherAlias.CALENDAR to COMPONENT_ENABLED_STATE_ENABLED, + LauncherAlias.PLAIN to COMPONENT_ENABLED_STATE_DEFAULT, + LauncherAlias.CALENDAR_PLAIN to COMPONENT_ENABLED_STATE_DEFAULT, + ) + assertThat(activeLauncherAlias(states, LauncherAlias.DEFAULT).entry) + .isEqualTo(LauncherEntry(LauncherName.CALENDAR, LauncherIcon.CALENDULA)) + } + + @Test + fun `changing the icon keeps the name`() { + val entry = LauncherEntry(LauncherName.CALENDAR, LauncherIcon.CALENDULA) + assertThat(LauncherAlias.of(entry.copy(icon = LauncherIcon.PLAIN))).isEqualTo(LauncherAlias.CALENDAR_PLAIN) + } +} diff --git a/docs/SETTINGS_BACKUP.md b/docs/SETTINGS_BACKUP.md index 367a1cda..ac0205b3 100644 --- a/docs/SETTINGS_BACKUP.md +++ b/docs/SETTINGS_BACKUP.md @@ -48,7 +48,7 @@ the exporting install had). Everything is written in one DataStore edit. After that the import refreshes what reads settings outside DataStore: the contact-dates mirror (turned on and synced, or off and torn down, as the settings toggle does), the reminder scan, the automatic-backup schedule, the -launcher name and the app language. Theme and widgets follow the stored +launcher name and icon and the app language. Theme and widgets follow the stored values on their own. A summary lists what could not be imported. ## `settings` @@ -116,6 +116,7 @@ than writing a file without them. |---|---|---| | `language` | String? | The app language tag; `null` follows the system. Absent: left as is. A language this build doesn't ship is skipped. | | `launcher_name` | String? | `CALENDULA` or `CALENDAR`. Unknown: left as is. | +| `launcher_icon` | String? | `CALENDULA` or `PLAIN`. Unknown: left as is. | ## Not exported diff --git a/floret-kit b/floret-kit index 751d0af2..61cad7e5 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 751d0af2ea6044160bf1d6098f17ad07be30be24 +Subproject commit 61cad7e56037e45664beb85ea0599b36a2f723e7