From a94ad7560a8440daa4fc0d90bc2b0f0735f1a24f Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 27 Nov 2026 12:16:34 +0100 Subject: [PATCH] Store density, button style and reduce motion in floret-kit's appearance prefs (#118, #157) --- app/build.gradle.kts | 1 + .../jeanlucmakiola/agendula/MainActivity.kt | 5 ++ .../agendula/data/prefs/SettingsPrefs.kt | 17 ++++ ...{ShapedActionButton.kt => ActionShapes.kt} | 0 .../agendula/ui/settings/SettingsViewModel.kt | 5 ++ .../jeanlucmakiola/agendula/ui/theme/Theme.kt | 6 ++ .../widget/TaskWidgetConfigActivity.kt | 5 ++ .../data/prefs/AppearanceSettingsTest.kt | 88 +++++++++++++++++++ floret-kit | 2 +- gradle/libs.versions.toml | 1 + 10 files changed, 129 insertions(+), 1 deletion(-) rename app/src/main/java/de/jeanlucmakiola/agendula/ui/common/{ShapedActionButton.kt => ActionShapes.kt} (100%) create mode 100644 app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/AppearanceSettingsTest.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cc3a000..d5bb8e2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -259,6 +259,7 @@ dependencies { implementation(libs.floret.core.reminders) implementation(libs.floret.core.locale) implementation(libs.floret.core.crash) + implementation(libs.floret.core.prefs) implementation(libs.floret.identity) implementation(libs.floret.components) implementation(libs.floret.glance) diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt b/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt index cc3aff0..6809646 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/MainActivity.kt @@ -39,6 +39,8 @@ import de.jeanlucmakiola.agendula.ui.theme.SystemTheme import de.jeanlucmakiola.floret.crash.CrashReportDialog import de.jeanlucmakiola.floret.crash.CrashReporter import de.jeanlucmakiola.floret.crash.submitCrashReport +import de.jeanlucmakiola.floret.prefs.ActionStyle +import de.jeanlucmakiola.floret.prefs.LayoutDensity import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch @@ -109,6 +111,9 @@ class MainActivity : ComponentActivity() { darkTheme = darkTheme, dynamicColor = ui.settings.dynamicColor, pureBlack = ui.settings.themeMode.isPureBlack, + compactLayout = ui.settings.density == LayoutDensity.COMPACT, + shapedActions = ui.settings.actionStyle == ActionStyle.SHAPES, + reduceMotion = ui.settings.reduceMotion, ) { CompositionLocalProvider( LocalUse24HourFormat provides use24Hour, diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt b/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt index e505b46..ebdbada 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt @@ -32,6 +32,11 @@ import de.jeanlucmakiola.agendula.domain.TaskSortOrder import de.jeanlucmakiola.agendula.domain.SmartList import de.jeanlucmakiola.agendula.domain.UpcomingRange import de.jeanlucmakiola.agendula.domain.withinUpcoming +import de.jeanlucmakiola.floret.prefs.ActionStyle +import de.jeanlucmakiola.floret.prefs.AppearancePrefs +import de.jeanlucmakiola.floret.prefs.LayoutDensity +import de.jeanlucmakiola.floret.prefs.get +import de.jeanlucmakiola.floret.prefs.set import de.jeanlucmakiola.floret.reminders.ReminderLead import de.jeanlucmakiola.floret.reminders.ReminderOverride import de.jeanlucmakiola.floret.reminders.ReminderOverrideCodec @@ -100,6 +105,12 @@ const val DEFAULT_ALL_DAY_REMINDER_MINUTE = 9 * 60 data class Settings( val themeMode: ThemeMode = ThemeMode.SYSTEM, val dynamicColor: Boolean = true, + /** How tightly rows and tiles pack. */ + val density: LayoutDensity = LayoutDensity.COMFORTABLE, + /** Plain icons or expressive shapes for header and top-bar actions (#118). */ + val actionStyle: ActionStyle = ActionStyle.ICONS, + /** Stops looping animations; the system "Remove animations" does so regardless (#157). */ + val reduceMotion: Boolean = false, /** The list a new task defaults to; `null` = first available. */ val defaultListId: Long? = null, /** Default reminders (0 before due = at due time); empty = none. */ @@ -280,6 +291,9 @@ class SettingsPrefs @Inject constructor( themeMode = p[THEME_MODE]?.let { runCatching { ThemeMode.valueOf(it) }.getOrNull() } ?: ThemeMode.SYSTEM, dynamicColor = p[DYNAMIC_COLOR] ?: true, + density = p[AppearancePrefs.density], + actionStyle = p[AppearancePrefs.actionStyle], + reduceMotion = p[AppearancePrefs.reduceMotion], defaultListId = p[DEFAULT_LIST_ID]?.takeIf { it > 0 }, // The single lead of earlier versions carries over until a list is saved. defaultReminders = p[DEFAULT_REMINDERS]?.let(::parseLeads) @@ -442,6 +456,9 @@ class SettingsPrefs @Inject constructor( suspend fun setThemeMode(mode: ThemeMode) = dataStore.edit { it[THEME_MODE] = mode.name } suspend fun setDynamicColor(enabled: Boolean) = dataStore.edit { it[DYNAMIC_COLOR] = enabled } + suspend fun setDensity(density: LayoutDensity) = dataStore.edit { it[AppearancePrefs.density] = density } + suspend fun setActionStyle(style: ActionStyle) = dataStore.edit { it[AppearancePrefs.actionStyle] = style } + suspend fun setReduceMotion(enabled: Boolean) = dataStore.edit { it[AppearancePrefs.reduceMotion] = enabled } suspend fun setDefaultListId(id: Long?) = dataStore.edit { if (id == null) it.remove(DEFAULT_LIST_ID) else it[DEFAULT_LIST_ID] = id } diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/common/ShapedActionButton.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/common/ActionShapes.kt similarity index 100% rename from app/src/main/java/de/jeanlucmakiola/agendula/ui/common/ShapedActionButton.kt rename to app/src/main/java/de/jeanlucmakiola/agendula/ui/common/ActionShapes.kt diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/settings/SettingsViewModel.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/settings/SettingsViewModel.kt index 6c697f9..4ced0fc 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/ui/settings/SettingsViewModel.kt @@ -28,6 +28,8 @@ import de.jeanlucmakiola.agendula.domain.DefaultDueDate import de.jeanlucmakiola.agendula.domain.DefaultStartDate import de.jeanlucmakiola.agendula.domain.TaskFormField import de.jeanlucmakiola.agendula.domain.TaskList +import de.jeanlucmakiola.floret.prefs.ActionStyle +import de.jeanlucmakiola.floret.prefs.LayoutDensity import de.jeanlucmakiola.floret.reminders.ReminderLead import de.jeanlucmakiola.floret.reminders.ReminderOverride import kotlinx.coroutines.CoroutineDispatcher @@ -242,6 +244,9 @@ class SettingsViewModel @Inject constructor( fun setThemeMode(mode: ThemeMode) = viewModelScope.launch { prefs.setThemeMode(mode) } fun setDynamicColor(enabled: Boolean) = viewModelScope.launch { prefs.setDynamicColor(enabled) } + fun setDensity(density: LayoutDensity) = viewModelScope.launch { prefs.setDensity(density) } + fun setActionStyle(style: ActionStyle) = viewModelScope.launch { prefs.setActionStyle(style) } + fun setReduceMotion(enabled: Boolean) = viewModelScope.launch { prefs.setReduceMotion(enabled) } fun setDefaultList(id: Long?) = viewModelScope.launch { prefs.setDefaultListId(id) } fun setDefaultReminders(leads: List) = viewModelScope.launch { prefs.setDefaultReminders(leads) diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/theme/Theme.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/theme/Theme.kt index 6e02f5f..3addeca 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/ui/theme/Theme.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/ui/theme/Theme.kt @@ -16,6 +16,9 @@ fun AgendulaTheme( darkTheme: Boolean = isSystemInDarkTheme(), dynamicColor: Boolean = true, pureBlack: Boolean = false, + compactLayout: Boolean = false, + shapedActions: Boolean = false, + reduceMotion: Boolean = false, content: @Composable () -> Unit, ) { FloretExpressiveTheme( @@ -25,6 +28,9 @@ fun AgendulaTheme( dynamicColor = dynamicColor, pureBlack = pureBlack, typography = AgendulaTypography, + compactLayout = compactLayout, + shapedActions = shapedActions, + reduceMotion = reduceMotion, content = content, ) } diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/widget/TaskWidgetConfigActivity.kt b/app/src/main/java/de/jeanlucmakiola/agendula/widget/TaskWidgetConfigActivity.kt index 504720c..373e760 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/widget/TaskWidgetConfigActivity.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/widget/TaskWidgetConfigActivity.kt @@ -55,6 +55,8 @@ import de.jeanlucmakiola.floret.components.pastelize import de.jeanlucmakiola.floret.components.positionOf import de.jeanlucmakiola.floret.glance.WidgetBackground import de.jeanlucmakiola.floret.glance.WidgetThemeMode +import de.jeanlucmakiola.floret.prefs.ActionStyle +import de.jeanlucmakiola.floret.prefs.LayoutDensity import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.launch @@ -139,6 +141,9 @@ class TaskWidgetConfigActivity : ComponentActivity() { darkTheme = dark, dynamicColor = settings.dynamicColor, pureBlack = settings.themeMode.isPureBlack, + compactLayout = settings.density == LayoutDensity.COMPACT, + shapedActions = settings.actionStyle == ActionStyle.SHAPES, + reduceMotion = settings.reduceMotion, ) { Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surface) {} WidgetFilterPicker( diff --git a/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/AppearanceSettingsTest.kt b/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/AppearanceSettingsTest.kt new file mode 100644 index 0000000..1ae24a8 --- /dev/null +++ b/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/AppearanceSettingsTest.kt @@ -0,0 +1,88 @@ +package de.jeanlucmakiola.agendula.data.prefs + +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey +import androidx.datastore.preferences.core.emptyPreferences +import androidx.datastore.preferences.core.mutablePreferencesOf +import androidx.datastore.preferences.core.stringPreferencesKey +import com.google.common.truth.Truth.assertThat +import de.jeanlucmakiola.agendula.data.tasks.ProviderEnvironment +import de.jeanlucmakiola.agendula.data.tasks.ProviderResolver +import de.jeanlucmakiola.floret.prefs.ActionStyle +import de.jeanlucmakiola.floret.prefs.LayoutDensity +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.Test + +/** Density, button style and reduce motion: their defaults, and that a choice sticks. */ +class AppearanceSettingsTest { + + private class MemoryDataStore(initial: Preferences = emptyPreferences()) : DataStore { + override val data = MutableStateFlow(initial) + override suspend fun updateData(transform: suspend (t: Preferences) -> Preferences) = + transform(data.value).also { data.value = it } + } + + private object NoProviders : ProviderEnvironment { + override fun packageDeclaring(authority: String): String? = null + override fun isGranted(permission: String) = false + override fun appLabel(packageName: String): String? = null + } + + private fun prefs(dataStore: DataStore = MemoryDataStore()) = + SettingsPrefs(dataStore, ProviderResolver(NoProviders)) + + @Test + fun `a fresh install is comfortable, icons only, with motion on`() = runBlocking { + val settings = prefs().settings.first() + + assertThat(Triple(settings.density, settings.actionStyle, settings.reduceMotion)) + .isEqualTo(Triple(LayoutDensity.COMFORTABLE, ActionStyle.ICONS, false)) + } + + @Test + fun `an existing install gets icons only too`() = runBlocking { + val upgraded = MemoryDataStore( + mutablePreferencesOf( + stringPreferencesKey("theme_mode") to "DARK", + booleanPreferencesKey("dynamic_color") to false, + ), + ) + + assertThat(prefs(upgraded).settings.first().actionStyle).isEqualTo(ActionStyle.ICONS) + } + + @Test + fun `the choices are kept`() = runBlocking { + val prefs = prefs() + + prefs.setDensity(LayoutDensity.COMPACT) + prefs.setActionStyle(ActionStyle.SHAPES) + prefs.setReduceMotion(true) + + val settings = prefs.settings.first() + assertThat(Triple(settings.density, settings.actionStyle, settings.reduceMotion)) + .isEqualTo(Triple(LayoutDensity.COMPACT, ActionStyle.SHAPES, true)) + } + + @Test + fun `the choices are stored under the keys floret-kit shares`() = runBlocking { + val dataStore = MemoryDataStore() + val prefs = prefs(dataStore) + + prefs.setDensity(LayoutDensity.COMPACT) + prefs.setActionStyle(ActionStyle.SHAPES) + prefs.setReduceMotion(true) + + val stored = dataStore.data.value + assertThat( + listOf( + stored[stringPreferencesKey("layout_density")], + stored[stringPreferencesKey("action_style")], + stored[booleanPreferencesKey("reduce_motion")], + ), + ).containsExactly("COMPACT", "SHAPES", true).inOrder() + } +} diff --git a/floret-kit b/floret-kit index 0c8f536..3e7d342 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 0c8f5367f5d4e2e611cc6d4e9761e4b41428dd02 +Subproject commit 3e7d342737d5265398fb6b618ed101979e87a334 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 92afa2b..f910a54 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -174,6 +174,7 @@ floret-core-time = { group = "de.jeanlucmakiola.floret", name = "core-time" } floret-core-reminders = { group = "de.jeanlucmakiola.floret", name = "core-reminders" } floret-core-locale = { group = "de.jeanlucmakiola.floret", name = "core-locale" } floret-core-crash = { group = "de.jeanlucmakiola.floret", name = "core-crash" } +floret-core-prefs = { group = "de.jeanlucmakiola.floret", name = "core-prefs" } floret-identity = { group = "de.jeanlucmakiola.floret", name = "identity" } floret-components = { group = "de.jeanlucmakiola.floret", name = "components" } floret-glance = { group = "de.jeanlucmakiola.floret", name = "glance" }