From f27b0e269d8180db32f3e0b2bbd82be438cb7a14 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 27 Jun 2026 16:30:27 +0200 Subject: [PATCH] fix(widget): refresh agenda widget when its range (or week start) changes The agenda widget only re-read agendaWidgetRange on the next data-change / midnight / periodic refresh (or re-placement), so a settings change appeared to do nothing until then. Push an updateAll from the settings setters: the agenda widget on an agenda-widget-range change, and both widgets on a week-start change (month weekday header + the agenda widget's "this week"). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../ui/settings/SettingsViewModel.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt index bc080ba..b55437a 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt @@ -1,9 +1,12 @@ package de.jeanlucmakiola.calendula.ui.settings +import android.content.Context import android.os.Build +import androidx.glance.appwidget.updateAll import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import dagger.hilt.android.qualifiers.ApplicationContext import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository import de.jeanlucmakiola.calendula.data.prefs.CalendarReminderOverride import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs @@ -14,6 +17,8 @@ import de.jeanlucmakiola.calendula.domain.CalendarSource import de.jeanlucmakiola.calendula.domain.EventFormField import de.jeanlucmakiola.calendula.ui.agenda.AgendaRange import de.jeanlucmakiola.calendula.ui.common.CalendarView +import de.jeanlucmakiola.calendula.widget.agenda.AgendaWidget +import de.jeanlucmakiola.calendula.widget.month.MonthWidget import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -28,6 +33,7 @@ import javax.inject.Inject class SettingsViewModel @Inject constructor( private val prefs: SettingsPrefs, repository: CalendarRepository, + @ApplicationContext private val appContext: Context, ) : ViewModel() { private val dynamicColorAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S @@ -139,7 +145,13 @@ class SettingsViewModel @Inject constructor( } fun setWeekStart(pref: WeekStartPref) { - viewModelScope.launch { prefs.setWeekStart(pref) } + viewModelScope.launch { + prefs.setWeekStart(pref) + // Both widgets depend on the week start (month weekday header; the + // agenda widget's "this week" range), so push a redraw. + AgendaWidget().updateAll(appContext) + MonthWidget().updateAll(appContext) + } } fun setAgendaScreenRange(range: AgendaRange) { @@ -147,7 +159,12 @@ class SettingsViewModel @Inject constructor( } fun setAgendaWidgetRange(range: AgendaRange) { - viewModelScope.launch { prefs.setAgendaWidgetRange(range) } + viewModelScope.launch { + prefs.setAgendaWidgetRange(range) + // Push the new range to the placed widget immediately, instead of + // waiting for the next data-change / midnight / periodic refresh. + AgendaWidget().updateAll(appContext) + } } fun setAgendaShowRangeBar(enabled: Boolean) {