Compare commits

..
18 changed files with 163 additions and 260 deletions

No files matched your search

+1
View File
@@ -74,3 +74,4 @@ Gemfile.lock
# Claude Code
/CLAUDE.md
.kotlin/
@@ -24,7 +24,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.IntentCompat
import androidx.core.net.toUri
import androidx.core.os.BundleCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
@@ -40,7 +39,6 @@ import de.jeanlucmakiola.calendula.domain.EventForm
import de.jeanlucmakiola.calendula.domain.buildInsertEventForm
import de.jeanlucmakiola.calendula.domain.sharedTextOrNull
import de.jeanlucmakiola.calendula.ui.ExternalRequests
import de.jeanlucmakiola.calendula.ui.LeaveTarget
import de.jeanlucmakiola.calendula.ui.InsertRequest
import de.jeanlucmakiola.calendula.ui.RootScreen
import de.jeanlucmakiola.calendula.ui.common.LocalShowHourGrid
@@ -94,10 +92,6 @@ class MainActivity : AppCompatActivity() {
insertFormOpen = false
if (launchedForInsert) finish()
},
onLeave = {
homeOnReturn = moveTaskToBack(true)
homeOnReturn
},
)
// Whether such a form is still open. Only then does a recreation re-read the
@@ -108,9 +102,6 @@ class MainActivity : AppCompatActivity() {
// app that asked instead of leaving the calendar on top of it.
private var launchedForInsert = false
// Back left a widget's day or event for the home screen; the next start shows the home view.
private var homeOnReturn = false
// A captured crash report awaiting the user's decision, surfaced as a dialog
// over the calendar on the next launch (the single-crash path). A startup
// crash-loop is handled out of band, before setContent — see below.
@@ -159,10 +150,7 @@ class MainActivity : AppCompatActivity() {
// specific event is what made a single reminder or widget tap re-open
// that event on every later launch, an error screen once the event had
// been deleted (#309); the user left it long ago, and the activity
// restores where they actually were along with its saved state. Every
// widget/shortcut navigation is held back the same way; one still pending
// at the recreation is restored from the saved state instead, so it's the
// request that actually arrived last, not the launch intent's (#530).
// restores where they actually were along with its saved state.
//
// Only those channels are held back. An .ics import or a prefilled
// create form keeps no saved state of its own, so re-reading the intent
@@ -174,15 +162,8 @@ class MainActivity : AppCompatActivity() {
requests.detailKey = intent.detailKeyOrNull() ?: intent.viewEventKeyOrNull()
requests.editKey = intent.editEventKeyOrNull()
}
requests.nav = if (replaying) {
savedInstanceState?.let { BundleCompat.getSerializable(it, KEY_PENDING_NAV, WidgetNavRequest::class.java) }
} else {
intent.navRequestOrNull()
}
requests.leaveTarget = savedInstanceState?.let {
BundleCompat.getSerializable(it, KEY_LEAVE_TARGET, LeaveTarget::class.java)
}
homeOnReturn = savedInstanceState?.getBoolean(KEY_HOME_ON_RETURN) == true
requests.nav = intent.navRequestOrNull()
?.takeUnless { replaying && it is WidgetNavRequest.OpenEvent }
requests.importUri = intent.importUriOrNull()
val insertOpenBefore = savedInstanceState?.getBoolean(KEY_INSERT_FORM_OPEN) == true
requests.insert = intent.createRequestOrNull()?.takeIf { !replaying || insertOpenBefore }
@@ -293,22 +274,10 @@ class MainActivity : AppCompatActivity() {
override fun onStart() {
super.onStart()
// Reset only now, so the screen doesn't change while the task animates away.
// A request arriving with this start (onNewIntent comes after) opens over it.
if (homeOnReturn) {
homeOnReturn = false
requests.resetToHome = true
}
// Changes made while we were away may never have notified us (#364).
calendarRepository.refresh()
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
// Once the user has left, a later return is no longer the widget's day or event.
requests.leaveTarget = null
}
override fun onResume() {
super.onResume()
// Reaching a running UI means startup succeeded; reset the loop trail.
@@ -320,9 +289,6 @@ class MainActivity : AppCompatActivity() {
super.onSaveInstanceState(outState)
outState.putBoolean(KEY_INSERT_FORM_OPEN, insertFormOpen)
outState.putBoolean(KEY_LAUNCHED_FOR_INSERT, launchedForInsert)
outState.putSerializable(KEY_PENDING_NAV, requests.nav)
outState.putSerializable(KEY_LEAVE_TARGET, requests.leaveTarget)
outState.putBoolean(KEY_HOME_ON_RETURN, homeOnReturn)
}
override fun onNewIntent(intent: Intent) {
@@ -490,9 +456,9 @@ class MainActivity : AppCompatActivity() {
}
private fun Intent.navRequestOrNull(): WidgetNavRequest? {
// An external date tap (launcher/clock) opens the day view over the default
// home view, and backs out to it.
calendarTimeDateOrNull()?.let { return WidgetNavRequest.OpenDate(it.toString(), fromWidget = false) }
// An external date tap (launcher/clock) has no widget source, so it opens
// the day view rooted over the default home view (OpenDate source = null).
calendarTimeDateOrNull()?.let { return WidgetNavRequest.OpenDate(it.toString(), source = null) }
// A widget header tap: open a top-level view with no date drill-in. The
// empty string carried by [openViewIntent] means "the default home view".
if (hasExtra(EXTRA_OPEN_VIEW)) {
@@ -515,8 +481,8 @@ class MainActivity : AppCompatActivity() {
endMillis = getLongExtra(EXTRA_END_MILLIS, 0L),
source = source,
)
getStringExtra(EXTRA_DATE_ISO) != null ->
WidgetNavRequest.OpenDate(getStringExtra(EXTRA_DATE_ISO)!!, fromWidget = true)
source != null && getStringExtra(EXTRA_DATE_ISO) != null ->
WidgetNavRequest.OpenDate(getStringExtra(EXTRA_DATE_ISO)!!, source)
else -> null
}
}
@@ -598,9 +564,6 @@ class MainActivity : AppCompatActivity() {
private val CALENDAR_EXTENSIONS = listOf(".ics", ".vcs")
private const val KEY_INSERT_FORM_OPEN = "insert_form_open"
private const val KEY_LAUNCHED_FOR_INSERT = "launched_for_insert"
private const val KEY_PENDING_NAV = "pending_nav"
private const val KEY_LEAVE_TARGET = "leave_target"
private const val KEY_HOME_ON_RETURN = "home_on_return"
private const val EXTRA_EVENT_ID = "de.jeanlucmakiola.calendula.extra.EVENT_ID"
private const val EXTRA_BEGIN_MILLIS = "de.jeanlucmakiola.calendula.extra.BEGIN"
@@ -639,13 +602,17 @@ class MainActivity : AppCompatActivity() {
}
/**
* Open the day view anchored on [date] from a home-screen widget; backing
* out of the day returns to the home screen (#530).
* Open the day view anchored on [date], drilled in over the launching
* widget's [source] view (home-screen widgets). Backing out of the day
* returns to [source], then to the default home view.
*/
fun openDateIntent(context: Context, date: LocalDate): Intent =
fun openDateIntent(context: Context, date: LocalDate, source: CalendarView): Intent =
Intent(context, MainActivity::class.java).apply {
data = "calendula://date/$date".toUri()
// The source is part of the URI so widgets of different kinds
// tapping the same date don't share one PendingIntent.
data = "calendula://date/$date/${source.name}".toUri()
putExtra(EXTRA_DATE_ISO, date.toString())
putExtra(EXTRA_SOURCE_VIEW, source.name)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
@@ -125,12 +125,11 @@ import kotlin.time.Instant
*
* The stack's bottom is the user's [CalendarHostViewModel.defaultView] home view.
* A lateral switch (pill / drawer) builds a visit history so back retraces it
* (see [selectView]); a widget event or header launch resets the stack to the
* widget's view; a date tap or date launch drills the day view on top. Pressing
* back pops one level, and the base-level [BackHandler] hands off to the system
* to exit once only the home view remains. Back from a widget-opened day or
* event leaves the app at once (#530), until the user navigates on from it; and
* back through pill switches walks the views in reverse.
* (see [selectView]); a widget launch resets the stack to its own view; a date
* tap drills the day view on top. Pressing back pops one level, and the
* base-level [BackHandler] hands off to the system to exit once only the home
* view remains. So back from a widget-opened screen returns to that widget's
* view, then home; and back through pill switches walks the views in reverse.
*
* [requests] carries what notifications, widgets and other apps asked to
* open. A tapped reminder's occurrence opens the detail overlay exactly like an
@@ -183,9 +182,7 @@ fun CalendarHost(
val switchTo: ((List<CalendarView>) -> List<CalendarView>) -> Unit = { move ->
navigationVersion++
returnedFromDay = false
val moved = move(viewStack)
requests.leaveTarget = requests.leaveTarget.afterMove(viewStack, moved)
viewStack = moved
viewStack = move(viewStack)
}
val onSelectView: (CalendarView) -> Unit = { target -> switchTo { it.selectView(target) } }
val onOpenDay: (LocalDate) -> Unit = { date ->
@@ -204,28 +201,12 @@ fun CalendarHost(
// Like every overlay below, it draws its last key through the slide-out
// ([rememberHeld]) rather than a placeholder.
var detailKey by rememberSaveable { mutableStateOf<LongArray?>(null) }
LaunchedEffect(detailKey) { requests.leaveTarget = requests.leaveTarget.afterDetail(detailKey) }
val onOpenDetail: (EventInstance) -> Unit = { event -> detailKey = event.occurrenceKey() }
// The drawer's "Hide in this view" picker (#517). It is its own window over
// everything here, so each external request below closes it first.
var showViewCalendars by rememberSaveable { mutableStateOf(false) }
// Back left a widget's day or event (#530): the app comes back on the home
// view. Ahead of the other requests, so one arriving with the return opens over it.
val resetToHome = requests.resetToHome
LaunchedEffect(resetToHome) {
if (resetToHome) {
navigationVersion++
returnedFromDay = false
detailKey = null
focus.navigateTo(currentDate())
viewStack = listOf(defaultView)
requests.leaveTarget = null
requests.resetToHome = false
}
}
// A tapped reminder notification asks for a specific occurrence.
val requestedDetailKey = requests.detailKey
LaunchedEffect(requestedDetailKey) {
@@ -422,7 +403,8 @@ fun CalendarHost(
// A home-screen widget launch asks to open a date (→ day view), open an
// event's detail, or start a create. Handled once and cleared, mirroring
// the detail request. A widget's day or event leaves the app on back (#530).
// the detail request. Date/event opens root the stack in the widget's own
// view so backing out returns there (then home), not to the default.
val widgetNavRequest = requests.nav
LaunchedEffect(widgetNavRequest) {
if (widgetNavRequest != null) {
@@ -431,12 +413,13 @@ fun CalendarHost(
}
when (val req = widgetNavRequest) {
is WidgetNavRequest.OpenDate -> {
// Drop any overlay that would cover the day, so the open doesn't
// land under Settings/form.
// Drill the day view in over the widget's view: drop any overlay
// that would cover it, so the open doesn't land under Settings/form.
dismissCoveringOverlays()
focus.navigateTo(LocalDate.parse(req.dateIso))
viewStack = listOf(defaultView).drillToDay()
requests.leaveTarget = req.leaveTarget
// No widget source (an external date tap) roots over the default
// home view, so backing out of the day returns home then exits.
viewStack = viewBaseStack(defaultView, req.source ?: defaultView).drillToDay()
requests.nav = null
}
is WidgetNavRequest.OpenEvent -> {
@@ -445,7 +428,6 @@ fun CalendarHost(
dismissCoveringOverlays()
viewStack = viewBaseStack(defaultView, req.source)
detailKey = longArrayOf(req.eventId, req.beginMillis, req.endMillis)
requests.leaveTarget = req.leaveTarget
requests.nav = null
}
is WidgetNavRequest.OpenView -> {
@@ -456,7 +438,6 @@ fun CalendarHost(
dismissCoveringOverlays()
focus.navigateTo(currentDate())
viewStack = viewBaseStack(defaultView, req.view ?: defaultView)
requests.leaveTarget = null
requests.nav = null
}
is WidgetNavRequest.Create -> {
@@ -553,12 +534,7 @@ fun CalendarHost(
val viewTransition = remember { SeekableTransitionState(view) }
LaunchedEffect(view) { viewTransition.animateTo(view) }
val reduceMotion = rememberReduceMotion()
val leaveOnBack = requests.leaveTarget.leaves(detailKey, anyOverlayVisible)
val viewBackEnabled = !anyOverlayVisible && viewStack.size > 1 && !leaveOnBack
// The app goes to the background and comes back on the home view. Overlays
// opened over a widget's detail register later, so their own back still wins.
// A refused move (screen pinning) falls back to the in-app back from then on.
BackHandler(enabled = leaveOnBack) { if (!requests.onLeave()) requests.leaveTarget = null }
val viewBackEnabled = !anyOverlayVisible && viewStack.size > 1
if (reduceMotion) {
BackHandler(enabled = viewBackEnabled) {
navigationVersion++
@@ -808,8 +784,6 @@ fun CalendarHost(
detailKey = null
},
visible = detailKey != null,
// A widget's own detail leaves the app on back, through the handler above.
backEnabled = !leaveOnBack,
)
}
}
@@ -15,15 +15,10 @@ import de.jeanlucmakiola.calendula.ui.edit.ImportSource
* it, so a later recomposition can't act on it twice.
*
* [onExternalFormClosed] runs when a form opened for [insert] closes, so the
* activity can hand control back to the app that asked. [onLeave] sends the app
* to the background when back leaves a widget's day or event ([leaveTarget]),
* false when the system refused.
* activity can hand control back to the app that asked.
*/
@Stable
class ExternalRequests(
val onExternalFormClosed: () -> Unit = {},
val onLeave: () -> Boolean = { false },
) {
class ExternalRequests(val onExternalFormClosed: () -> Unit = {}) {
/** A tapped reminder notification's occurrence (eventId, begin, end), for the detail screen. */
var detailKey by mutableStateOf<LongArray?>(null)
@@ -42,12 +37,6 @@ class ExternalRequests(
/** An external "edit this event" (ACTION_EDIT), in the detail key's shape. */
var editKey by mutableStateOf<LongArray?>(null)
/** What back leaves the app from (#530). Cleared once the user leaves the app. */
var leaveTarget by mutableStateOf<LeaveTarget?>(null)
/** Set when the app comes back after [onLeave]: show the home view. */
var resetToHome by mutableStateOf(false)
/** Whether these came from re-reading the launch intent on a recreation. */
var replayed = false
}
@@ -1,25 +1,27 @@
package de.jeanlucmakiola.calendula.ui
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import java.io.Serializable
/**
* A navigation a home-screen widget asked the app to perform when launched.
* Parsed from the launch intent in MainActivity and consumed once by
* [CalendarHost]. An event open carries the [OpenEvent.source] view of the
* widget it came from (the agenda widget → [CalendarView.Agenda]) as the view
* under its detail. (Reminder notifications are not widgets — they keep the
* separate detail-key channel and leave the base view untouched.)
* [CalendarHost]. Every request carries the [source] view of the widget it came
* from (the agenda widget → [CalendarView.Agenda], the month widget →
* [CalendarView.Month]) so the in-app back stack roots itself in that view:
* backing out of the opened date/event returns to the widget's own view, not the
* default home. (Reminder notifications are not widgets — they keep the separate
* detail-key channel and leave the base view untouched.)
*/
sealed interface WidgetNavRequest : Serializable {
sealed interface WidgetNavRequest {
/**
* Open the day view anchored on [dateIso] (an ISO `yyyy-MM-dd` date), over the
* default home view. [fromWidget] makes back leave the app at once (#530); a
* launcher/clock date tap (issue #9) or the daily summary backs out to home.
* Open the day view anchored on [dateIso] (an ISO `yyyy-MM-dd` date), over
* [source]. A null [source] means the request came from outside the app (a
* launcher/clock date tap, issue #9) rather than a widget, so it roots over
* the default home view instead of a widget's view.
*/
data class OpenDate(val dateIso: String, val fromWidget: Boolean) : WidgetNavRequest
data class OpenDate(val dateIso: String, val source: CalendarView?) : WidgetNavRequest
/** Open one occurrence's detail (a widget event tap), over [source]; back leaves the app (#530). */
/** Open one occurrence's detail (an agenda-widget event tap), over [source]. */
data class OpenEvent(
val eventId: Long,
val beginMillis: Long,
@@ -39,38 +41,3 @@ sealed interface WidgetNavRequest : Serializable {
*/
data class OpenView(val view: CalendarView?) : WidgetNavRequest
}
/** What back leaves the app from (#530): a widget's day, or a widget's event detail. */
sealed interface LeaveTarget : Serializable {
/** The view a widget opened, while no overlay covers it. */
data object View : LeaveTarget
/** The detail of the occurrence a widget opened. */
data class Detail(val eventId: Long, val beginMillis: Long, val endMillis: Long) : LeaveTarget {
fun matches(key: LongArray?): Boolean =
key != null && key.size == 3 && key[0] == eventId && key[1] == beginMillis && key[2] == endMillis
}
}
/** What back leaves the app from after this request: a widget's day or event, else nothing. */
val WidgetNavRequest.leaveTarget: LeaveTarget?
get() = when (this) {
is WidgetNavRequest.OpenDate -> LeaveTarget.View.takeIf { fromWidget }
is WidgetNavRequest.OpenEvent -> LeaveTarget.Detail(eventId, beginMillis, endMillis)
else -> null
}
/** The target after a move from [before] to [after]: kept only while the user stays on the same views. */
fun LeaveTarget?.afterMove(before: List<CalendarView>, after: List<CalendarView>): LeaveTarget? =
takeIf { before == after }
/** The target once the detail shows [shown]: a widget's detail is dropped once it closes or changes. */
fun LeaveTarget?.afterDetail(shown: LongArray?): LeaveTarget? =
if (this is LeaveTarget.Detail && !matches(shown)) null else this
/** Whether back leaves the app now, given the open detail and whether any overlay is up. */
fun LeaveTarget?.leaves(detail: LongArray?, overlayVisible: Boolean): Boolean = when (this) {
LeaveTarget.View -> !overlayVisible
is LeaveTarget.Detail -> matches(detail)
null -> false
}
@@ -112,11 +112,11 @@ data class QuickSwitchConfig(
* top; switching to one already in the stack pops back to it (collapsing the
* loop, so the depth stays bounded by the number of distinct views). Selecting
* the home view collapses to just `[default]`.
* - [viewBaseStack] — the stack a widget event or header launch resets to: just `[default]` when
* - [viewBaseStack] — the stack a widget launch resets to: just `[default]` when
* the widget's view is the home view, else `[default, source]`. A widget entry
* starts a fresh context rather than extending in-app history.
* - [drillToDay] — pushes the day view on top (a date tap from the month grid, a
* widget or a launcher), unless the day view is already current.
* - [drillToDay] — pushes the day view on top (a date tap from the month grid or
* a widget), unless the day view is already current.
*/
fun List<CalendarView>.selectView(target: CalendarView): List<CalendarView> {
val existing = indexOf(target)
@@ -2,6 +2,7 @@ package de.jeanlucmakiola.calendula.ui.common
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
@@ -131,7 +132,8 @@ fun FixedTimeReminderEditor(
* Picker for a fixed-time default (#459), full-screen: off, or a reminder at a
* set time edited in place — and, on a per-calendar picker ([inheritedLabel]
* non-null), deferring to the global default, [inherited], which also seeds the
* editor. Applies live; the user leaves via back.
* editor. Applies live; the user leaves via back, or through [footer], which
* follows the options and gets [onDismiss].
*/
@Composable
fun FixedTimeReminderPicker(
@@ -141,6 +143,7 @@ fun FixedTimeReminderPicker(
onDismiss: () -> Unit,
inheritedLabel: String? = null,
inherited: FixedTimeReminder? = null,
footer: @Composable ColumnScope.(dismiss: () -> Unit) -> Unit = {},
) {
var current by rememberSaveable(stateSaver = FixedTimeOverrideSaver) { mutableStateOf(selected) }
var editing by rememberSaveable { mutableStateOf(false) }
@@ -192,6 +195,7 @@ fun FixedTimeReminderPicker(
},
)
}
footer(onDismiss)
}
}
@@ -142,7 +142,6 @@ fun EventDetailScreen(
onEdit: () -> Unit,
onDuplicate: (EventForm) -> Unit,
visible: Boolean = true,
backEnabled: Boolean = true,
viewModel: EventDetailViewModel = hiltViewModel(),
) {
LaunchedEffect(eventId, beginMillis, endMillis) {
@@ -199,7 +198,7 @@ fun EventDetailScreen(
}
Scaffold(
modifier = Modifier.predictiveBack(onBack = onBack, enabled = backEnabled, visible = visible),
modifier = Modifier.predictiveBack(onBack = onBack, visible = visible),
snackbarHost = { SnackbarHost(snackbarHostState) },
topBar = {
TopAppBar(
@@ -4,6 +4,7 @@ import de.jeanlucmakiola.floret.identity.collapseExit
import de.jeanlucmakiola.floret.identity.expandEnter
import androidx.compose.foundation.layout.Column
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterExitState
import android.Manifest
import android.content.Context
import android.content.Intent
@@ -19,10 +20,13 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.NotificationsActive
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -108,6 +112,7 @@ internal fun NotificationsScreen(
var showFixedDefault by remember { mutableStateOf(false) }
var showDigestDay by remember { mutableStateOf(false) }
var showDigestTime by remember { mutableStateOf(false) }
var revealDigest by rememberSaveable { mutableStateOf(false) }
val scope = rememberCoroutineScope()
val channelStatus by viewModel.channelStatus.collectAsStateWithLifecycle()
val digestBlocked by viewModel.digestBlocked.collectAsStateWithLifecycle()
@@ -193,9 +198,14 @@ internal fun NotificationsScreen(
Spacer(Modifier.height(24.dp))
DailyDigestRows(
reveal = revealDigest,
onRevealed = { revealDigest = false },
digest = state.dailyDigest,
blocked = channelStatus.appBlocked || digestBlocked,
onEnable = toggleDigest,
onEnable = {
revealDigest = false
toggleDigest(it)
},
onPickDay = { showDigestDay = true },
onPickTime = { showDigestTime = true },
onOpenSound = {
@@ -257,6 +267,29 @@ internal fun NotificationsScreen(
selected = state.defaultFixedTimeReminder?.let { FixedTimeOverride.At(it) } ?: FixedTimeOverride.Off,
onSelect = { viewModel.setDefaultFixedTimeReminder((it as? FixedTimeOverride.At)?.reminder) },
onDismiss = { showFixedDefault = false },
footer = { dismiss ->
// For those after one list of the day's events (#459).
if (!state.dailyDigest.enabled) {
Spacer(Modifier.height(24.dp))
GroupedRow(
title = stringResource(R.string.settings_digest_turn_on),
summary = stringResource(R.string.settings_digest_hint),
position = Position.Alone,
leading = {
Icon(
imageVector = Icons.Outlined.NotificationsActive,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
},
onClick = {
revealDigest = true
toggleDigest(true)
dismiss()
},
)
}
},
)
}
if (showDigestDay) {
@@ -328,7 +361,8 @@ internal fun NotificationsScreen(
/**
* The daily summary (#459): its switch, and once on, which day it lists, when,
* and its channel's system settings.
* and its channel's system settings. With [reveal], the block scrolls into view
* once those rows have expanded, then reports [onRevealed].
*/
@Composable
private fun DailyDigestRows(
@@ -338,47 +372,59 @@ private fun DailyDigestRows(
onPickDay: () -> Unit,
onPickTime: () -> Unit,
onOpenSound: () -> Unit,
reveal: Boolean,
onRevealed: () -> Unit,
) {
GroupedSwitchRow(
title = stringResource(R.string.settings_digest),
checked = digest.enabled,
onCheckedChange = onEnable,
summary = if (digest.enabled) {
stringResource(
R.string.settings_digest_summary,
stringResource(digestDayLabel(digest.day)),
settingsTimeOfDay(digest.timeMinutes),
)
} else {
stringResource(R.string.settings_digest_hint)
},
position = if (digest.enabled) Position.Top else Position.Alone,
)
AnimatedVisibility(visible = digest.enabled, enter = expandEnter(), exit = collapseExit()) {
Column {
GroupedRow(
title = stringResource(R.string.settings_digest_day),
summary = stringResource(digestDayLabel(digest.day)),
position = Position.Middle,
onClick = onPickDay,
)
GroupedRow(
title = stringResource(R.string.settings_digest_time),
summary = settingsTimeOfDay(digest.timeMinutes),
position = Position.Middle,
onClick = onPickTime,
)
GroupedRow(
title = stringResource(R.string.settings_notification_sound),
summary = if (blocked) {
stringResource(R.string.settings_notifications_blocked_hint)
} else {
stringResource(R.string.settings_digest_sound_hint)
},
position = Position.Bottom,
trailing = { ExternalLinkIcon() },
onClick = onOpenSound,
)
val requester = remember { BringIntoViewRequester() }
Column(Modifier.bringIntoViewRequester(requester)) {
GroupedSwitchRow(
title = stringResource(R.string.settings_digest),
checked = digest.enabled,
onCheckedChange = onEnable,
summary = if (digest.enabled) {
stringResource(
R.string.settings_digest_summary,
stringResource(digestDayLabel(digest.day)),
settingsTimeOfDay(digest.timeMinutes),
)
} else {
stringResource(R.string.settings_digest_hint)
},
position = if (digest.enabled) Position.Top else Position.Alone,
)
AnimatedVisibility(visible = digest.enabled, enter = expandEnter(), exit = collapseExit()) {
val settled = !transition.isRunning && transition.currentState == EnterExitState.Visible
LaunchedEffect(settled, reveal) {
if (settled && reveal) {
requester.bringIntoView()
onRevealed()
}
}
Column {
GroupedRow(
title = stringResource(R.string.settings_digest_day),
summary = stringResource(digestDayLabel(digest.day)),
position = Position.Middle,
onClick = onPickDay,
)
GroupedRow(
title = stringResource(R.string.settings_digest_time),
summary = settingsTimeOfDay(digest.timeMinutes),
position = Position.Middle,
onClick = onPickTime,
)
GroupedRow(
title = stringResource(R.string.settings_notification_sound),
summary = if (blocked) {
stringResource(R.string.settings_notifications_blocked_hint)
} else {
stringResource(R.string.settings_digest_sound_hint)
},
position = Position.Bottom,
trailing = { ExternalLinkIcon() },
onClick = onOpenSound,
)
}
}
}
}
@@ -39,9 +39,9 @@ internal fun EventInstance.openIntent(context: Context, source: CalendarView) =
source = source,
)
/** Opens [date]'s day view. */
/** Opens [date] in the app's agenda. */
internal fun openDayAction(context: Context, date: LocalDate) =
actionStartActivity(MainActivity.openDateIntent(context, date))
actionStartActivity(MainActivity.openDateIntent(context, date, CalendarView.Agenda))
/** An event's time on [day]: "All day", "Starts 14:00", "Ends 9:00" or "14:00 – 15:30". */
internal fun widgetTimeLabel(context: Context, event: EventInstance, day: LocalDate, is24Hour: Boolean): String =
@@ -33,6 +33,7 @@ import androidx.glance.text.Text
import androidx.glance.text.TextAlign
import androidx.glance.text.TextStyle
import de.jeanlucmakiola.calendula.MainActivity
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import de.jeanlucmakiola.calendula.widget.CalendulaWidgetReceiver
import de.jeanlucmakiola.calendula.widget.CalendulaWidgetRoot
import de.jeanlucmakiola.calendula.widget.WidgetAppearance
@@ -98,7 +99,7 @@ internal fun DateWidgetContent(today: LocalDate, appearance: WidgetAppearance, a
Column(
modifier = GlanceModifier
.fillMaxSize()
.clickable(actionStartActivity(MainActivity.openDateIntent(context, today)))
.clickable(actionStartActivity(MainActivity.openDateIntent(context, today, CalendarView.Day)))
.semantics { contentDescription = label },
horizontalAlignment = Alignment.CenterHorizontally,
verticalAlignment = Alignment.CenterVertically,
@@ -14,6 +14,7 @@ import de.jeanlucmakiola.calendula.MainActivity
import de.jeanlucmakiola.calendula.R
import de.jeanlucmakiola.calendula.domain.EventInstance
import de.jeanlucmakiola.calendula.domain.isCrossedOut
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import de.jeanlucmakiola.calendula.ui.common.eventFill
import de.jeanlucmakiola.calendula.ui.common.eventInk
import de.jeanlucmakiola.floret.glance.RemoteColor
@@ -160,7 +161,7 @@ private fun span(text: String, span: Any): CharSequence =
private fun openDayIntent(context: Context, date: LocalDate): PendingIntent = PendingIntent.getActivity(
context,
date.toEpochDays().toInt(),
MainActivity.openDateIntent(context, date),
MainActivity.openDateIntent(context, date, CalendarView.Month),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
)
@@ -415,7 +415,7 @@ private fun DayList(day: LocalDate, data: MonthDayData.Ready, preview: Boolean)
val events = groupAgendaDays(day, day, source.instances, zone).firstOrNull()?.events.orEmpty()
.let { all -> if (data.options.pastDisplay == PastEventDisplay.HIDE) all.filterNot { it.hasEnded(data.now) } else all }
val metrics = compactRowMetrics(data.options.textSize, context.resources.configuration.fontScale)
val openDay = actionStartActivity(MainActivity.openDateIntent(context, day))
val openDay = actionStartActivity(MainActivity.openDateIntent(context, day, CalendarView.Month))
Column(modifier = GlanceModifier.fillMaxSize()) {
val date = localizedDateFormatter(widgetLocale(), "EEEdMMM").format(day.toJavaLocalDate())
val label = when (day) {
@@ -245,7 +245,7 @@ private fun TodayPill(today: LocalDate) {
.fillMaxHeight()
.cornerRadius(PillWidth / 2)
.background(GlanceTheme.colors.primary)
.clickable(actionStartActivity(MainActivity.openDateIntent(context, today)))
.clickable(actionStartActivity(MainActivity.openDateIntent(context, today, CalendarView.Day)))
.semantics { contentDescription = localizedDateFormatter(locale, "EEEEdMMMM").format(today.toJavaLocalDate()) },
horizontalAlignment = Alignment.CenterHorizontally,
verticalAlignment = Alignment.CenterVertically,
@@ -46,6 +46,7 @@ import androidx.glance.text.TextStyle
import androidx.glance.unit.ColorProvider
import de.jeanlucmakiola.calendula.MainActivity
import de.jeanlucmakiola.calendula.R
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import de.jeanlucmakiola.calendula.ui.common.eventAccent
import de.jeanlucmakiola.calendula.ui.common.eventFill
import de.jeanlucmakiola.calendula.widget.CalendulaWidgetReceiver
@@ -154,7 +155,7 @@ private fun DayTile(date: LocalDate, data: DaysWidgetData.Ready) {
.fillMaxSize()
.cornerRadius(14.dp)
.background(container)
.clickable(actionStartActivity(MainActivity.openDateIntent(context, date)))
.clickable(actionStartActivity(MainActivity.openDateIntent(context, date, CalendarView.Week)))
.semantics {
contentDescription = if (colors.isEmpty()) label else context.resources.getQuantityString(
R.plurals.widget_day_with_events, events.size, label, events.size,
+1
View File
@@ -808,6 +808,7 @@
<string name="settings_fixed_reminder_hint">Added to new timed events, e.g. the evening before. It follows the event when you move it to another time.</string>
<!-- Daily summary notification (#459) -->
<string name="settings_digest">Daily summary</string>
<string name="settings_digest_turn_on">Turn on daily summary</string>
<string name="settings_digest_hint">One notification listing a day\'s events</string>
<!-- %1$s is settings_digest_day_today/tomorrow, %2$s a clock time. -->
<string name="settings_digest_summary">%1$s at %2$s</string>
@@ -1,48 +0,0 @@
package de.jeanlucmakiola.calendula.ui
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import org.junit.jupiter.api.Test
class WidgetNavRequestTest {
private val detail = LeaveTarget.Detail(1, 2, 3)
@Test
fun `a widget's day or event is what back leaves from`() {
assertThat(WidgetNavRequest.OpenDate("2026-11-25", fromWidget = true).leaveTarget).isEqualTo(LeaveTarget.View)
assertThat(WidgetNavRequest.OpenDate("2026-11-25", fromWidget = false).leaveTarget).isNull()
assertThat(WidgetNavRequest.OpenEvent(1, 2, 3, CalendarView.Agenda).leaveTarget).isEqualTo(detail)
assertThat(WidgetNavRequest.OpenEvent(1, 2, 3, CalendarView.Day).leaveTarget).isEqualTo(detail)
assertThat(WidgetNavRequest.OpenView(CalendarView.Month).leaveTarget).isNull()
assertThat(WidgetNavRequest.Create(null).leaveTarget).isNull()
}
@Test
fun `the target stays only while the views stay put`() {
val day = listOf(CalendarView.Week, CalendarView.Day)
assertThat(LeaveTarget.View.afterMove(day, day.toList())).isEqualTo(LeaveTarget.View)
assertThat(LeaveTarget.View.afterMove(day, listOf(CalendarView.Week))).isNull()
assertThat(detail.afterMove(day, day + CalendarView.Month)).isNull()
assertThat(null.afterMove(day, day)).isNull()
}
@Test
fun `a widget's detail is dropped once it closes or another opens`() {
assertThat(detail.afterDetail(longArrayOf(1, 2, 3))).isEqualTo(detail)
assertThat(detail.afterDetail(null)).isNull()
assertThat(detail.afterDetail(longArrayOf(4, 5, 6))).isNull()
// A widget's day keeps its target under an in-app detail.
assertThat(LeaveTarget.View.afterDetail(longArrayOf(4, 5, 6))).isEqualTo(LeaveTarget.View)
}
@Test
fun `back leaves only from the widget's own day or detail`() {
assertThat(LeaveTarget.View.leaves(detail = null, overlayVisible = false)).isTrue()
assertThat(LeaveTarget.View.leaves(detail = longArrayOf(4, 5, 6), overlayVisible = true)).isFalse()
assertThat(detail.leaves(detail = longArrayOf(1, 2, 3), overlayVisible = true)).isTrue()
assertThat(detail.leaves(detail = longArrayOf(4, 5, 6), overlayVisible = true)).isFalse()
assertThat(detail.leaves(detail = null, overlayVisible = false)).isFalse()
assertThat(null.leaves(detail = null, overlayVisible = false)).isFalse()
}
}
@@ -6,8 +6,8 @@ import org.junit.jupiter.api.Test
/**
* The pure back-stack rules behind [CalendarHost]'s top-level navigation:
* the home view is always the bottom, a lateral move keeps the stack one deep,
* and a date tap drills the day view on top. Verifies the back sequences, e.g.
* agenda → day → back → agenda → back → home.
* and a date tap drills the day view on top. Verifies the back sequences the
* widget-UX fix promises (e.g. agenda widget → day → back → agenda → back → home).
*/
class ViewBackStackTest {
@@ -74,8 +74,8 @@ class ViewBackStackTest {
}
@Test
fun `a day tapped in a widget event's view backs out to it, then home`() {
// Agenda widget event tap roots [Week, Agenda]; a day tapped there drills on top.
fun `agenda widget date tap backs out agenda then home`() {
// openDate(source = Agenda): root in Agenda over the Week home, then drill.
val stack = viewBaseStack(CalendarView.Week, CalendarView.Agenda).drillToDay()
assertThat(stack)
.containsExactly(CalendarView.Week, CalendarView.Agenda, CalendarView.Day)
@@ -86,11 +86,11 @@ class ViewBackStackTest {
}
@Test
fun `a date launch drills the day over the home view only`() {
assertThat(listOf(CalendarView.Week).drillToDay())
.containsExactly(CalendarView.Week, CalendarView.Day)
.inOrder()
assertThat(listOf(CalendarView.Day).drillToDay()).containsExactly(CalendarView.Day)
fun `month widget date tap backs out month then home`() {
val stack = viewBaseStack(CalendarView.Week, CalendarView.Month).drillToDay()
assertThat(stack.last()).isEqualTo(CalendarView.Day)
assertThat(stack.dropLast(1).last()).isEqualTo(CalendarView.Month)
assertThat(stack.first()).isEqualTo(CalendarView.Week)
}
@Test