Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ aren't obvious from using it.
about, unlike a timer, so there's nothing worth a permanent notification for; it keeps
running across tab swipes and a trip to Settings and back (both stay under the same
`TabsScreen` back-stack entry) but not past the app process being killed.
- **Changing an alarm's time switches it on**, the way the stock Clock app does. Setting a
time is how you set an alarm, so picking one on a switched-off alarm and leaving it off
would just mean it silently doesn't ring. The quick time popup always enables; the full
editor sheet only does so when the time actually changed, since that sheet has no on/off
switch of its own (that lives on the list row) and merely renaming a switched-off alarm
shouldn't quietly turn it on.
- **Editing is in-place, not a separate screen.** Tap an alarm's time for a quick
time-only popup — which now also has a Delete action, so removing an alarm doesn't
require opening the full editor either — or tap its label/repeat area for the full
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ class AlarmRepository(
save(alarm.copy(enabled = enabled))
}

/** Updates just the time, leaving every other setting untouched — used by the quick time-edit popup. */
/** Updates just the time, leaving every other setting untouched — used by the quick time-edit
* popup — and switches the alarm on. Setting a time is how you set an alarm: picking one on a
* switched-off alarm and having it stay off means it silently won't ring, which is never what
* was meant. Matches the stock Clock app. */
suspend fun updateTime(id: Long, hour: Int, minute: Int) {
val alarm = dao.getById(id) ?: return
save(alarm.copy(hour = hour, minute = minute))
save(alarm.copy(hour = hour, minute = minute, enabled = true))
}

/** Re-arms every enabled alarm's AlarmManager entry; alarms don't survive a reboot on their own.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ class AlarmEditorViewModel(
private val _state = MutableStateFlow(AlarmEditorUiState(isNew = alarmId == null))
val state: StateFlow<AlarmEditorUiState> = _state.asStateFlow()

/** The time an existing alarm had when the sheet opened, so [save] can tell whether the user
* actually changed it. Null for a new alarm, which starts switched on anyway. */
private var loadedTime: Pair<Int, Int>? = null

init {
val defaults = appDefaultsStore.defaults.value
val id = alarmId
if (id != null) {
viewModelScope.launch {
val alarm = repository.getById(id)
loadedTime = alarm?.let { it.hour to it.minute }
_state.value = if (alarm != null) {
AlarmEditorUiState(
id = alarm.id,
Expand Down Expand Up @@ -107,14 +112,20 @@ class AlarmEditorViewModel(

fun save(onDone: () -> Unit) {
val s = _state.value
// Changing the time switches the alarm on, the same as the quick time popup does: picking
// a new time for a switched-off alarm and leaving it off means it silently won't ring.
// Only when the time actually changed, though — this sheet has no on/off switch of its own
// (that lives on the list row), so saving it after only renaming a switched-off alarm must
// not quietly turn it on.
val timeChanged = loadedTime?.let { (hour, minute) -> hour != s.hour || minute != s.minute } ?: false
viewModelScope.launch {
repository.save(
Alarm(
id = s.id,
hour = s.hour,
minute = s.minute,
label = s.label,
enabled = s.enabled,
enabled = s.enabled || timeChanged,
repeatDaysMask = s.repeatDaysMask,
vibrate = s.vibrate,
fadeInEnabled = s.fadeInEnabled,
Expand Down
Loading