From 85d72ad051895859590bf0e89f48f93388ebc807 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 19 Jul 2026 12:18:47 +0200 Subject: [PATCH] refactor(views): extract shared TodayAction top-bar button Collapse the today icon-button block that was copy-pasted into all four calendar top bars (Week/Month/Day/Agenda) into one TodayAction composable in ui/common. No behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../calendula/ui/agenda/AgendaScreen.kt | 11 ++------ .../calendula/ui/common/TodayAction.kt | 26 +++++++++++++++++++ .../calendula/ui/day/DayScreen.kt | 11 ++------ .../calendula/ui/month/MonthScreen.kt | 11 ++------ .../calendula/ui/week/WeekScreen.kt | 11 ++------ 5 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TodayAction.kt diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaScreen.kt index 39817c7..1b648fb 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/agenda/AgendaScreen.kt @@ -22,7 +22,6 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Coffee import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.filled.Today import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card import androidx.compose.material3.DrawerValue @@ -66,6 +65,7 @@ import de.jeanlucmakiola.calendula.ui.common.agendaRangeLabel import de.jeanlucmakiola.floret.identity.animateItemMotion import de.jeanlucmakiola.calendula.ui.common.CalendarDrawer import de.jeanlucmakiola.calendula.ui.common.CalendarFabColumn +import de.jeanlucmakiola.calendula.ui.common.TodayAction import de.jeanlucmakiola.calendula.ui.common.CalendarFailure import de.jeanlucmakiola.calendula.ui.common.CalendarView import de.jeanlucmakiola.calendula.ui.common.IMPLEMENTED_VIEWS @@ -528,14 +528,7 @@ private fun AgendaTopBar( } }, actions = { - if (showTodayButton) { - IconButton(onClick = onToday) { - Icon( - imageVector = Icons.Default.Today, - contentDescription = stringResource(R.string.today_jump_action), - ) - } - } + TodayAction(show = showTodayButton, onToday = onToday) IconButton(onClick = onOpenSearch) { Icon( imageVector = Icons.Default.Search, diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TodayAction.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TodayAction.kt new file mode 100644 index 0000000..1234bb1 --- /dev/null +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TodayAction.kt @@ -0,0 +1,26 @@ +package de.jeanlucmakiola.calendula.ui.common + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Today +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import de.jeanlucmakiola.calendula.R + +/** + * The top-bar "jump to today" icon button, shared by every calendar view's app + * bar (#60). Shown in place of the fade-in FAB pill when the user moves the + * today control into the toolbar; renders nothing when [show] is false, so it + * drops straight into an app bar's `actions` slot without a wrapping condition. + */ +@Composable +fun TodayAction(show: Boolean, onToday: () -> Unit) { + if (!show) return + IconButton(onClick = onToday) { + Icon( + imageVector = Icons.Default.Today, + contentDescription = stringResource(R.string.today_jump_action), + ) + } +} diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/day/DayScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/day/DayScreen.kt index 8e750e1..4526677 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/day/DayScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/day/DayScreen.kt @@ -27,7 +27,6 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.filled.Today import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.DrawerValue @@ -72,6 +71,7 @@ import de.jeanlucmakiola.calendula.domain.EventInstance import de.jeanlucmakiola.calendula.ui.common.formatCalendarTitle import de.jeanlucmakiola.calendula.ui.common.CalendarDrawer import de.jeanlucmakiola.calendula.ui.common.CalendarFabColumn +import de.jeanlucmakiola.calendula.ui.common.TodayAction import de.jeanlucmakiola.calendula.ui.common.CalendarFailure import de.jeanlucmakiola.calendula.ui.common.CalendarView import de.jeanlucmakiola.calendula.ui.common.IMPLEMENTED_VIEWS @@ -401,14 +401,7 @@ private fun DayTopBar( } }, actions = { - if (showTodayButton) { - IconButton(onClick = onToday) { - Icon( - imageVector = Icons.Default.Today, - contentDescription = stringResource(R.string.today_jump_action), - ) - } - } + TodayAction(show = showTodayButton, onToday = onToday) IconButton(onClick = onOpenSearch) { Icon( imageVector = Icons.Default.Search, diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt index 6aa60f5..7f501dc 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt @@ -24,7 +24,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.filled.Today import androidx.compose.material3.DrawerValue import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -68,6 +67,7 @@ import de.jeanlucmakiola.calendula.domain.hasEnded import de.jeanlucmakiola.calendula.ui.common.formatCalendarTitle import de.jeanlucmakiola.calendula.ui.common.CalendarDrawer import de.jeanlucmakiola.calendula.ui.common.CalendarFabColumn +import de.jeanlucmakiola.calendula.ui.common.TodayAction import de.jeanlucmakiola.calendula.ui.common.CalendarFailure import de.jeanlucmakiola.calendula.ui.common.CalendarView import de.jeanlucmakiola.calendula.ui.common.IMPLEMENTED_VIEWS @@ -333,14 +333,7 @@ private fun MonthTopBar( } }, actions = { - if (showTodayButton) { - IconButton(onClick = onToday) { - Icon( - imageVector = Icons.Default.Today, - contentDescription = stringResource(R.string.today_jump_action), - ) - } - } + TodayAction(show = showTodayButton, onToday = onToday) IconButton(onClick = onOpenSearch) { Icon( imageVector = Icons.Default.Search, diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt index 141481a..bd44535 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt @@ -30,7 +30,6 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.filled.Today import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.DrawerValue @@ -81,6 +80,7 @@ import de.jeanlucmakiola.calendula.domain.hasEnded import de.jeanlucmakiola.calendula.ui.common.formatCalendarTitle import de.jeanlucmakiola.calendula.ui.common.CalendarDrawer import de.jeanlucmakiola.calendula.ui.common.CalendarFabColumn +import de.jeanlucmakiola.calendula.ui.common.TodayAction import de.jeanlucmakiola.calendula.ui.common.CalendarFailure import de.jeanlucmakiola.calendula.ui.common.CalendarView import de.jeanlucmakiola.calendula.ui.common.IMPLEMENTED_VIEWS @@ -434,14 +434,7 @@ private fun WeekTopBar( } }, actions = { - if (showTodayButton) { - IconButton(onClick = onToday) { - Icon( - imageVector = Icons.Default.Today, - contentDescription = stringResource(R.string.today_jump_action), - ) - } - } + TodayAction(show = showTodayButton, onToday = onToday) IconButton(onClick = onOpenSearch) { Icon( imageVector = Icons.Default.Search,