Author SHA1 Message Date
makiolaj b7ce0bc5b1 chore: move floret-kit to the ring branch with calendula#145's core-android fix (calendula#171) 2026-11-14 03:04:48 +01:00
makiolaj a83fe5b4bc fix: review round 2 - TonePlayer only behind RingAudioPlayer, floret-kit ring fixes (calendula#171) 2026-11-13 17:43:35 +01:00
makiolaj 3a36b26686 refactor: in-call check from floret-kit's ring module (calendula#171) 2026-11-13 17:35:11 +01:00
makiolaj 3200afd97b fix: review round 1 - TonePlayer in the audio-path rule, self-check opens the full-screen settings with a fallback (calendula#171) 2026-11-13 17:18:39 +01:00
makiolaj 8a5d7c434b chore: move floret-kit to the ring module's review fixes (calendula#171) 2026-11-13 17:13:33 +01:00
makiolaj bf19f70543 refactor: ring through floret-kit's shared ring module (calendula#171) 2026-11-13 17:00:52 +01:00
makiolaj a81a3641ce chore(release): 1.0.0-beta.8
Beta — Codeberg pre-release / detect (push) Successful in 5s
Beta — Codeberg pre-release / beta (push) Successful in 11m52s
2026-11-02 20:15:55 +01:00
makiolaj 4a29346351 chore: move floret-kit to main after the SnackChip fix (floret-kit#26) 2026-11-02 20:10:53 +01:00
makiolaj 0148031907 fix: review findings on week start and settings motion
- The last week start is saved with the activity, so a rotation no
  longer draws one frame in the locale's order before the stored day.
- A backup with "week_start": null restores Automatic instead of
  rejecting the whole file.
- Under reduced motion a settings sub-page fades in, matching its exit.
- LocalWeekStart, rememberWeekStart and one shared rememberLocale move
  to ui/common; the picker, the day buttons and the summaries use them.
- The "Week starts on" row shows the day Automatic resolves to.
2026-11-02 19:40:06 +01:00
makiolaj fe17bcc8e8 Merge branch 'feat/29-world-clock-list' into release/v1.0.0
# Conflicts:
#	app/src/main/java/de/jeanlucmakiola/clockula/data/prefs/SettingsPrefs.kt
#	app/src/main/java/de/jeanlucmakiola/clockula/ui/settings/ClockSettingsScreen.kt
#	app/src/main/java/de/jeanlucmakiola/clockula/ui/settings/SettingsViewModel.kt
#	app/src/main/res/values/strings.xml
#	app/src/test/java/de/jeanlucmakiola/clockula/backup/BackupEngineTest.kt
#	app/src/test/java/de/jeanlucmakiola/clockula/ui/settings/SettingsViewModelTest.kt
#	docs/ARCHITECTURE.md
2026-11-02 19:30:34 +01:00
makiolaj 381f2b8f69 Merge branch 'feat/30-week-start-impl' into release/v1.0.0
# Conflicts:
#	app/src/main/java/de/jeanlucmakiola/clockula/ui/settings/ClockSettingsScreen.kt
2026-11-02 19:29:55 +01:00
makiolaj 8c5c664cd9 Merge branch 'feat/32-settings-back-motion' into release/v1.0.0 2026-11-02 19:29:43 +01:00
makiolaj f3789fc164 Merge branch 'fix/35-snack-chip-shadow' into release/v1.0.0 2026-11-02 19:29:43 +01:00
makiolaj 7d65b2b206 feat(world-clock): an optional compact home clock
A "Compact home clock" switch under Settings > Clock swaps the World clock
tab's analog face for a row: a home glyph, the city, "Home · <zone name>"
and the time, in the seconds-aware style the city rows use and spoken to
the minute like them. It is drawn the way the automatic local clock's row
is, through one shared pinned-row composable, and the local row still sits
directly under home. Off by default.

Like show-seconds it is display-only, so it is its own preference and flow
(world_clock_compact_home) rather than a clock default, and it is applied
outside the tick so flipping it does not restart the ticker. Backups carry
it; older files restore it as off.

Closes #29.
2026-11-02 19:29:16 +01:00
makiolaj 3e74d03ea7 feat(settings): a "Week starts on" setting
Settings > Clock gets a "Week starts on" row: Automatic, which follows
the locale (and with it Android 14's regional first-day preference), or
any of the seven days, after Calendula's own. The repeat-day buttons in
the alarm editor and on the bedtime screen, and the alarm list's day
summaries, start on the chosen day. MainActivity reads the preference
once and provides it as LocalWeekStart.

Stored under Calendula's key name, week_start, and carried in the
backup; a file without it, or with a value this version does not know,
restores Automatic.

Closes #30.
2026-11-02 19:27:55 +01:00
makiolaj d749bc0b7b feat(settings): sub-pages leave with the predictive-back motion
A settings sub-page now previews the back gesture and leaves fading and
shrinking toward the hub, as in Calendula and Agendula, instead of
sliding out. The sub-page's scaffold takes back, replacing the hub's
BackHandler. Closes #32.
2026-11-02 19:17:29 +01:00
makiolaj 5d7876684d fix(ui): the Undo chip's shadow no longer shows square
Moves the floret-kit pin to the SnackChip fix (floret-kit#26).
2026-11-02 19:15:34 +01:00
makiolaj 005df7db19 chore(release): 1.0.0-beta.7
Beta — Codeberg pre-release / detect (push) Successful in 7s
Beta — Codeberg pre-release / beta (push) Successful in 12m6s
2026-11-02 18:53:09 +01:00
makiolaj 0a92dce8a9 Merge branch 'fix/black-nav-bar' into release/v1.0.0 2026-11-02 18:51:05 +01:00
makiolaj cd705961ca fix(appearance): a black navigation bar in the Black theme
The tab bar sat on surfaceContainer, which the Black theme only dims, and
the three-button scrim was the dark theme's grey. Both are black now, so
the bottom of the screen is black down to the system bar (#28).
2026-11-02 18:48:53 +01:00
60 changed files with 757 additions and 621 deletions

No files matched your search

+6 -4
View File
@@ -26,8 +26,9 @@ The first release of Clockula: alarms, timers, a stopwatch and a world clock.
reader. Deleting an alarm, or a timer from its card, doesn't ask first:
Undo brings it back with all its settings, and a snoozed alarm comes back
snoozed.
- Repeat days that start on your locale's first day of the week, and a "skip
next alarm" switch so you can sleep in once without turning the alarm off.
- Repeat days that start on your locale's first day of the week, or on any
day you pick under "Week starts on" in Settings > Clock, and a "skip next
alarm" switch so you can sleep in once without turning the alarm off.
- An "Upcoming alarm" notification two hours before an alarm rings, with a
Dismiss button, so you can turn off today's alarm when you're already awake.
A repeating alarm skips just that once; a one-time alarm is switched off.
@@ -72,7 +73,8 @@ The first release of Clockula: alarms, timers, a stopwatch and a world clock.
the offset from your time and whether it's a different day there. Reorder
them by dragging or with a screen reader, and set a home time zone or follow
the device. "Display time with seconds" in Settings > Clock adds seconds to
every time on the tab and a second hand to the face.
every time on the tab and a second hand to the face, and "Compact home
clock" swaps the face for a row like the other cities'.
- An automatic local clock while travelling. When you've set a home time zone
and your device is somewhere the time differs, the World clock tab adds a
"Local time" row under the home face. It goes away again once you're back
@@ -88,7 +90,7 @@ The first release of Clockula: alarms, timers, a stopwatch and a world clock.
- Settings: theme, dynamic colour, language, and the defaults every new alarm
and timer inherits.
- A Black theme next to Light and Dark: dark with pure black backgrounds,
for AMOLED screens.
navigation bar included, for AMOLED screens.
- Choose how long a ringing alarm or a finished timer keeps going before it
stops on its own: 1, 5, 10, 15, 20 or 25 minutes, or Never, separately for
alarms and timers. Ten minutes stays the default, and Never still stops
+3 -2
View File
@@ -32,8 +32,8 @@ android {
// versionCode is derived from versionName by scripts/version_info.sh
// (1.0.0-beta.1 -> 1000001, 1.0.0 -> 1000099), and CI fails if the
// committed one doesn't match. See docs/RELEASING.md.
versionCode = 1000006
versionName = "1.0.0-beta.6"
versionCode = 1000008
versionName = "1.0.0-beta.8"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
@@ -217,6 +217,7 @@ dependencies {
implementation("de.jeanlucmakiola.floret:identity")
implementation("de.jeanlucmakiola.floret:components")
implementation("de.jeanlucmakiola.floret:glance")
implementation("de.jeanlucmakiola.floret:ring")
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
@@ -9,16 +9,20 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.bedtime.BedtimeIntents
import de.jeanlucmakiola.clockula.data.prefs.SettingsPrefs
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.interop.InteropIntents
import de.jeanlucmakiola.clockula.ui.common.LocalWeekStart
import de.jeanlucmakiola.clockula.ui.crash.CrashReportActivity
import de.jeanlucmakiola.clockula.ui.shell.ClockulaShell
import de.jeanlucmakiola.clockula.ui.shell.ShellNavigation
@@ -96,25 +100,37 @@ class MainActivity : ComponentActivity() {
val appearance by settingsPrefs.appearance
.collectAsStateWithLifecycle(initialValue = Appearance())
val darkTheme = appearance.themeMode.isDark(isSystemInDarkTheme())
// Read here once rather than by each screen that lays out a week:
// the alarm list, the alarm editor and bedtime all do (#30). The
// last value is saved with the activity, so a rotation or a theme
// change doesn't draw one frame in the locale's order first.
var lastWeekStart by rememberSaveable { mutableStateOf(WeekStartPref.AUTO) }
val weekStart by settingsPrefs.weekStart
.collectAsStateWithLifecycle(initialValue = WeekStartPref.parse(lastWeekStart))
LaunchedEffect(weekStart) { lastWeekStart = weekStart.storageValue }
// The system bars follow the *resolved* theme, not the device night
// flag: with the device dark and ThemeMode.LIGHT stored, deriving the
// icon colours from the system would paint white icons onto a light
// background. Re-applied whenever the stored preference changes.
LaunchedEffect(darkTheme) { applyEdgeToEdge(darkTheme) }
val pureBlack = darkTheme && appearance.themeMode.isPureBlack
LaunchedEffect(darkTheme, pureBlack) { applyEdgeToEdge(darkTheme, pureBlack) }
ClockulaTheme(
darkTheme = darkTheme,
dynamicColor = appearance.dynamicColor,
pureBlack = appearance.themeMode.isPureBlack,
pureBlack = pureBlack,
) {
ClockulaShell(
modifier = Modifier.fillMaxSize(),
openRequest = openRequest,
// Consumed once: a request left standing would re-select the
// tab on every recomposition and fight the user's taps.
onRequestConsumed = { openRequest = null },
)
CompositionLocalProvider(LocalWeekStart provides weekStart) {
ClockulaShell(
modifier = Modifier.fillMaxSize(),
pureBlack = pureBlack,
openRequest = openRequest,
// Consumed once: a request left standing would re-select the
// tab on every recomposition and fight the user's taps.
onRequestConsumed = { openRequest = null },
)
}
// First launch asks for notifications once, and only here:
// it belongs to starting the app, not to any one tab.
RequestNotificationPermissionOnce(settingsPrefs)
@@ -136,10 +152,11 @@ class MainActivity : ComponentActivity() {
}
}
private fun applyEdgeToEdge(darkTheme: Boolean) {
private fun applyEdgeToEdge(darkTheme: Boolean, pureBlack: Boolean) {
val darkScrim = if (pureBlack) NAV_BAR_BLACK_SCRIM else NAV_BAR_DARK_SCRIM
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(NAV_BAR_LIGHT_SCRIM, NAV_BAR_DARK_SCRIM) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(NAV_BAR_LIGHT_SCRIM, darkScrim) { darkTheme },
)
}
@@ -187,3 +204,6 @@ class MainActivity : ComponentActivity() {
/** The scrims androidx uses for a three-button navigation bar, matched exactly. */
private val NAV_BAR_LIGHT_SCRIM = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
private val NAV_BAR_DARK_SCRIM = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
/** The Black theme's: the dark one's alpha over black, so the bar reads black (#28). */
private val NAV_BAR_BLACK_SCRIM = Color.argb(0x80, 0x00, 0x00, 0x00)
@@ -7,6 +7,7 @@ import android.os.Build
import dagger.hilt.android.qualifiers.ApplicationContext
import de.jeanlucmakiola.clockula.alarm.AlarmCapabilities
import de.jeanlucmakiola.clockula.domain.alarm.CapabilitySnapshot
import de.jeanlucmakiola.floret.ring.canUseFullScreenIntent
import javax.inject.Inject
import javax.inject.Singleton
@@ -23,7 +24,7 @@ class AndroidAlarmCapabilities @Inject constructor(
override fun snapshot(): CapabilitySnapshot = CapabilitySnapshot(
canScheduleExactAlarms = canScheduleExactAlarms(),
canUseFullScreenIntent = canUseFullScreenIntent(),
canUseFullScreenIntent = context.canUseFullScreenIntent(),
notificationsEnabled = notifications().areNotificationsEnabled(),
)
@@ -34,13 +35,6 @@ class AndroidAlarmCapabilities @Inject constructor(
true
}
private fun canUseFullScreenIntent(): Boolean =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
notifications().canUseFullScreenIntent()
} else {
true
}
private fun notifications(): NotificationManager =
context.getSystemService(NotificationManager::class.java)
}
@@ -5,8 +5,8 @@ import android.content.Intent
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.alarm.AlarmEngine
import de.jeanlucmakiola.clockula.alarm.AlarmIntents
import de.jeanlucmakiola.clockula.ring.HandoffWakeLock
import de.jeanlucmakiola.floret.di.ApplicationScope
import de.jeanlucmakiola.floret.ring.RingWakeLock
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlin.time.Instant
@@ -34,7 +34,7 @@ class AlarmFireReceiver : HiltBroadcastReceiver() {
val alarmId = intent.getLongExtra(AlarmIntents.EXTRA_ALARM_ID, 0L)
val action = intent.action ?: return
if (action == AlarmIntents.ACTION_FIRE) HandoffWakeLock.acquire(context, "clockula:alarm-fire")
if (action == AlarmIntents.ACTION_FIRE) RingWakeLock.handOff(context, "clockula:alarm-fire")
val pendingResult = goAsync()
scope.launch {
try {
@@ -6,10 +6,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import android.os.PowerManager
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.alarm.AlarmCapabilities
import de.jeanlucmakiola.clockula.alarm.AlarmEngine
@@ -21,8 +18,10 @@ import de.jeanlucmakiola.clockula.domain.ring.RingFallbackPolicy
import de.jeanlucmakiola.clockula.domain.ring.SilenceAfter
import de.jeanlucmakiola.clockula.ring.ForegroundRingScreen
import de.jeanlucmakiola.clockula.ring.RingAudioPlayer
import de.jeanlucmakiola.clockula.ring.RingVibrator
import de.jeanlucmakiola.clockula.ui.ring.AlarmRingActivity
import de.jeanlucmakiola.floret.ring.RingVibrator
import de.jeanlucmakiola.floret.ring.RingWakeLock
import de.jeanlucmakiola.floret.ring.startRingForeground
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -58,7 +57,7 @@ class AlarmRingService : Service() {
private val audio by lazy { RingAudioPlayer(this) }
private val vibrator by lazy { RingVibrator(this) }
private var wakeLock: PowerManager.WakeLock? = null
private val wakeLock by lazy { RingWakeLock(this, WAKE_LOCK_TAG, WAKE_LOCK_TIMEOUT_MILLIS) }
private var ringing: Job? = null
/** The alarm this service last asked a ring screen for. */
@@ -94,7 +93,7 @@ class AlarmRingService : Service() {
// database read is not something to spend them on.
startForegroundPreparing()
// Also before the read: the fire broadcast's own wake lock is gone by now.
acquireWakeLock()
wakeLock.acquire()
ringing = scope.launch {
val session = engine.ringSession()
if (session == null) {
@@ -184,26 +183,7 @@ class AlarmRingService : Service() {
private fun startForeground(notification: Notification) {
posted = notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// systemExempted: Android's own guidance names an app holding an
// exact-alarm permission and continuing an alarm in the background.
startForeground(
RingNotifications.RING_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED,
)
} else {
startForeground(RingNotifications.RING_NOTIFICATION_ID, notification)
}
}
private fun acquireWakeLock() {
if (wakeLock != null) return
val power = getSystemService(PowerManager::class.java)
wakeLock = power.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply {
setReferenceCounted(false)
runCatching { acquire(WAKE_LOCK_TIMEOUT_MILLIS) }
}
startRingForeground(RingNotifications.RING_NOTIFICATION_ID, notification)
}
private fun releaseRing() {
@@ -211,8 +191,7 @@ class AlarmRingService : Service() {
ringing = null
audio.stop()
vibrator.stop()
wakeLock?.let { if (it.isHeld) runCatching { it.release() } }
wakeLock = null
wakeLock.release()
}
private fun stop() {
@@ -116,8 +116,10 @@ class BackupEngine @Inject constructor(
defaults = settings.currentDefaults(),
timerPresets = settings.timerPresets.first(),
worldClockSeconds = settings.worldClockSeconds.first(),
compactHomeClock = settings.compactHomeClock.first(),
screenSaver = settings.screenSaver.first(),
quickTileDuration = settings.quickTileDuration.first(),
weekStart = settings.weekStart.first(),
bedtime = settings.currentBedtime(),
)
}
@@ -7,6 +7,7 @@ import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.PauseRange
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.TimeOfDay
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.Zones
import de.jeanlucmakiola.clockula.domain.alarm.VolumeButtonAction
import de.jeanlucmakiola.clockula.domain.backup.BackupAlarm
@@ -148,11 +149,13 @@ object BackupCodec {
volumeButtons = defaults.volumeButtons.name,
automaticLocalClock = defaults.automaticLocalClock,
worldClockSeconds = worldClockSeconds,
compactHomeClock = compactHomeClock,
timerPresets = timerPresets.map { it.inWholeMilliseconds },
bedtime = bedtime?.toDto(),
screenSaverStyle = screenSaver.style.name,
screenSaverNightMode = screenSaver.nightMode,
quickTileDurationMillis = quickTileDuration.inWholeMilliseconds,
weekStart = weekStart.storageValue,
)
private fun BedtimeSettings.toDto() = BedtimeDto(
@@ -311,11 +314,13 @@ object BackupCodec {
),
timerPresets = settingsDto.timerPresets?.map { it.milliseconds } ?: TimerPresets.BUILT_IN,
worldClockSeconds = settingsDto.worldClockSeconds,
compactHomeClock = settingsDto.compactHomeClock,
screenSaver = ScreenSaverSettings(
style = settingsDto.screenSaverStyle.toEnum(ScreenSaverStyle.DIGITAL),
nightMode = settingsDto.screenSaverNightMode,
),
quickTileDuration = parseQuickTimerDuration(settingsDto.quickTileDurationMillis),
weekStart = WeekStartPref.parse(settingsDto.weekStart),
bedtime = settingsDto.bedtime?.toBedtime(),
)
@@ -97,6 +97,8 @@ data class SettingsDto(
@SerialName("automatic_local_clock") val automaticLocalClock: Boolean = true,
/** Absent in files from before it existed, which keeps the default: off. */
@SerialName("world_clock_show_seconds") val worldClockSeconds: Boolean = false,
/** Absent in files from before #29, which keeps the default: off. */
@SerialName("world_clock_compact_home") val compactHomeClock: Boolean = false,
/**
* Absent is not empty: an empty list is a user who removed every preset,
* while a file without the field (an older or hand-written one) keeps the
@@ -110,6 +112,8 @@ data class SettingsDto(
@SerialName("screen_saver_night_mode") val screenSaverNightMode: Boolean = false,
/** Absent (a file from before #26) or out of range keeps the tile's default. */
@SerialName("quick_tile_duration_millis") val quickTileDurationMillis: Long? = null,
/** Absent (a file from before #30), null or unrecognised follows the locale, the default. */
@SerialName("week_start") val weekStart: String? = null,
)
/**
@@ -2,6 +2,7 @@ package de.jeanlucmakiola.clockula.data.prefs
import de.jeanlucmakiola.clockula.domain.ClockLimits
import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.Zones
import de.jeanlucmakiola.clockula.domain.alarm.VolumeButtonAction
import de.jeanlucmakiola.clockula.domain.ring.SilenceAfter
@@ -74,6 +75,13 @@ object ClockPrefs {
*/
val worldClockSeconds: Pref<Boolean> = booleanPref("world_clock_show_seconds", false)
/**
* The world clock tab's home as a row like the cities' rather than the
* analog face (#29). Off by default. Not part of `ClockDefaults`, for the
* same reason as [worldClockSeconds].
*/
val compactHomeClock: Pref<Boolean> = booleanPref("world_clock_compact_home", false)
/**
* Whether a ringing alarm or timer opens its screen over another app
* rather than as a heads-up. Off by default, and only in effect while the
@@ -92,6 +100,14 @@ object ClockPrefs {
*/
val automaticLocalClock: Pref<Boolean> = booleanPref("automatic_local_clock", true)
/**
* The first day of the week (#30), under Calendula's key name. Absent means
* [WeekStartPref.Auto], so an upgrade keeps the locale's week. Not a clock
* default either: no alarm overrides it.
*/
val weekStart: Pref<WeekStartPref> =
nullableStringPref("week_start").map(decode = WeekStartPref::parse, encode = { it.storageValue })
private fun Pref<Int>.clampedTo(range: IntRange): Pref<Int> =
map(decode = { it.coerceIn(range) }, encode = { it.coerceIn(range) })
@@ -4,6 +4,7 @@ import androidx.datastore.preferences.core.MutablePreferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import de.jeanlucmakiola.clockula.domain.ClockDefaults
import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.alarm.VolumeButtonAction
import de.jeanlucmakiola.clockula.domain.backup.BackupSettings
import de.jeanlucmakiola.clockula.domain.bedtime.BedtimeEffects
@@ -128,6 +129,8 @@ class SettingsPrefs @Inject constructor(private val store: PrefStore) {
prefs[ClockPrefs.volumeButtons] = backup.defaults.volumeButtons
prefs[ClockPrefs.automaticLocalClock] = backup.defaults.automaticLocalClock
prefs[ClockPrefs.worldClockSeconds] = backup.worldClockSeconds
prefs[ClockPrefs.weekStart] = backup.weekStart
prefs[ClockPrefs.compactHomeClock] = backup.compactHomeClock
prefs[TimerPrefs.presets] = backup.timerPresets
// Absent from a file written before bedtime existed: keep it.
backup.bedtime?.let { prefs.putBedtime(it) }
@@ -191,6 +194,20 @@ class SettingsPrefs @Inject constructor(private val store: PrefStore) {
suspend fun setWorldClockSeconds(enabled: Boolean) = store.set(ClockPrefs.worldClockSeconds, enabled)
// --- week start (#30) ---
/** Its own flow, like [worldClockSeconds]: nothing an alarm or timer inherits depends on it. */
val weekStart: Flow<WeekStartPref> = store.flow(ClockPrefs.weekStart)
suspend fun setWeekStart(pref: WeekStartPref) = store.set(ClockPrefs.weekStart, pref)
// --- compact home clock (#29) ---
/** Its own flow, as [worldClockSeconds] is (#29). */
val compactHomeClock: Flow<Boolean> = store.flow(ClockPrefs.compactHomeClock)
suspend fun setCompactHomeClock(enabled: Boolean) = store.set(ClockPrefs.compactHomeClock, enabled)
// --- ring screen over other apps ---
val ringOverOtherApps: Flow<Boolean> = store.flow(ClockPrefs.ringOverOtherApps)
@@ -8,7 +8,7 @@ sealed interface RepeatSummary {
data object Weekdays : RepeatSummary
data object Weekends : RepeatSummary
/** The mask's days, ordered from the locale's first day of week. Never empty. */
/** The mask's days, ordered from the week's first day. Never empty. */
data class SomeDays(val days: List<DayOfWeek>) : RepeatSummary
}
@@ -0,0 +1,40 @@
package de.jeanlucmakiola.clockula.domain
import java.time.DayOfWeek
import java.time.temporal.WeekFields
import java.util.Locale
/**
* Which day the week starts on wherever Clockula lays one out: the repeat-day
* buttons and the alarm list's day summaries (#30). [Auto] follows the locale,
* which on Android 14 and up carries the regional first-day preference too;
* [Day] pins any of the seven. After Calendula's own.
*/
sealed interface WeekStartPref {
data object Auto : WeekStartPref
data class Day(val day: DayOfWeek) : WeekStartPref
/** What the preference and the backup store: [AUTO], or a [DayOfWeek] name. */
val storageValue: String
get() = when (this) {
Auto -> AUTO
is Day -> day.name
}
companion object {
const val AUTO = "AUTO"
/** [Auto], then Monday to Sunday: the picker's options. */
val OPTIONS: List<WeekStartPref> = listOf(Auto) + DayOfWeek.entries.map(::Day)
/** Absent, [AUTO] or anything unrecognised reads as [Auto]. */
fun parse(stored: String?): WeekStartPref =
DayOfWeek.entries.firstOrNull { it.name == stored }?.let(::Day) ?: Auto
}
}
/** The concrete first day: the pinned one, or [locale]'s (Monday in DE, Sunday in en-US). */
fun WeekStartPref.resolveFirstDay(locale: Locale): DayOfWeek = when (this) {
is WeekStartPref.Day -> day
WeekStartPref.Auto -> WeekFields.of(locale).firstDayOfWeek
}
@@ -7,7 +7,7 @@ import kotlin.time.Duration.Companion.minutes
* The alarm ring cycle's constants. They are values rather than settings
* (docs/PLAN.md §4). How long an alarm rings before it is silenced as missed
* became a setting in #17: `ClockDefaults.alarmSilenceAfter`. The audio
* chain's own constants live in `domain/ring/RingAudio`, shared with the
* chain's own constants live in floret-kit's `VolumeRamp`, shared with the
* timer's ring.
*/
object AlarmRing {
@@ -5,6 +5,7 @@ import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.PauseRange
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.TimeOfDay
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.bedtime.BedtimeSettings
import de.jeanlucmakiola.clockula.domain.screensaver.ScreenSaverSettings
import de.jeanlucmakiola.clockula.domain.widget.QuickTimerWidgetSettings
@@ -65,9 +66,13 @@ data class BackupSettings(
val timerPresets: List<Duration>,
/** The world clock's "Display time with seconds" (#23). */
val worldClockSeconds: Boolean,
/** The world clock's "Compact home clock" (#29). */
val compactHomeClock: Boolean = false,
val screenSaver: ScreenSaverSettings,
/** What the quick-timer Quick Settings tile starts (#26). */
val quickTileDuration: Duration = QuickTimerWidgetSettings.DEFAULT,
/** The first day of the week (#30). */
val weekStart: WeekStartPref = WeekStartPref.Auto,
/** Null for a file written before bedtime existed: restoring it keeps the current schedule. */
val bedtime: BedtimeSettings? = null,
)
@@ -45,13 +45,3 @@ object RingFallbackPolicy {
fun vibrationRequired(audioAvailable: Boolean, vibrateSetting: Boolean): Boolean =
vibrateSetting || !audioAvailable
}
/** Long buzz, short gap, long buzz, longer gap — loudly rhythmic, not a doorbell. */
object VibrationPattern {
val TIMINGS: LongArray = longArrayOf(500L, 250L, 500L, 1_000L)
val AMPLITUDES: IntArray = intArrayOf(255, 0, 255, 0)
/** The index the pattern loops from: 0, so the whole pattern repeats. */
const val REPEAT_INDEX: Int = 0
}
@@ -85,7 +85,7 @@ object MediaRingPolicy {
return ceil(fraction * musicMax).toInt().coerceIn(1, musicMax)
}
/** The index for a ramp [level] (`RingAudio.MIN_VOLUME`..1) on the way to [target]. */
/** The index for a ramp [level] (`VolumeRamp.MIN_LEVEL`..1) on the way to [target]. */
fun mediaVolumeIndex(level: Float, target: Int): Int {
if (target <= 0) return 0
return (level.coerceIn(0f, 1f) * target).roundToInt().coerceIn(1, target)
@@ -1,17 +0,0 @@
package de.jeanlucmakiola.clockula.domain.ring
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
/**
* The audio chain's constants, shared by both ring paths. They moved out of
* `AlarmRing` when the timer's ring started using the same player: a constant
* named for one caller reads as that caller's private business (slice plan D8).
*/
object RingAudio {
/** How often a ringing service steps the volume ramp. */
val RAMP_TICK: Duration = 200.milliseconds
/** The ramp's floor — a ramping ring never starts at true silence. */
const val MIN_VOLUME: Float = 0.05f
}
@@ -1,19 +0,0 @@
package de.jeanlucmakiola.clockula.domain.ring
import kotlin.time.Duration
/**
* Quadratic in amplitude is roughly linear in perceived loudness, so the ramp
* sounds like a steady climb rather than a jump at the end.
*/
object VolumeRamp {
/** `RingAudio.MIN_VOLUME`..1f. Never throws. */
fun levelAt(elapsed: Duration, ramp: Duration): Float {
if (ramp <= Duration.ZERO || elapsed >= ramp) return 1f
if (elapsed <= Duration.ZERO) return RingAudio.MIN_VOLUME
val progress = (elapsed / ramp).toFloat()
val level = RingAudio.MIN_VOLUME + (1f - RingAudio.MIN_VOLUME) * progress * progress
return level.coerceIn(RingAudio.MIN_VOLUME, 1f)
}
}
@@ -5,12 +5,12 @@ import android.app.Application
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import de.jeanlucmakiola.clockula.domain.alarm.DirectLaunchFacts
import de.jeanlucmakiola.clockula.domain.alarm.DirectLaunchPolicy
import de.jeanlucmakiola.floret.ring.isInCall
/**
* Opens a ring screen directly where a full-screen intent would only show a
@@ -66,7 +66,7 @@ object ForegroundRingScreen {
screenShowing = screenShowing,
overOtherApps = overOtherApps,
canDrawOverlays = Settings.canDrawOverlays(context),
inCall = inCall(context),
inCall = context.isInCall(),
)
if (!DirectLaunchPolicy.opensDirectly(facts)) return
// A refused start costs nothing: the notification is up either way.
@@ -80,11 +80,4 @@ object ForegroundRingScreen {
private fun phoneInUse(context: Context): Boolean =
context.getSystemService(PowerManager::class.java).isInteractive &&
!context.getSystemService(KeyguardManager::class.java).isKeyguardLocked
/** The audio mode, which needs no phone permission, unlike the telecom APIs. */
private fun inCall(context: Context): Boolean =
when (context.getSystemService(AudioManager::class.java).mode) {
AudioManager.MODE_IN_CALL, AudioManager.MODE_IN_COMMUNICATION, AudioManager.MODE_RINGTONE -> true
else -> false
}
}
@@ -1,28 +0,0 @@
package de.jeanlucmakiola.clockula.ring
import android.content.Context
import android.os.PowerManager
/**
* Keeps the CPU awake across the gap between an AlarmManager broadcast and the
* service it starts. The platform's own wake lock ends with the receiver, and
* the service takes its own only after a database read, so without this a
* dozing device can suspend in between and ring minutes late.
*
* Timed rather than released: the service holds its own lock well before the
* timeout, and a lock that outlives a crashed hand-off cannot leak.
*/
object HandoffWakeLock {
private const val TIMEOUT_MILLIS = 30_000L
fun acquire(context: Context, tag: String) {
val power = context.getSystemService(PowerManager::class.java) ?: return
runCatching {
power.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag).apply {
setReferenceCounted(false)
acquire(TIMEOUT_MILLIS)
}
}
}
}
@@ -1,35 +1,28 @@
package de.jeanlucmakiola.clockula.ring
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioFocusRequest
import android.media.AudioManager
import android.media.MediaPlayer
import android.media.RingtoneManager
import android.net.Uri
import de.jeanlucmakiola.clockula.data.ringtones.BundledTones
import de.jeanlucmakiola.clockula.domain.MediaSources
import de.jeanlucmakiola.clockula.domain.ring.AudioSourcePolicy
import de.jeanlucmakiola.clockula.domain.ring.MediaRingPolicy
import de.jeanlucmakiola.clockula.domain.ring.RingAudio
import de.jeanlucmakiola.clockula.domain.ring.RingtoneSourceKind
import de.jeanlucmakiola.clockula.domain.ring.VolumeRamp
import de.jeanlucmakiola.floret.ring.TonePlayer
import de.jeanlucmakiola.floret.ring.VolumeRamp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
/**
* `MediaPlayer` over `USAGE_ALARM`, plus the ramp loop. The ramp is stepped into
* [MediaPlayer.setVolume] and **never** into `AudioManager.setStreamVolume`,
* which would edit the user's own alarm volume and leave it edited. (A ring
* another app plays is the one exception — see [MediaAppRing].)
* floret-kit's [TonePlayer] over the ringing thing's sources, plus a ring
* another app plays ([MediaAppRing]) in front of it. The ramp never edits the
* user's own alarm volume; a ring another app plays is the one exception.
*
* [start] does not wait for the sound: opening one can take seconds when
* another app plays it, and the caller has a notification to post and a
@@ -39,18 +32,10 @@ import kotlin.time.Duration.Companion.seconds
*/
class RingAudioPlayer(private val context: Context) {
private val audioManager: AudioManager = context.getSystemService(AudioManager::class.java)
private val tones = TonePlayer(context)
private val routes by lazy { MediaRouteCheck(context) }
private val attributes: AudioAttributes = AudioAttributes.Builder()
// USAGE_ALARM is what makes Do Not Disturb's alarm exemption apply.
.setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
private var player: MediaPlayer? = null
private var focusRequest: AudioFocusRequest? = null
private var ramp: Job? = null
/** Set while another app plays the ring ([MediaAppRing]). */
@@ -59,8 +44,10 @@ class RingAudioPlayer(private val context: Context) {
/**
* Which ring is live. [start] and [stop] both move it on, so work a ring
* left in flight — a `prepare`, a music app that answers late — sees it is
* no longer wanted and releases what it opened rather than starting it.
* left in flight — a music app that answers late — sees it is no longer
* wanted and releases what it opened rather than starting it. A `prepare`
* in flight is [TonePlayer]'s, guarded by its own counter, which [stop]
* moves on too.
*/
private var generation: Int = 0
@@ -104,9 +91,7 @@ class RingAudioPlayer(private val context: Context) {
ramp = null
mediaRing?.stop()
mediaRing = null
player?.let(::release)
player = null
abandonFocus()
tones.stop()
}
/** False when there is no media source, or it would not be heard, or the app would not play. */
@@ -143,12 +128,8 @@ class RingAudioPlayer(private val context: Context) {
}
/**
* Prepares on IO, because [MediaPlayer.prepare] is blocking I/O and the
* moment the alarm rings is the worst possible moment to block the main
* thread with it.
*
* A player that errors once it is playing (the media server died, the file
* went away) hands the ring to the sources after its own, unramped, and to
* The ordinary chain, through [TonePlayer]: a player that errors once it is
* playing hands the ring to the sources after its own, unramped, and to
* [onSilenced] when none is left — a ring never goes quiet mid-alarm.
*/
private suspend fun startPlayer(
@@ -158,47 +139,9 @@ class RingAudioPlayer(private val context: Context) {
rampFor: Duration,
rampStart: Duration,
onSilenced: () -> Unit,
from: Int = 0,
): Boolean {
if (ring != generation) return false
for ((index, uri) in sources(ringtoneUri).withIndex()) {
if (index < from) continue
val prepared = withContext(Dispatchers.IO) { prepare(uri) } ?: continue
// Stopped while preparing: never start an obsolete ring.
if (ring != generation) {
release(prepared)
return false
}
requestFocus()
val initial = VolumeRamp.levelAt(rampStart, rampFor)
val started = runCatching {
prepared.setVolume(initial, initial)
prepared.start()
}.isSuccess
if (!started) {
release(prepared)
abandonFocus()
continue
}
player = prepared
prepared.setOnErrorListener { failed, _, _ ->
if (player === failed && ring == generation) {
ramp?.cancel()
ramp = null
player = null
release(failed)
abandonFocus()
scope.launch {
val next = startPlayer(ring, scope, ringtoneUri, Duration.ZERO, Duration.ZERO, onSilenced, index + 1)
if (!next && ring == generation) onSilenced()
}
}
true
}
ramp = launchRamp(scope, rampFor, rampStart) { level -> runCatching { player?.setVolume(level, level) } }
return true
}
return false
return tones.play(scope, sources(ringtoneUri), rampFor, rampStart, onSilenced)
}
/**
@@ -218,7 +161,7 @@ class RingAudioPlayer(private val context: Context) {
onSilenced: () -> Unit,
) {
media.setLevel(VolumeRamp.levelAt(rampStart, rampFor))
ramp = launchRamp(scope, rampFor, rampStart, media::setLevel)
ramp = VolumeRamp.launch(scope, rampFor, rampStart, media::setLevel)
watchdog = scope.launch {
var stall = MediaRingPolicy.Stall()
while (isActive && ring == generation) {
@@ -235,22 +178,6 @@ class RingAudioPlayer(private val context: Context) {
}
}
/** Steps [setLevel] along [VolumeRamp] every [RingAudio.RAMP_TICK] from [from] until [rampFor] has passed. */
private fun launchRamp(
scope: CoroutineScope,
rampFor: Duration,
from: Duration,
setLevel: (Float) -> Unit,
): Job =
scope.launch {
var elapsed = from
while (isActive && elapsed < rampFor) {
delay(RingAudio.RAMP_TICK)
elapsed += RingAudio.RAMP_TICK
setLevel(VolumeRamp.levelAt(elapsed, rampFor))
}
}
/**
* The order is [AudioSourcePolicy]'s, so the decision — including the silent
* sentinel's empty list, which is what forces vibration (M5 D18) — lives in
@@ -268,42 +195,4 @@ class RingAudioPlayer(private val context: Context) {
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
}
}
/**
* A prepared, not-yet-started player, or null. A source that throws has its
* player released here: one leaked [MediaPlayer] per unusable fallback is
* still a leak, and there are three fallbacks.
*/
private fun prepare(uri: Uri): MediaPlayer? {
val candidate = MediaPlayer()
return runCatching {
candidate.setAudioAttributes(attributes)
candidate.setDataSource(context, uri)
candidate.isLooping = true
candidate.prepare()
candidate
}.getOrElse {
release(candidate)
null
}
}
private fun release(player: MediaPlayer) {
runCatching { player.stop() }
runCatching { player.release() }
}
/** GAIN_TRANSIENT: an alarm interrupts what is playing; it does not duck it. */
private fun requestFocus() {
val request = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
.setAudioAttributes(attributes)
.build()
focusRequest = request
runCatching { audioManager.requestAudioFocus(request) }
}
private fun abandonFocus() {
focusRequest?.let { runCatching { audioManager.abandonAudioFocusRequest(it) } }
focusRequest = null
}
}
@@ -1,46 +0,0 @@
package de.jeanlucmakiola.clockula.ring
import android.content.Context
import android.media.AudioAttributes
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import android.os.VibratorManager
import de.jeanlucmakiola.clockula.domain.ring.VibrationPattern
/**
* The waveform, looped, with `USAGE_ALARM` attributes so Do Not Disturb treats
* it the way it treats the sound. Shared by the alarm's ring and the timer's. `minSdk` is 29, so `VibratorManager` (API 31+)
* is guarded and the older accessor stands in below it.
*/
class RingVibrator(private val context: Context) {
private val attributes: AudioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
private val vibrator: Vibrator? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
context.getSystemService(VibratorManager::class.java)?.defaultVibrator
} else {
@Suppress("DEPRECATION")
context.getSystemService(Vibrator::class.java)
}
fun start() {
val device = vibrator?.takeIf { it.hasVibrator() } ?: return
val effect = VibrationEffect.createWaveform(
VibrationPattern.TIMINGS,
VibrationPattern.AMPLITUDES,
VibrationPattern.REPEAT_INDEX,
)
runCatching {
@Suppress("DEPRECATION")
device.vibrate(effect, attributes)
}
}
fun stop() {
runCatching { vibrator?.cancel() }
}
}
@@ -4,9 +4,9 @@ import android.content.Context
import android.content.Intent
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.alarm.receiver.HiltBroadcastReceiver
import de.jeanlucmakiola.clockula.ring.HandoffWakeLock
import de.jeanlucmakiola.clockula.timer.TimerEngine
import de.jeanlucmakiola.floret.di.ApplicationScope
import de.jeanlucmakiola.floret.ring.RingWakeLock
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import javax.inject.Inject
@@ -29,7 +29,7 @@ class TimerExpiryReceiver : HiltBroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
HandoffWakeLock.acquire(context, "clockula:timer-expiry")
RingWakeLock.handOff(context, "clockula:timer-expiry")
val pendingResult = goAsync()
scope.launch {
try {
@@ -4,10 +4,7 @@ import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import android.os.PowerManager
import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.alarm.AlarmCapabilities
@@ -22,12 +19,14 @@ import de.jeanlucmakiola.clockula.domain.timer.TimerRingDecision
import de.jeanlucmakiola.clockula.domain.timer.TimerSettings
import de.jeanlucmakiola.clockula.ring.ForegroundRingScreen
import de.jeanlucmakiola.clockula.ring.RingAudioPlayer
import de.jeanlucmakiola.clockula.ring.RingVibrator
import de.jeanlucmakiola.clockula.timer.AlarmRingStatus
import de.jeanlucmakiola.clockula.timer.TimerEngine
import de.jeanlucmakiola.clockula.timer.TimerIntents
import de.jeanlucmakiola.clockula.timer.TimerServiceState
import de.jeanlucmakiola.clockula.ui.ring.TimerRingActivity
import de.jeanlucmakiola.floret.ring.RingVibrator
import de.jeanlucmakiola.floret.ring.RingWakeLock
import de.jeanlucmakiola.floret.ring.startRingForeground
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -87,7 +86,7 @@ class TimerService : Service() {
private val audio by lazy { RingAudioPlayer(this) }
private val vibrator by lazy { RingVibrator(this) }
private var wakeLock: PowerManager.WakeLock? = null
private val wakeLock by lazy { RingWakeLock(this, WAKE_LOCK_TAG, WAKE_LOCK_TIMEOUT_MILLIS) }
private var collector: Job? = null
/** The two independent delays the engine hands down (D20). */
@@ -245,7 +244,7 @@ class TimerService : Service() {
releaseRing()
sounding = decision.subjectId
soundingSettings = decision.settings
acquireWakeLock()
wakeLock.acquire()
// Vibration first, and the sound without waiting for it: a sound
// another app plays can take seconds to open, and this runs
// inside the collector that posts the notification and its Stop.
@@ -331,38 +330,19 @@ class TimerService : Service() {
}
private fun startForeground(notification: Notification) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// systemExempted, the same type and justification as the alarm's
// ringing service: an app holding an exact-alarm permission,
// continuing an alarm-shaped event in the background (D6).
startForeground(
notificationId,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED,
)
} else {
startForeground(notificationId, notification)
}
// systemExempted, the same type and justification as the alarm's
// ringing service (D6).
startRingForeground(notificationId, notification)
wentForeground = true
}
private fun acquireWakeLock() {
if (wakeLock != null) return
val power = getSystemService(PowerManager::class.java)
wakeLock = power.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply {
setReferenceCounted(false)
runCatching { acquire(WAKE_LOCK_TIMEOUT_MILLIS) }
}
}
/** The whole ring released, not just the audio: an orphaned looping player cannot be stopped. */
private fun releaseRing() {
sounding = null
soundingSettings = null
audio.stop()
vibrator.stop()
wakeLock?.let { if (it.isHeld) runCatching { it.release() } }
wakeLock = null
wakeLock.release()
}
private fun stop() {
@@ -16,10 +16,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
@@ -41,13 +39,12 @@ import de.jeanlucmakiola.clockula.domain.RepeatSummary
import de.jeanlucmakiola.clockula.domain.format.NextFireLabel
import de.jeanlucmakiola.clockula.ui.common.SwipeToDelete
import de.jeanlucmakiola.clockula.ui.common.rememberAlarmTimeFormatter
import de.jeanlucmakiola.clockula.ui.common.rememberLocale
import de.jeanlucmakiola.clockula.ui.common.rememberWeekStart
import de.jeanlucmakiola.floret.components.GroupedListInset
import de.jeanlucmakiola.floret.components.GroupedSurface
import de.jeanlucmakiola.floret.components.Position
import java.time.DayOfWeek
import java.time.format.TextStyle
import java.time.temporal.WeekFields
import java.util.Locale
/**
* A standalone alarm card. The time and switch share the first line, leaving
@@ -267,18 +264,3 @@ internal fun repeatSummaryText(repeatDays: RepeatDays): String {
}
}
}
/** The locale's own first day of week, re-read with the configuration. */
@Composable
internal fun rememberWeekStart(): DayOfWeek {
val locale = rememberLocale()
return remember(locale) { WeekFields.of(locale).firstDayOfWeek }
}
@Composable
private fun rememberLocale(): Locale {
// Keyed on the configuration, so a language change re-reads both the
// locale's day names and where its week begins.
val configuration = LocalConfiguration.current
return remember(configuration) { Locale.getDefault() }
}
@@ -8,26 +8,25 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Text
import androidx.compose.material3.ToggleButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.RepeatDaysOrder
import de.jeanlucmakiola.clockula.ui.common.rememberLocale
import de.jeanlucmakiola.clockula.ui.common.rememberWeekStart
import de.jeanlucmakiola.floret.components.GroupedListInset
import de.jeanlucmakiola.floret.components.GroupedSurface
import de.jeanlucmakiola.floret.components.Position
import java.time.DayOfWeek
import java.time.format.TextStyle
import java.util.Locale
/**
* Seven equal toggle buttons in one row — the Expressive round↔squircle morph
* on check is the shape play a genuinely clock-specific control earns (M5 D28).
*
* The columns start on the locale's own first day of week, and each button
* The columns start on the week's first day ([rememberWeekStart]), and each button
* carries the day's full name as its content description: "M T W T F S S" is
* not something a screen reader can disambiguate.
*/
@@ -39,8 +38,7 @@ internal fun RepeatDaySelector(
modifier: Modifier = Modifier,
position: Position = Position.Alone,
) {
val configuration = LocalConfiguration.current
val locale = remember(configuration) { Locale.getDefault() }
val locale = rememberLocale()
val days = RepeatDaysOrder.startingAt(rememberWeekStart())
GroupedSurface(
@@ -0,0 +1,37 @@
package de.jeanlucmakiola.clockula.ui.common
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalConfiguration
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.resolveFirstDay
import java.time.DayOfWeek
import java.util.Locale
/**
* The stored "Week starts on" choice (#30), provided once by `MainActivity` for
* every screen that lays out a week. Auto outside it, as in a preview.
*/
internal val LocalWeekStart: ProvidableCompositionLocal<WeekStartPref> =
compositionLocalOf { WeekStartPref.Auto }
/** The chosen first day of week, or the locale's own, re-read with the configuration. */
@Composable
internal fun rememberWeekStart(): DayOfWeek {
val locale = rememberLocale()
val weekStart = LocalWeekStart.current
return remember(locale, weekStart) { weekStart.resolveFirstDay(locale) }
}
/**
* The locale day names and the week's first day are read in. Keyed on the
* configuration, so a language change re-reads both; shared, so the repeat-day
* buttons, the alarm summaries and the week-start picker never disagree.
*/
@Composable
internal fun rememberLocale(): Locale {
val configuration = LocalConfiguration.current
return remember(configuration) { Locale.getDefault() }
}
@@ -2,7 +2,6 @@ package de.jeanlucmakiola.clockula.ui.ring
import android.os.Bundle
import android.view.KeyEvent
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
@@ -17,6 +16,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.domain.alarm.VolumeKeyEffect
import de.jeanlucmakiola.clockula.ui.theme.ClockulaTheme
import de.jeanlucmakiola.floret.ring.showOverLockScreen
/**
* The window a firing alarm gets: over the lock screen, with the display turned
@@ -39,6 +39,8 @@ class AlarmRingActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// An alarm the user has to unlock to silence is not an alarm. Keeping
// the screen on is scoped to this window, so it cannot outlive the ring.
showOverLockScreen()
setContent {
@@ -106,21 +108,6 @@ class AlarmRingActivity : ComponentActivity() {
return true
}
/**
* Shown over the lock screen with the display turned on: an alarm the user
* has to unlock to silence is not an alarm. `minSdk` is 29, so the
* pre-API-27 window flags are not needed.
*
* `FLAG_KEEP_SCREEN_ON` is the "wake lock for the ring duration only" that
* docs/PLAN.md §4 asks for — scoped to this window's life, so unlike a
* `PowerManager.WakeLock` it cannot be leaked past the alarm.
*/
private fun showOverLockScreen() {
setShowWhenLocked(true)
setTurnScreenOn(true)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
private companion object {
val VOLUME_KEYS = setOf(
KeyEvent.KEYCODE_VOLUME_UP,
@@ -1,35 +1,23 @@
package de.jeanlucmakiola.clockula.ui.ring
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Alarm
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
@@ -37,7 +25,7 @@ import de.jeanlucmakiola.clockula.R
import de.jeanlucmakiola.clockula.ui.common.rememberAlarmTimeFormatter
import de.jeanlucmakiola.floret.identity.collapseExit
import de.jeanlucmakiola.floret.identity.expandEnter
import de.jeanlucmakiola.floret.identity.rememberReduceMotion
import de.jeanlucmakiola.floret.ring.RingBadge
/**
* The ring screen itself: the time, the label, snooze, and the dismiss
@@ -68,7 +56,7 @@ internal fun RingScreen(
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
RingingBadge()
RingBadge(icon = Icons.Rounded.Alarm)
Text(
text = formatTime(state.time),
style = MaterialTheme.typography.displayLarge,
@@ -140,35 +128,6 @@ internal fun RingScreen(
}
}
/** One pulsing circular badge — the screen's only motion flourish. */
@Composable
private fun RingingBadge() {
val reduceMotion = rememberReduceMotion()
val pulse = rememberInfiniteTransition(label = "ring-pulse")
val scale by pulse.animateFloat(
initialValue = 1f,
targetValue = if (reduceMotion) 1f else 1.08f,
animationSpec = infiniteRepeatable(tween(900), RepeatMode.Reverse),
label = "ring-pulse-scale",
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(96.dp)
.scale(scale)
.background(MaterialTheme.colorScheme.primaryContainer, CircleShape),
) {
Icon(
imageVector = Icons.Rounded.Alarm,
// The time and the label below say what this is; the badge is the
// same sentence in a circle.
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.size(48.dp),
)
}
}
private fun ChallengeUiState.escapeAvailable(): Boolean = when (this) {
ChallengeUiState.Direct -> false
is ChallengeUiState.Math -> escapeAvailable
@@ -1,7 +1,6 @@
package de.jeanlucmakiola.clockula.ui.ring
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
@@ -15,6 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dagger.hilt.android.AndroidEntryPoint
import de.jeanlucmakiola.clockula.ui.theme.ClockulaTheme
import de.jeanlucmakiola.floret.ring.showOverLockScreen
/**
* The window an expired timer gets, opened by the timer notification's
@@ -34,9 +34,7 @@ class TimerRingActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
// As AlarmRingActivity: shown over the lock screen, display on, and
// kept on for this window's life only.
setShowWhenLocked(true)
setTurnScreenOn(true)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
showOverLockScreen()
setContent {
ClockulaTheme {
@@ -1,39 +1,27 @@
package de.jeanlucmakiola.clockula.ui.ring
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Timer
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import de.jeanlucmakiola.clockula.R
import de.jeanlucmakiola.floret.identity.rememberReduceMotion
import de.jeanlucmakiola.floret.ring.RingBadge
/**
* The timer ring screen: the label, "Finished", and the notification's two
@@ -53,7 +41,7 @@ internal fun TimerRingScreen(
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
TimerBadge()
RingBadge(icon = Icons.Rounded.Timer)
Text(
text = stringResource(R.string.timer_finished),
style = MaterialTheme.typography.displayMedium,
@@ -83,30 +71,3 @@ internal fun TimerRingScreen(
}
}
}
/** The alarm screen's pulsing badge, with the timer's icon. */
@Composable
private fun TimerBadge() {
val reduceMotion = rememberReduceMotion()
val pulse = rememberInfiniteTransition(label = "timer-ring-pulse")
val scale by pulse.animateFloat(
initialValue = 1f,
targetValue = if (reduceMotion) 1f else 1.08f,
animationSpec = infiniteRepeatable(tween(900), RepeatMode.Reverse),
label = "timer-ring-pulse-scale",
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(96.dp)
.scale(scale)
.background(MaterialTheme.colorScheme.primaryContainer, CircleShape),
) {
Icon(
imageVector = Icons.Rounded.Timer,
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.size(48.dp),
)
}
}
@@ -49,11 +49,17 @@ internal fun AlarmDefaultsScreen(
state: SettingsUiState.Loaded,
viewModel: SettingsViewModel,
onBack: () -> Unit,
visible: Boolean,
) {
val defaults = state.defaults
var openPicker by rememberSaveable { mutableStateOf<OpenAlarmPicker?>(null) }
CollapsingScaffold(title = stringResource(R.string.settings_section_alarms), onBack = onBack) {
CollapsingScaffold(
title = stringResource(R.string.settings_section_alarms),
onBack = onBack,
predictiveBack = true,
visible = visible,
) {
SettingsHint(stringResource(R.string.settings_alarm_defaults_hint))
Spacer(Modifier.height(8.dp))
@@ -53,13 +53,19 @@ internal fun AppearanceScreen(
state: SettingsUiState.Loaded,
viewModel: SettingsViewModel,
onBack: () -> Unit,
visible: Boolean,
) {
val dynamicColorAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
var showTheme by rememberSaveable { mutableStateOf(false) }
var showAppIcon by rememberSaveable { mutableStateOf(false) }
val launcherIcon by viewModel.launcherIcon.collectAsStateWithLifecycle()
CollapsingScaffold(title = stringResource(R.string.settings_section_appearance), onBack = onBack) {
CollapsingScaffold(
title = stringResource(R.string.settings_section_appearance),
onBack = onBack,
predictiveBack = true,
visible = visible,
) {
GroupedRow(
title = stringResource(R.string.settings_theme),
summary = themeModeLabel(state.appearance.themeMode),
@@ -4,6 +4,10 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Switch
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
@@ -14,18 +18,28 @@ import de.jeanlucmakiola.floret.components.GroupedRow
import de.jeanlucmakiola.floret.components.Position
/**
* The clock tab's settings: the home zone, whether the tab shows seconds and
* the automatic local clock. Then the screen saver's: it is a clock face, and
* the settings Android's own screen saver screen opens are the same rows.
* The zone picker itself is ViewModel state, drawn by the hub.
* The clock tab's settings: the home zone, whether home is a face or a row,
* whether the tab shows seconds and the automatic local clock. Then the day the
* week starts on, which, like the home zone, is a matter of where you live
* (#30). Then the screen saver's: it is a clock face, and the settings Android's
* own screen saver screen opens are the same rows. The zone picker itself is
* ViewModel state, drawn by the hub.
*/
@Composable
internal fun ClockSettingsScreen(
state: SettingsUiState.Loaded,
viewModel: SettingsViewModel,
onBack: () -> Unit,
visible: Boolean,
) {
CollapsingScaffold(title = stringResource(R.string.settings_section_clock), onBack = onBack) {
var showWeekStart by rememberSaveable { mutableStateOf(false) }
CollapsingScaffold(
title = stringResource(R.string.settings_section_clock),
onBack = onBack,
predictiveBack = true,
visible = visible,
) {
SettingsHint(stringResource(R.string.settings_clock_hint))
Spacer(Modifier.height(8.dp))
@@ -35,6 +49,18 @@ internal fun ClockSettingsScreen(
position = Position.Top,
onClick = viewModel::onOpenHomeZonePicker,
)
GroupedRow(
title = stringResource(R.string.settings_compact_home_clock),
summary = stringResource(R.string.settings_compact_home_clock_hint),
position = Position.Middle,
trailing = {
Switch(
checked = state.compactHomeClock,
onCheckedChange = viewModel::onCompactHomeClockChanged,
)
},
onClick = { viewModel.onCompactHomeClockChanged(!state.compactHomeClock) },
)
GroupedRow(
title = stringResource(R.string.settings_world_clock_seconds),
summary = stringResource(R.string.settings_world_clock_seconds_hint),
@@ -72,6 +98,22 @@ internal fun ClockSettingsScreen(
onClick = { viewModel.onAutomaticLocalClockChanged(!automaticLocalClock) },
)
Spacer(Modifier.height(24.dp))
GroupedRow(
title = stringResource(R.string.settings_week_start),
summary = weekStartSummary(state.weekStart),
position = Position.Alone,
onClick = { showWeekStart = true },
)
ScreenSaverSettingsSection(inApp = true)
}
if (showWeekStart) {
WeekStartPicker(
selected = state.weekStart,
onSelect = viewModel::onWeekStartChanged,
onDismiss = { showWeekStart = false },
)
}
}
@@ -33,6 +33,7 @@ import de.jeanlucmakiola.floret.components.CollapsingScaffold
import de.jeanlucmakiola.floret.components.GroupedRow
import de.jeanlucmakiola.floret.components.Position
import de.jeanlucmakiola.floret.components.positionOf
import de.jeanlucmakiola.floret.ring.openFullScreenIntentSettings
/**
* The "why might my alarm not ring?" screen (`docs/PLAN.md` §4): one row per
@@ -145,8 +146,10 @@ private fun launchFix(context: Context, fix: SelfCheckFix) {
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
.putExtra(Settings.EXTRA_CHANNEL_ID, RingNotifications.RING_CHANNEL_ID)
SelfCheckFix.OpenFullScreenIntentSettings ->
Intent(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT, Uri.parse("package:${context.packageName}"))
SelfCheckFix.OpenFullScreenIntentSettings -> {
context.openFullScreenIntentSettings()
return
}
SelfCheckFix.OpenBatteryOptimizationSettings ->
Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
SelfCheckFix.OpenAppDetailsSettings ->
@@ -1,13 +1,10 @@
package de.jeanlucmakiola.clockula.ui.settings
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
@@ -28,6 +25,7 @@ import androidx.compose.material.icons.filled.PrivacyTip
import androidx.compose.material.icons.filled.Public
import androidx.compose.material.icons.filled.Timer
import androidx.compose.material.icons.filled.Translate
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
@@ -38,6 +36,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
@@ -63,6 +62,8 @@ import de.jeanlucmakiola.floret.crash.CrashReportDialog
import de.jeanlucmakiola.floret.crash.CrashReporter
import de.jeanlucmakiola.floret.crash.openIssueTracker
import de.jeanlucmakiola.floret.crash.submitCrashReport
import de.jeanlucmakiola.floret.identity.predictiveBackExit
import de.jeanlucmakiola.floret.identity.rememberReduceMotion
/** The settings sub-screens reached from the hub's category rows. */
private enum class SettingsSection { Appearance, Alarms, Timers, Clock }
@@ -114,10 +115,6 @@ fun SettingsScreen(
val loaded = state as? SettingsUiState.Loaded
// Inside a sub-screen, system back (button or gesture) returns to the hub
// rather than popping the whole Settings destination.
BackHandler(enabled = section != null) { section = null }
Box(
modifier = modifier
.fillMaxSize()
@@ -133,17 +130,21 @@ fun SettingsScreen(
)
if (loaded != null) {
SlideInSection(visible = section == SettingsSection.Appearance) {
AppearanceScreen(state = loaded, viewModel = viewModel, onBack = { section = null })
val appearanceOpen = section == SettingsSection.Appearance
SlideInSection(visible = appearanceOpen) {
AppearanceScreen(state = loaded, viewModel = viewModel, onBack = { section = null }, visible = appearanceOpen)
}
SlideInSection(visible = section == SettingsSection.Alarms) {
AlarmDefaultsScreen(state = loaded, viewModel = viewModel, onBack = { section = null })
val alarmsOpen = section == SettingsSection.Alarms
SlideInSection(visible = alarmsOpen) {
AlarmDefaultsScreen(state = loaded, viewModel = viewModel, onBack = { section = null }, visible = alarmsOpen)
}
SlideInSection(visible = section == SettingsSection.Timers) {
TimerDefaultsScreen(state = loaded, viewModel = viewModel, onBack = { section = null })
val timersOpen = section == SettingsSection.Timers
SlideInSection(visible = timersOpen) {
TimerDefaultsScreen(state = loaded, viewModel = viewModel, onBack = { section = null }, visible = timersOpen)
}
SlideInSection(visible = section == SettingsSection.Clock) {
ClockSettingsScreen(state = loaded, viewModel = viewModel, onBack = { section = null })
val clockOpen = section == SettingsSection.Clock
SlideInSection(visible = clockOpen) {
ClockSettingsScreen(state = loaded, viewModel = viewModel, onBack = { section = null }, visible = clockOpen)
}
}
}
@@ -172,12 +173,22 @@ fun SettingsScreen(
}
}
/**
* A sub-screen layered over the hub, with Calendula's overlay motion: it slides
* in on the motion scheme's spring and leaves from its predictive-back preview.
* Inside it, back (button or gesture) returns to the hub rather than popping
* the whole Settings destination; the sub-screen's scaffold takes it.
*/
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
private fun SlideInSection(visible: Boolean, content: @Composable () -> Unit) {
val slideSpec = MaterialTheme.motionScheme.defaultSpatialSpec<IntOffset>()
// Reduced motion fades it in, as predictiveBackExit already fades it out.
val enter = if (rememberReduceMotion()) fadeIn() else slideInHorizontally(slideSpec) { it } + fadeIn()
AnimatedVisibility(
visible = visible,
enter = slideInHorizontally { it } + fadeIn(),
exit = slideOutHorizontally { it } + fadeOut(),
enter = enter,
exit = predictiveBackExit(),
) { content() }
}
@@ -1,6 +1,7 @@
package de.jeanlucmakiola.clockula.ui.settings
import de.jeanlucmakiola.clockula.domain.ClockDefaults
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.floret.prefs.Appearance
/**
@@ -16,8 +17,12 @@ internal sealed interface SettingsUiState {
val selfCheckProblemCount: Int? = null,
/** The world clock's "Display time with seconds" (#23); not a clock default. */
val worldClockSeconds: Boolean,
/** The world clock's "Compact home clock" (#29); not a clock default either. */
val compactHomeClock: Boolean,
/** The stored choice; the screen pairs it with the overlay permission. */
val ringOverOtherApps: Boolean,
/** "Week starts on" (#30); not a clock default either. */
val weekStart: WeekStartPref,
) : SettingsUiState
}
@@ -14,6 +14,7 @@ import de.jeanlucmakiola.clockula.data.ringtones.RingtonePreviewer
import de.jeanlucmakiola.clockula.domain.ClockDefaults
import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.Ringtones
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.Zones
import de.jeanlucmakiola.clockula.domain.alarm.VolumeButtonAction
import de.jeanlucmakiola.clockula.domain.selfcheck.CheckStatus
@@ -72,10 +73,19 @@ class SettingsViewModel @Inject internal constructor(
settings.appearance,
settings.defaults,
selfCheckProblemCount,
settings.worldClockSeconds,
// Grouped, since `combine` stops at five typed flows.
combine(settings.worldClockSeconds, settings.compactHomeClock, settings.weekStart, ::Triple),
settings.ringOverOtherApps,
) { appearance, defaults, problemCount, worldClockSeconds, ringOverOtherApps ->
SettingsUiState.Loaded(appearance, defaults, problemCount, worldClockSeconds, ringOverOtherApps)
) { appearance, defaults, problemCount, (worldClockSeconds, compactHomeClock, weekStart), ringOverOtherApps ->
SettingsUiState.Loaded(
appearance = appearance,
defaults = defaults,
selfCheckProblemCount = problemCount,
worldClockSeconds = worldClockSeconds,
compactHomeClock = compactHomeClock,
ringOverOtherApps = ringOverOtherApps,
weekStart = weekStart,
)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(SUBSCRIPTION_GRACE_MS), SettingsUiState.Loading)
/**
@@ -254,6 +264,11 @@ class SettingsViewModel @Inject internal constructor(
fun onWorldClockSecondsChanged(enabled: Boolean) =
viewModelScope.launch { settings.setWorldClockSeconds(enabled) }
fun onWeekStartChanged(pref: WeekStartPref) = viewModelScope.launch { settings.setWeekStart(pref) }
fun onCompactHomeClockChanged(enabled: Boolean) =
viewModelScope.launch { settings.setCompactHomeClock(enabled) }
fun onRingOverOtherAppsChanged(enabled: Boolean) =
viewModelScope.launch { settings.setRingOverOtherApps(enabled) }
@@ -35,12 +35,18 @@ internal fun TimerDefaultsScreen(
state: SettingsUiState.Loaded,
viewModel: SettingsViewModel,
onBack: () -> Unit,
visible: Boolean,
) {
val defaults = state.defaults
var showRampPicker by rememberSaveable { mutableStateOf(false) }
var silenceAfterOpen by rememberSaveable { mutableStateOf(false) }
CollapsingScaffold(title = stringResource(R.string.settings_section_timers), onBack = onBack) {
CollapsingScaffold(
title = stringResource(R.string.settings_section_timers),
onBack = onBack,
predictiveBack = true,
visible = visible,
) {
SettingsHint(stringResource(R.string.settings_timer_defaults_hint))
Spacer(Modifier.height(8.dp))
@@ -0,0 +1,63 @@
package de.jeanlucmakiola.clockula.ui.settings
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import de.jeanlucmakiola.clockula.R
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.resolveFirstDay
import de.jeanlucmakiola.clockula.ui.common.rememberLocale
import de.jeanlucmakiola.floret.components.GroupedHint
import de.jeanlucmakiola.floret.components.OptionPicker
import java.time.format.TextStyle
/** A pinned day is the locale's own weekday name, so no per-day string is needed. */
@Composable
internal fun weekStartText(pref: WeekStartPref): String = when (pref) {
WeekStartPref.Auto -> stringResource(R.string.settings_week_start_auto)
is WeekStartPref.Day -> pref.day.getDisplayName(TextStyle.FULL, rememberLocale())
}
/** The row's summary: a pinned day, or "Automatic (Monday)" with the day it resolves to. */
@Composable
internal fun weekStartSummary(pref: WeekStartPref): String = when (pref) {
WeekStartPref.Auto -> stringResource(
R.string.settings_week_start_auto_row,
weekStartText(WeekStartPref.Day(pref.resolveFirstDay(rememberLocale()))),
)
is WeekStartPref.Day -> weekStartText(pref)
}
/**
* The week-start chooser (#30), after Calendula's but without its month-grid
* preview: Clockula has no grid to rearrange. "Automatic" carries the day it
* resolves to as its summary, read from the same locale the repeat-day
* buttons resolve it from, so the two never disagree.
*/
@Composable
internal fun WeekStartPicker(
selected: WeekStartPref,
onSelect: (WeekStartPref) -> Unit,
onDismiss: () -> Unit,
) {
val locale = rememberLocale()
OptionPicker(
title = stringResource(R.string.settings_week_start),
header = { GroupedHint(stringResource(R.string.settings_week_start_hint), verticalPadding = 8.dp) },
options = WeekStartPref.OPTIONS,
selected = selected,
label = { weekStartText(it) },
summary = { option ->
if (option == WeekStartPref.Auto) {
stringResource(
R.string.settings_week_start_auto_summary,
weekStartText(WeekStartPref.Day(option.resolveFirstDay(locale))),
)
} else {
null
}
},
onSelect = onSelect,
onDismiss = onDismiss,
)
}
@@ -12,8 +12,10 @@ import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteDefaults
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteItem
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldDefaults
@@ -77,10 +79,15 @@ import kotlin.math.sign
* state is saveable, so the tab survives rotation and process death with no
* mirror of ours to drift — and the `NavHost` holds only what is pushed over
* the tabs: the editors, the timer setup page, Settings.
*
* With [pureBlack] the bar sits on the black ground rather than on
* `surfaceContainer`, so the bottom of the screen is black down to the
* system navigation bar (#28).
*/
@Composable
fun ClockulaShell(
modifier: Modifier = Modifier,
pureBlack: Boolean = false,
openRequest: ShellRequest? = null,
onRequestConsumed: () -> Unit = {},
viewModel: ShellViewModel = hiltViewModel(),
@@ -192,6 +199,14 @@ fun ClockulaShell(
enabled = back is ShellBackAction.GoTo,
),
navigationSuiteType = navigationSuiteType,
navigationSuiteColors = if (pureBlack) {
NavigationSuiteDefaults.colors(
shortNavigationBarContainerColor = MaterialTheme.colorScheme.background,
navigationBarContainerColor = MaterialTheme.colorScheme.background,
)
} else {
NavigationSuiteDefaults.colors()
},
) {
Box(Modifier.fillMaxSize()) {
CompositionLocalProvider(
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.DragHandle
import androidx.compose.material.icons.rounded.Home
import androidx.compose.material.icons.rounded.NearMe
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
@@ -22,6 +23,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.pluralStringResource
@@ -227,16 +229,70 @@ internal fun LocalClockRow(
) {
// "Local time · 7 hours ahead": the label is what tells it apart from a
// saved city, so it leads the summary rather than hiding in a glyph.
val summary = stringResource(R.string.world_clock_summary, stringResource(R.string.world_clock_local), summaryFor(row))
val time = row.time?.let(formatTime)
// `LocalClock` only offers a zone the device lists, so the time is there;
// the fallback keeps TalkBack from reading an empty slot if that changes.
// Spoken to the minute, as a saved row is.
val spokenTime = row.time?.let(formatSpokenTime)
// the pinned row's fallback keeps TalkBack from reading an empty slot if
// that changes.
PinnedClockRow(
icon = Icons.Rounded.NearMe,
name = row.name,
summary = stringResource(R.string.world_clock_summary, stringResource(R.string.world_clock_local), summaryFor(row)),
time = row.time,
formatTime = formatTime,
formatSpokenTime = formatSpokenTime,
timeStyle = timeStyle,
modifier = modifier,
)
}
/**
* Home as a row, for the compact home clock (#29): drawn as the local row is,
* with a home glyph, and with home's long zone name in the summary where the
* face would caption it. Home is not stored in the list either, so it has
* nothing to move or remove.
*/
@Composable
internal fun HomeClockRow(
home: HomeFaceState,
formatTime: (LocalTime) -> String,
formatSpokenTime: (LocalTime) -> String,
timeStyle: RowTimeStyle,
modifier: Modifier = Modifier,
) {
val homeLabel = stringResource(R.string.world_clock_home)
PinnedClockRow(
icon = Icons.Rounded.Home,
name = home.city,
summary = home.zoneName?.let { stringResource(R.string.world_clock_summary, homeLabel, it) } ?: homeLabel,
time = home.time,
formatTime = formatTime,
formatSpokenTime = formatSpokenTime,
timeStyle = timeStyle,
modifier = modifier,
)
}
/**
* A row outside the reorderable column: a glyph where the drag handle would
* be, no actions, and a summary allowed two lines — a label is prepended to
* it, and on a phone the day ("Tomorrow") or the zone name is what an
* ellipsis would otherwise eat. Spoken to the minute, as a saved row is.
*/
@Composable
private fun PinnedClockRow(
icon: ImageVector,
name: String,
summary: String,
time: LocalTime?,
formatTime: (LocalTime) -> String,
formatSpokenTime: (LocalTime) -> String,
timeStyle: RowTimeStyle,
modifier: Modifier = Modifier,
) {
val spokenTime = time?.let(formatSpokenTime)
val description = if (spokenTime != null) {
stringResource(R.string.world_clock_row_description, row.name, spokenTime, summary)
stringResource(R.string.world_clock_row_description, name, spokenTime, summary)
} else {
stringResource(R.string.world_clock_row_description_unknown, row.name, summary)
stringResource(R.string.world_clock_row_description_unknown, name, summary)
}
GroupedSurface(
@@ -253,19 +309,17 @@ internal fun LocalClockRow(
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Rounded.NearMe,
imageVector = icon,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier.size(24.dp),
)
// Two lines, not one: "Local time · " is prepended, and on a phone
// the day ("Tomorrow") is what an ellipsis would otherwise eat.
RowText(name = row.name, summary = summary, time = time, timeStyle = timeStyle, summaryMaxLines = 2)
RowText(name = name, summary = summary, time = time?.let(formatTime), timeStyle = timeStyle, summaryMaxLines = 2)
}
}
}
/** The name over the summary, then the time: what a saved row and the local row share. */
/** The name over the summary, then the time: what a saved row and a pinned row share. */
@Composable
private fun RowScope.RowText(
name: String,
@@ -59,6 +59,8 @@ internal sealed interface WorldClockUiState {
* `WorldClocks.MAX`.
*/
val local: WorldClockRowState? = null,
/** Home drawn as a row like the cities' rather than the analog face (#29). */
val compactHome: Boolean = false,
) : WorldClockUiState
}
@@ -60,6 +60,10 @@ import java.time.LocalTime
* digits cannot: day or night at home, at a glance. The caption is where the
* ICU long zone name is shown, which is the one place it earns its length.
*
* The compact home clock (#29) trades the face for a row like the cities',
* for whoever wants the tab dense and digital throughout. The automatic local
* clock then sits under that row exactly as it sits under the face.
*
* `scrollable` stays true: `ReorderableColumn` is not lazy and cannot live
* inside a `LazyColumn`, and a list capped at twenty-four rows is exactly the
* shape it was written for (D12).
@@ -122,12 +126,23 @@ fun WorldClockScreen(
},
) {
if (loaded != null) {
HomeFace(
home = loaded.home,
showSeconds = loaded.showSeconds,
formatTime = formatTime,
formatSpokenTime = formatSpokenTime,
)
if (loaded.compactHome) {
HomeClockRow(
home = loaded.home,
formatTime = formatTime,
formatSpokenTime = formatSpokenTime,
timeStyle = rowTimeStyle,
modifier = Modifier.padding(top = 8.dp),
)
Spacer(Modifier.height(8.dp))
} else {
HomeFace(
home = loaded.home,
showSeconds = loaded.showSeconds,
formatTime = formatTime,
formatSpokenTime = formatSpokenTime,
)
}
// Above the saved cities and outside their column: it is not one
// of them, and a drag must not be able to land between the two.
@@ -82,6 +82,9 @@ internal class WorldClockSource @Inject constructor(
ticker.alignedTicks(WorldClockDefaults.tickFor(seconds))
.map { build(clocks, storedHome, localClock, seconds) }
}
// Outside the tick: how home is drawn changes nothing it computes,
// so flipping it neither restarts the ticker nor waits for it.
.combine(settings.compactHomeClock) { loaded, compact -> loaded.copy(compactHome = compact) }
.distinctUntilChanged()
/**
+8 -1
View File
@@ -357,14 +357,21 @@
<string name="settings_timer_defaults_hint">How timers ring. A timer can still pick its own sound in its editor.</string>
<string name="settings_timer_vibrate_off">Off. A timer set to Silent still vibrates</string>
<string name="settings_section_clock">Clock</string>
<string name="settings_clock_subtitle">Home time zone, seconds, local clock and screen saver</string>
<string name="settings_clock_subtitle">Home time zone and clock, seconds, local clock, week start and screen saver</string>
<string name="settings_clock_hint">World clocks show how far each city is from your home time zone.</string>
<string name="settings_home_zone">Home time zone</string>
<string name="settings_compact_home_clock">Compact home clock</string>
<string name="settings_compact_home_clock_hint">Show home as a row like the other cities, without the analog clock.</string>
<string name="settings_world_clock_seconds">Display time with seconds</string>
<string name="settings_world_clock_seconds_hint">The world clock shows seconds and a second hand. Uses a little more battery.</string>
<string name="settings_automatic_local_clock">Automatic local clock</string>
<string name="settings_automatic_local_clock_hint">While you’re somewhere the time differs from home, show the local time under the home clock.</string>
<string name="settings_automatic_local_clock_needs_home">Needs a home time zone. Home follows the device now, so it’s always local time.</string>
<string name="settings_week_start">Week starts on</string>
<string name="settings_week_start_auto">Automatic</string>
<string name="settings_week_start_auto_summary">Currently %1$s</string>
<string name="settings_week_start_auto_row">Automatic (%1$s)</string>
<string name="settings_week_start_hint">The day every week begins on, in alarms and bedtime.</string>
<string name="screen_saver_title">Screen saver</string>
<string name="screen_saver_style">Clock style</string>
<string name="screen_saver_style_digital">Digital</string>
@@ -214,7 +214,8 @@ class ArchitectureRulesTest {
/**
* M6 D31: "reuses M3's audio path" made mechanical. One `MediaPlayer`
* wrapper for both ring paths and one for the picker's preview; a third
* wrapper for both ring paths (floret-kit's `TonePlayer`, behind
* `ring/RingAudioPlayer`) and one for the picker's preview; a third
* audio path cannot be added without the build failing. The `/ring/` match
* covers the wrapper both before and after D8's package move.
*/
@@ -227,6 +228,16 @@ class ArchitectureRulesTest {
assertThat(offenders).isEmpty()
}
/** floret-kit's `TonePlayer` is that wrapper now, so only `RingAudioPlayer` may hold one. */
@Test
fun `TonePlayer lives only behind RingAudioPlayer`() {
val offenders = kotlinSources.containing("TonePlayer").filterNot {
it.endsWith("de/jeanlucmakiola/clockula/ring/RingAudioPlayer.kt")
}
assertThat(offenders).isEmpty()
}
/**
* M7 D19: the stopwatch is silent. It never opens audio, never vibrates and
* never takes a wake lock — which is the one thing a future "make the lap
@@ -241,6 +252,7 @@ class ArchitectureRulesTest {
"MediaPlayer",
"RingAudioPlayer",
"RingVibrator",
"TonePlayer",
"Vibrator",
"AudioManager",
// D3's "no wake lock, ever" is half of the promise this rule makes,
@@ -4,6 +4,7 @@ import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.TimeOfDay
import de.jeanlucmakiola.clockula.domain.TimerState
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.WorldClock
import de.jeanlucmakiola.clockula.domain.backup.BackupAlarm
import de.jeanlucmakiola.clockula.testing.BERLIN
@@ -19,6 +20,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.nio.file.Path
import java.time.DayOfWeek
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
@@ -44,6 +46,8 @@ class BackupEngineTest {
source.settings.setSnoozeMinutes(7)
source.settings.setHomeZoneId("America/New_York")
source.settings.setWorldClockSeconds(true)
source.settings.setWeekStart(WeekStartPref.Day(DayOfWeek.MONDAY))
source.settings.setCompactHomeClock(true)
val exported = source.backupEngine.export()
@@ -70,6 +74,8 @@ class BackupEngineTest {
assertThat(target.settings.currentDefaults().snoozeMinutes).isEqualTo(7)
assertThat(target.settings.currentDefaults().homeZoneId).isEqualTo("America/New_York")
assertThat(target.settings.worldClockSeconds.first()).isTrue()
assertThat(target.settings.weekStart.first()).isEqualTo(WeekStartPref.Day(DayOfWeek.MONDAY))
assertThat(target.settings.compactHomeClock.first()).isTrue()
}
@Test
@@ -6,6 +6,7 @@ import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.PauseRange
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.TimeOfDay
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.alarm.VolumeButtonAction
import de.jeanlucmakiola.clockula.domain.backup.BackupAlarm
import de.jeanlucmakiola.clockula.domain.backup.BackupContent
@@ -21,6 +22,7 @@ import de.jeanlucmakiola.clockula.domain.timer.TimerPresets
import de.jeanlucmakiola.clockula.domain.widget.QuickTimerWidgetSettings
import de.jeanlucmakiola.floret.prefs.ThemeMode
import org.junit.jupiter.api.Test
import java.time.DayOfWeek
import java.time.LocalDate
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Instant
@@ -79,8 +81,10 @@ class BackupCodecTest {
),
timerPresets = listOf(1.minutes, 2.minutes, 10.minutes),
worldClockSeconds = true,
compactHomeClock = true,
quickTileDuration = 3.minutes,
screenSaver = ScreenSaverSettings(style = ScreenSaverStyle.ANALOG, nightMode = true),
weekStart = WeekStartPref.Day(DayOfWeek.SATURDAY),
bedtime = BedtimeSettings(
enabled = true,
bedtime = TimeOfDay(23, 15),
@@ -194,6 +198,27 @@ class BackupCodecTest {
assertThat(decoded.defaults().timerVibrate).isFalse()
}
@Test
fun `a file from before the week start setting follows the locale`() {
val decoded = BackupCodec.decode(settingsOnly(""""default_vibrate": true"""))
assertThat((decoded as BackupResult.Success).content.settings.weekStart).isEqualTo(WeekStartPref.Auto)
}
@Test
fun `an unknown week start follows the locale rather than rejecting the file`() {
val decoded = BackupCodec.decode(settingsOnly(""""week_start": "FUNDAY""""))
assertThat((decoded as BackupResult.Success).content.settings.weekStart).isEqualTo(WeekStartPref.Auto)
}
@Test
fun `a null week start follows the locale rather than rejecting the file`() {
val decoded = BackupCodec.decode(settingsOnly(""""week_start": null"""))
assertThat((decoded as BackupResult.Success).content.settings.weekStart).isEqualTo(WeekStartPref.Auto)
}
private fun settingsOnly(settings: String): String =
"""{ "format": "clockula-backup", "version": 1, "exportedAt": 0, "settings": { $settings } }"""
@@ -483,6 +508,17 @@ class BackupCodecTest {
assertThat(BackupCodec.encode(sampleContent())).contains("\"world_clock_show_seconds\": true")
}
@Test
fun `a file from before the compact home clock keeps it off`() {
val settings = (BackupCodec.decode(minimalDocument()) as BackupResult.Success).content.settings
assertThat(settings.compactHomeClock).isFalse()
}
@Test
fun `the compact home clock is written under its preference key`() {
assertThat(BackupCodec.encode(sampleContent())).contains("\"world_clock_compact_home\": true")
}
@Test
fun `a file from before the automatic local clock keeps it on`() {
val settings = (BackupCodec.decode(minimalDocument()) as BackupResult.Success).content.settings
@@ -115,6 +115,25 @@ class ClockPrefsTest {
assertThat(prefs.worldClockSeconds.first()).isTrue()
}
@Test
fun `the compact home clock round-trips without touching the clock defaults`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(PrefStore(newDataStore(tempDir)))
assertThat(prefs.compactHomeClock.first()).isFalse()
prefs.defaults.test {
assertThat(awaitItem()).isEqualTo(ClockDefaults())
prefs.setCompactHomeClock(true)
// A barrier on this same flow, as for show-seconds above.
prefs.setSnoozeMinutes(7)
assertThat(awaitItem()).isEqualTo(ClockDefaults(snoozeMinutes = 7))
expectNoEvents()
cancel()
}
assertThat(prefs.compactHomeClock.first()).isTrue()
}
@Test
fun `snooze minutes clamp on write`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(PrefStore(newDataStore(tempDir)))
@@ -11,6 +11,7 @@ import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.clockula.domain.ClockDefaults
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.TimeOfDay
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.alarm.VolumeButtonAction
import de.jeanlucmakiola.clockula.domain.ring.SilenceAfter
import de.jeanlucmakiola.clockula.domain.backup.BackupSettings
@@ -32,6 +33,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.nio.file.Path
import java.time.DayOfWeek
import kotlin.time.Duration.Companion.minutes
/**
@@ -106,8 +108,10 @@ class SettingsPrefsTest {
),
timerPresets = listOf(5.minutes, 1.minutes, 5.minutes),
worldClockSeconds = false,
compactHomeClock = true,
quickTileDuration = 2.minutes,
screenSaver = ScreenSaverSettings(ScreenSaverStyle.ANALOG, nightMode = true),
weekStart = WeekStartPref.Day(DayOfWeek.MONDAY),
),
)
@@ -122,9 +126,53 @@ class SettingsPrefsTest {
assertThat(prefs.currentDefaults().timerVibrate).isFalse()
assertThat(prefs.currentDefaults().timerVolumeRampSeconds).isEqualTo(60)
assertThat(prefs.currentDefaults().automaticLocalClock).isFalse()
assertThat(prefs.compactHomeClock.first()).isTrue()
assertThat(prefs.timerPresets.first()).containsExactly(1.minutes, 5.minutes).inOrder()
assertThat(prefs.quickTileDuration.first()).isEqualTo(2.minutes)
assertThat(prefs.screenSaver.first()).isEqualTo(ScreenSaverSettings(ScreenSaverStyle.ANALOG, nightMode = true))
assertThat(prefs.weekStart.first()).isEqualTo(WeekStartPref.Day(DayOfWeek.MONDAY))
}
// --- #30: week start ---
@Test
fun `a fresh install follows the locale's week`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(PrefStore(newDataStore(tempDir)))
assertThat(prefs.weekStart.first()).isEqualTo(WeekStartPref.Auto)
}
@Test
fun `a pinned week start round-trips, and so does going back to automatic`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(PrefStore(newDataStore(tempDir)))
prefs.setWeekStart(WeekStartPref.Day(DayOfWeek.SATURDAY))
assertThat(prefs.weekStart.first()).isEqualTo(WeekStartPref.Day(DayOfWeek.SATURDAY))
prefs.setWeekStart(WeekStartPref.Auto)
assertThat(prefs.weekStart.first()).isEqualTo(WeekStartPref.Auto)
}
@Test
fun `the week start is written under Calendula's key name`(@TempDir tempDir: Path) = runTest {
val dataStore = newDataStore(tempDir)
val prefs = SettingsPrefs(PrefStore(dataStore))
prefs.setWeekStart(WeekStartPref.Day(DayOfWeek.MONDAY))
assertThat(dataStore.data.first()[stringPreferencesKey("week_start")]).isEqualTo("MONDAY")
}
@Test
fun `a corrupted week start falls back to the locale's`(@TempDir tempDir: Path) = runTest {
val dataStore = newDataStore(tempDir)
val prefs = SettingsPrefs(PrefStore(dataStore))
dataStore.updateData { stored ->
stored.toMutablePreferences().apply { this[stringPreferencesKey("week_start")] = "FUNDAY" }
}
assertThat(prefs.weekStart.first()).isEqualTo(WeekStartPref.Auto)
}
@Test
@@ -0,0 +1,52 @@
package de.jeanlucmakiola.clockula.domain
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
import java.time.DayOfWeek
import java.util.Locale
/** "Week starts on" (#30): the locale's day unless one is pinned, and a stored value never throws. */
class WeekStartPrefTest {
@Test
fun `automatic follows the locale`() {
assertThat(WeekStartPref.Auto.resolveFirstDay(Locale.GERMANY)).isEqualTo(DayOfWeek.MONDAY)
assertThat(WeekStartPref.Auto.resolveFirstDay(Locale.US)).isEqualTo(DayOfWeek.SUNDAY)
}
@Test
fun `a pinned day wins over the locale`() {
assertThat(WeekStartPref.Day(DayOfWeek.MONDAY).resolveFirstDay(Locale.US)).isEqualTo(DayOfWeek.MONDAY)
assertThat(WeekStartPref.Day(DayOfWeek.SATURDAY).resolveFirstDay(Locale.GERMANY))
.isEqualTo(DayOfWeek.SATURDAY)
}
@Test
fun `the regional first-day extension is honoured`() {
val germanSundays = Locale.forLanguageTag("de-DE-u-fw-sun")
assertThat(WeekStartPref.Auto.resolveFirstDay(germanSundays)).isEqualTo(DayOfWeek.SUNDAY)
}
@Test
fun `every option round-trips through its stored value`() {
WeekStartPref.OPTIONS.forEach { option ->
assertThat(WeekStartPref.parse(option.storageValue)).isEqualTo(option)
}
}
@Test
fun `absent or unknown reads as automatic`() {
assertThat(WeekStartPref.parse(null)).isEqualTo(WeekStartPref.Auto)
assertThat(WeekStartPref.parse("FUNDAY")).isEqualTo(WeekStartPref.Auto)
assertThat(WeekStartPref.parse("monday")).isEqualTo(WeekStartPref.Auto)
}
@Test
fun `the options are automatic then monday to sunday`() {
assertThat(WeekStartPref.OPTIONS.first()).isEqualTo(WeekStartPref.Auto)
assertThat(WeekStartPref.OPTIONS.drop(1))
.containsExactlyElementsIn(DayOfWeek.entries.map(WeekStartPref::Day))
.inOrder()
}
}
@@ -1,25 +0,0 @@
package de.jeanlucmakiola.clockula.domain.ring
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
/**
* The looped waveform, now shared by both ring paths (slice plan D8). Moved
* here with its assertion unchanged: the pattern did not change, only where it
* lives.
*/
class VibrationPatternTest {
@Test
fun `the vibration pattern is a loopable, non-empty pair of timings and amplitudes`() {
val timings = VibrationPattern.TIMINGS
val amplitudes = VibrationPattern.AMPLITUDES
assertThat(timings.size).isEqualTo(amplitudes.size)
assertThat(timings.size).isGreaterThan(0)
assertThat(VibrationPattern.REPEAT_INDEX).isIn(timings.indices.toList())
assertThat(timings.filter { it <= 0L }).isEmpty()
assertThat(amplitudes.filterNot { it in 0..255 }).isEmpty()
assertThat(amplitudes.filter { it > 0 }).isNotEmpty()
}
}
@@ -1,65 +0,0 @@
package de.jeanlucmakiola.clockula.domain.ring
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
/**
* The ramp is a pure function of elapsed time, so "it never starts at silence
* and never overshoots" is an assertion rather than a listening test.
*/
class VolumeRampTest {
private val ramp = 15.seconds
@Test
fun `the ramp starts at the floor rather than at silence`() {
val level = VolumeRamp.levelAt(Duration.ZERO, ramp)
assertThat(level).isEqualTo(RingAudio.MIN_VOLUME)
}
@Test
fun `the ramp reaches full volume exactly at its end`() {
val level = VolumeRamp.levelAt(ramp, ramp)
assertThat(level).isEqualTo(1f)
}
@Test
fun `past the end the ramp stays at full volume`() {
val level = VolumeRamp.levelAt(30.seconds, ramp)
assertThat(level).isEqualTo(1f)
}
@Test
fun `a zero ramp is full volume immediately`() {
assertThat(VolumeRamp.levelAt(5.seconds, Duration.ZERO)).isEqualTo(1f)
assertThat(VolumeRamp.levelAt(Duration.ZERO, Duration.ZERO)).isEqualTo(1f)
}
@Test
fun `a negative elapsed reading never falls below the floor`() {
val level = VolumeRamp.levelAt((-5).seconds, ramp)
assertThat(level).isEqualTo(RingAudio.MIN_VOLUME)
}
@Test
fun `the ramp never gets quieter as it runs`() {
val samples = (0..100).map { step -> VolumeRamp.levelAt((ramp / 100) * step, ramp) }
assertThat(samples.zipWithNext().filter { (a, b) -> b < a }).isEmpty()
}
@Test
fun `every sample across and beyond the ramp stays inside the floor and the ceiling`() {
val samples = (0..100).map { step ->
VolumeRamp.levelAt((-5).seconds + (35.seconds / 100) * step, ramp)
}
assertThat(samples.filterNot { it >= RingAudio.MIN_VOLUME && it <= 1f }).isEmpty()
}
}
@@ -12,6 +12,7 @@ import de.jeanlucmakiola.clockula.data.timers.TimerRepositoryImpl
import de.jeanlucmakiola.clockula.data.timers.TimerRingStateStore
import de.jeanlucmakiola.clockula.domain.DismissChallenge
import de.jeanlucmakiola.clockula.domain.RepeatDays
import de.jeanlucmakiola.clockula.domain.WeekStartPref
import de.jeanlucmakiola.clockula.domain.ring.SilenceAfter
import de.jeanlucmakiola.clockula.testing.BERLIN
import de.jeanlucmakiola.clockula.testing.FakeAlarmDao
@@ -52,6 +53,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import org.junit.jupiter.api.io.TempDir
import java.nio.file.Path
import java.time.DayOfWeek
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
@@ -235,6 +237,32 @@ class SettingsViewModelTest {
assertThat((viewModel.state.value as SettingsUiState.Loaded).worldClockSeconds).isTrue()
}
@Test
fun `the week start writes through`(@TempDir tempDir: Path) = runTest(main.dispatcher) {
val viewModel = collecting(newViewModel(tempDir))
advanceUntilIdle()
assertThat((viewModel.state.value as SettingsUiState.Loaded).weekStart).isEqualTo(WeekStartPref.Auto)
viewModel.onWeekStartChanged(WeekStartPref.Day(DayOfWeek.SATURDAY))
advanceUntilIdle()
assertThat((viewModel.state.value as SettingsUiState.Loaded).weekStart)
.isEqualTo(WeekStartPref.Day(DayOfWeek.SATURDAY))
}
@Test
fun `the compact home clock switch writes through`(@TempDir tempDir: Path) =
runTest(main.dispatcher) {
val viewModel = collecting(newViewModel(tempDir))
advanceUntilIdle()
assertThat((viewModel.state.value as SettingsUiState.Loaded).compactHomeClock).isFalse()
viewModel.onCompactHomeClockChanged(true)
advanceUntilIdle()
assertThat((viewModel.state.value as SettingsUiState.Loaded).compactHomeClock).isTrue()
}
@Test
fun `choosing a default alarm ringtone writes through and closes the picker`(@TempDir tempDir: Path) =
runTest(main.dispatcher) {
@@ -420,6 +420,21 @@ class WorldClockViewModelTest {
assertThat(harness.ticker.requestedPeriods).isEmpty()
}
/** #29: how home is drawn is not something the tab ticks for. */
@Test
fun `the compact home clock reaches the tab without restarting the ticker`(@TempDir tempDir: Path) =
runTest(main.dispatcher) {
val harness = collecting(worldClockHarness(tempDir))
advanceUntilIdle()
assertThat(harness.loaded().compactHome).isFalse()
harness.settings.setCompactHomeClock(true)
advanceUntilIdle()
assertThat(harness.loaded().compactHome).isTrue()
assertThat(harness.ticker.requestedUnits).containsExactly(WorldClockDefaults.tickFor(showSeconds = false))
}
/** #23: the tab wakes every second only while the user asked for seconds. */
@Test
fun `turning seconds on and off moves the cadence with it`(@TempDir tempDir: Path) =
+5 -4
View File
@@ -87,7 +87,7 @@ kit module: the kit's roadmap keeps schedulers app-local.
|---|---|
| `domain/` | `Alarm.kt`, `Timer.kt`, `WorldClock.kt`, `Stopwatch.kt`, `ClockDefaults.kt`, `Ringtone.kt` (the silent and bundled-tone sentinels), `RepeatSummary.kt`, `AlarmDefaults.kt`. Plain Kotlin, no Android |
| `domain/alarm/` | the alarm engine's pure half: occurrences, the resolver, the ring state, the presentation and scheduling policies, the challenge gate, `VolumeButtonPolicy` (#18), and `AlarmSetCountdown`, what the "Alarm in …" chip says (#19). The *shared* ring vocabulary moved out to `domain/ring/` in M6 |
| `domain/ring/` | what both ring paths share: `RingAudio` (the ramp tick, the volume floor), `VolumeRamp`, `AudioSourcePolicy`/`RingtoneSourceKind`, `RingFallbackPolicy`, `VibrationPattern` |
| `domain/ring/` | what both ring paths share: `AudioSourcePolicy`/`RingtoneSourceKind`, `RingFallbackPolicy`, `MediaRingPolicy`, `SilenceAfter`. The ramp (`VolumeRamp`) and the vibration waveform (`VibrationPattern`) live in floret-kit's `ring` module |
| `domain/stopwatch/` | the stopwatch path's pure half: `StopwatchReadings` (the one reading the pill, the shade and the tab share), `LapStats` (best and worst), `StopwatchLaps` (the lap cap), `StopwatchNotificationPolicy` |
| `domain/timer/` | the timer path's pure half: `TimerReadings` (the app's one timer precedence), `TimerExpiry` (the sweep and the slot's value), `TimerRingPolicy`, `TimerNotificationPolicy`, `TimerPresets`, `TimerDurationEntry`, `TimerSettings`, `TimerRing` |
| `domain/time/` | `WallClock`, `ElapsedRealtimeClock`, `ZoneProvider` (`current()` and, since M8, `available()`, the device's tzdata), `BootId`, `Ticker`, and for the screen saver `ClockChanges` (a time, zone or 12/24-hour change while collected), `HourFormat` and `MinuteBoundary` |
@@ -116,9 +116,9 @@ kit module: the kit's roadmap keeps schedulers app-local.
| `alarm/` | `AlarmEngine` and the four seams it talks to (`AlarmScheduler`, `AlarmCapabilities`, `RingCoordinator`, `AlarmNotifier`), plus `AlarmIntents` |
| `alarm/android/` | the seams' Android implementations: AlarmManager, the capability reads, the service handle, the snoozed and upcoming notifications |
| `alarm/receiver/` | `AlarmFireReceiver`, `AlarmActionReceiver`, `SystemEventReceiver` |
| `alarm/ring/` | the alarm's ringing foreground service and its notifications. Its audio player and vibrator moved to `ring/` in M6, shared with the timer's ring |
| `alarm/ring/` | the alarm's ringing foreground service and its notifications. Its audio player moved to `ring/` in M6, shared with the timer's ring; the vibrator now comes from floret-kit's `ring` module |
| `alarm/di/` | `AlarmModule`: `@Binds` for the four seams |
| `ring/` | `RingAudioPlayer` and `RingVibrator`: one `MediaPlayer` wrapper and one vibrator for both ring paths. A build rule fails on a second one |
| `ring/` | `RingAudioPlayer` (the ringing thing's sources and the media-app ring in front of floret-kit's `TonePlayer`), `ForegroundRingScreen`, the media-app ring. The `MediaPlayer` wrapper, `RingVibrator`, `RingWakeLock` and `startRingForeground` come from floret-kit's `ring` module, shared with Calendula's full-screen reminders. A build rule fails on a second `MediaPlayer` path |
| `timer/` | `TimerEngine` and the three seams it talks to (`TimerScheduler`, `TimerServiceHandle`, `AlarmRingStatus` + `AlarmStateRingStatus`), plus `TimerIntents`, and `QuickTileTimer` (#26), the quick-timer tile's model and tap, through the engine and with no Android type |
| `timer/android/` | the seams' Android implementations: the one elapsed-realtime AlarmManager slot, the service handle |
| `timer/receiver/` | `TimerExpiryReceiver` (the slot arriving), `TimerActionReceiver` (the notification's buttons) |
@@ -618,7 +618,8 @@ Six slices:
|---|---|---|
| Appearance (M1) | `theme_mode`, `dynamic_color` | `AppearancePrefs` in `core-prefs`, the family's shared key names |
| Clock defaults (M2) | `default_snooze_minutes`, `default_snooze_limit`, `default_vibrate`, `default_volume_ramp_seconds`, `default_alarm_ringtone_uri`, `default_timer_ringtone_uri`, `default_timer_vibrate`, `default_timer_volume_ramp_seconds` (#22), `default_dismiss_challenge`, `home_zone_id`, `volume_buttons_while_ringing` (#18; app-wide, no per-alarm override), `automatic_local_clock` (#24) | `ClockPrefs`, surfaced as `SettingsPrefs.defaults: Flow<ClockDefaults>` |
| World clock display (#23) | `world_clock_show_seconds` | `ClockPrefs`, surfaced as its own `SettingsPrefs.worldClockSeconds`, not a clock default, so flipping it re-emits nothing alarms and timers watch |
| Week start (#30) | `week_start` | `ClockPrefs`: `AUTO` (absent reads the same) follows the locale, a `DayOfWeek` name pins that day; surfaced as `SettingsPrefs.weekStart`, provided to every screen by `MainActivity` as `LocalWeekStart`, and carried in the backup |
| World clock display (#23, #29) | `world_clock_show_seconds`, `world_clock_compact_home` | `ClockPrefs`, surfaced as their own `SettingsPrefs.worldClockSeconds` and `SettingsPrefs.compactHomeClock`, not clock defaults, so flipping them re-emits nothing alarms and timers watch |
| Stopwatch run record (M2) | `stopwatch_state`, `stopwatch_started_elapsed_millis`, `stopwatch_accumulated_millis`, `stopwatch_last_lap_cumulative_millis` (M7 is the first caller of the last, for the in-progress lap's split) | `StopwatchPrefs`, behind `StopwatchStateStore` |
| System facts (M3) | `last_boot_id` | `SystemPrefs`, behind `BootStateStore`, the persisted half of the reboot gate |
| Timers (M6) | `timer_presets`, `timer_ring_sounding_since_millis` | `TimerPrefs`: the presets surfaced as `SettingsPrefs.timerPresets`, the ring session's anchor behind `TimerRingStateStore` |
+9 -2
View File
@@ -164,6 +164,7 @@ device or after a reboot (`docs/PLAN.md` §5). Every imported timer lands
"default_timer_silence_after_minutes": 10,
"volume_buttons_while_ringing": "CONTROL_VOLUME",
"world_clock_show_seconds": false,
"world_clock_compact_home": false,
"automatic_local_clock": true,
"timer_presets": [60000, 120000, 180000, 300000, 600000, 900000, 1800000, 3600000],
"bedtime": {
@@ -179,7 +180,8 @@ device or after a reboot (`docs/PLAN.md` §5). Every imported timer lands
},
"screen_saver_style": "DIGITAL",
"screen_saver_night_mode": false,
"quick_tile_duration_millis": 300000
"quick_tile_duration_millis": 300000,
"week_start": "AUTO"
}
```
@@ -213,9 +215,14 @@ rings for that long anyway); a negative one reads as the default, 10.
Files from before `world_clock_show_seconds` existed import with it off, its
default. It travels with the settings but is not a clock default: nothing an
alarm or timer inherits depends on it. A file without `automatic_local_clock`
alarm or timer inherits depends on it. The same goes for
`world_clock_compact_home` (#29), which a file without it restores as off. A file without `automatic_local_clock`
(one written before it existed) restores it as `true`, its default.
`week_start` is the first day of the week (#30): `AUTO`, which follows the
locale, or a day name from `MONDAY` to `SUNDAY`. A file without it, or with a
value this version does not know or `null`, restores `AUTO`.
Every numeric/duration value is clamped on *apply* using the same ranges and encoding
as the existing preference setters, never on parse.