refactor(#514): one firing-reminders view for the editor and the import prompt
This commit is contained in:
1 parent
738a28fc0a
commit
6a384b03e9
3 files changed
+15
-15
No files matched your search
+2
-2
@@ -47,7 +47,7 @@ internal fun toProviderAllDayMinutes(
|
||||
): Int {
|
||||
if (semanticMinutes == MINUTES_DEFAULT) return semanticMinutes
|
||||
val utcMidnight = startDate.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli()
|
||||
val fire = startDate.minusDays((wholeDayLeadMinutes(semanticMinutes) / MINUTES_PER_DAY).toLong())
|
||||
val fire = startDate.minusDays((semanticMinutes / MINUTES_PER_DAY).toLong())
|
||||
.atTime(LocalTime.of(timeOfDayMinutes / 60, timeOfDayMinutes % 60))
|
||||
.atZone(zone).toInstant().toEpochMilli()
|
||||
val raw = ((utcMidnight - fire) / MILLIS_PER_MINUTE).toInt()
|
||||
@@ -56,7 +56,7 @@ internal fun toProviderAllDayMinutes(
|
||||
|
||||
/**
|
||||
* A lead time as the whole days an all-day reminder actually fires at: the
|
||||
* sub-day part is dropped, the same truncation [toProviderAllDayMinutes] applies.
|
||||
* sub-day part is dropped, matching [toProviderAllDayMinutes]'s day count.
|
||||
* [MINUTES_DEFAULT] passes through.
|
||||
*/
|
||||
internal fun wholeDayLeadMinutes(minutes: Int): Int =
|
||||
|
||||
@@ -166,7 +166,6 @@ import de.jeanlucmakiola.floret.components.Position
|
||||
import de.jeanlucmakiola.floret.components.groupedShape as floretGroupedShape
|
||||
import de.jeanlucmakiola.floret.components.positionOf
|
||||
import de.jeanlucmakiola.calendula.ui.common.reminderPresets
|
||||
import de.jeanlucmakiola.calendula.data.calendar.wholeDayLeadTimes
|
||||
import de.jeanlucmakiola.calendula.ui.common.customReminderUnits
|
||||
import de.jeanlucmakiola.calendula.ui.common.customReminderPlaceholder
|
||||
import de.jeanlucmakiola.calendula.ui.common.splitsSubDay
|
||||
@@ -878,7 +877,7 @@ private fun EventEditContent(
|
||||
OptionalFormSection(visible = EventFormField.Reminders in state.visibleFields) {
|
||||
Spacer(Modifier.height(gap))
|
||||
RemindersSection(
|
||||
reminders = form.shownReminders(),
|
||||
reminders = form.firingReminders(),
|
||||
onRemove = viewModel::removeReminder,
|
||||
onAdd = { sheet = EditSheet.Reminder },
|
||||
)
|
||||
@@ -1283,14 +1282,6 @@ private fun LocationCard(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reminders as they fire: an all-day event fires on whole days, so a sub-day lead
|
||||
* time kept from the timed form shows as its day. The form keeps the raw values,
|
||||
* so switching all-day off again restores them.
|
||||
*/
|
||||
private fun EventForm.shownReminders(): List<Int> =
|
||||
if (isAllDay) wholeDayLeadTimes(reminders) else reminders
|
||||
|
||||
/**
|
||||
* A grouped list like guests: each reminder is its own tonal card with
|
||||
* connected corners, the last row being "Add reminder".
|
||||
@@ -1501,7 +1492,7 @@ private fun EditSheetHost(
|
||||
}
|
||||
EditSheet.Reminder -> ReminderPickerDialog(
|
||||
isAllDay = form.isAllDay,
|
||||
alreadyChosen = form.shownReminders(),
|
||||
alreadyChosen = form.firingReminders(),
|
||||
onSelect = { minutes ->
|
||||
viewModel.addReminder(minutes)
|
||||
onClose()
|
||||
|
||||
@@ -8,6 +8,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository
|
||||
import de.jeanlucmakiola.calendula.data.calendar.NoSuchEventException
|
||||
import de.jeanlucmakiola.calendula.data.calendar.wholeDayLeadMinutes
|
||||
import de.jeanlucmakiola.calendula.data.calendar.wholeDayLeadTimes
|
||||
import de.jeanlucmakiola.calendula.data.ics.IcsExporter
|
||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||
@@ -537,9 +538,9 @@ class EventEditViewModel @Inject constructor(
|
||||
if (opened != session) return@launch
|
||||
val current = _form.value ?: return@launch
|
||||
if (_editTarget.value != null) return@launch
|
||||
if (default.isEmpty() || default == current.reminders) return@launch
|
||||
if (default.isEmpty() || default == current.firingReminders()) return@launch
|
||||
_importReminderPrompt.value = ImportReminderPrompt(
|
||||
currentReminderCount = current.reminders.size,
|
||||
currentReminderCount = current.firingReminders().size,
|
||||
defaultReminders = default,
|
||||
)
|
||||
}
|
||||
@@ -962,3 +963,11 @@ class EventEditViewModel @Inject constructor(
|
||||
_form.value = _form.value?.let(block)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reminders as they fire: an all-day event fires on whole days, so a sub-day lead
|
||||
* time kept from the timed form reads as its day. The form keeps the raw values,
|
||||
* so switching all-day off again restores them.
|
||||
*/
|
||||
internal fun EventForm.firingReminders(): List<Int> =
|
||||
if (isAllDay) wholeDayLeadTimes(reminders) else reminders
|
||||
Reference in new issue
Block a user