This commit is contained in:
1 parent
8a1e16c5f9
commit
a94ad7560a
10 files changed
+129
-1
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
File renamed without changes.
@@ -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<ReminderLead>) = viewModelScope.launch {
|
||||
prefs.setDefaultReminders(leads)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -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<Preferences> {
|
||||
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<Preferences> = MemoryDataStore()) =
|
||||
SettingsPrefs(dataStore, ProviderResolver(NoProviders))
|
||||
|
||||
@Test
|
||||
fun `a fresh install is comfortable, icons only, with motion on`() = runBlocking<Unit> {
|
||||
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<Unit> {
|
||||
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<Unit> {
|
||||
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<Unit> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
+1
-1
Submodule floret-kit updated: 0c8f5367f5...3e7d342737.
@@ -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" }
|
||||
|
||||
Reference in new issue
Block a user