Redraw the tapped widget by its own id, not updateAll (#18)
This commit is contained in:
@@ -24,7 +24,6 @@ import androidx.glance.appwidget.cornerRadius
|
||||
import androidx.glance.appwidget.lazy.LazyColumn
|
||||
import androidx.glance.appwidget.lazy.items
|
||||
import androidx.glance.appwidget.provideContent
|
||||
import androidx.glance.appwidget.updateAll
|
||||
import androidx.glance.background
|
||||
import androidx.glance.currentState
|
||||
import androidx.glance.state.PreferencesGlanceStateDefinition
|
||||
@@ -135,10 +134,14 @@ class AgendaWidget : GlanceAppWidget() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Re-reads the calendar and redraws the widget (header refresh button). */
|
||||
/**
|
||||
* Re-reads the calendar and redraws the widget (header refresh button). Targets
|
||||
* the tapped widget's own id rather than `updateAll`, whose provider-name lookup
|
||||
* is empty in a process a tap woke from cold — see `ShiftMonthAction` (#18).
|
||||
*/
|
||||
class RefreshAgendaAction : ActionCallback {
|
||||
override suspend fun onAction(context: Context, glanceId: GlanceId, parameters: ActionParameters) {
|
||||
AgendaWidget().updateAll(context.applicationContext)
|
||||
AgendaWidget().update(context.applicationContext, glanceId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import androidx.glance.appwidget.action.actionStartActivity
|
||||
import androidx.glance.appwidget.cornerRadius
|
||||
import androidx.glance.appwidget.provideContent
|
||||
import androidx.glance.appwidget.state.updateAppWidgetState
|
||||
import androidx.glance.appwidget.updateAll
|
||||
import androidx.glance.background
|
||||
import androidx.glance.currentState
|
||||
import androidx.glance.layout.Alignment
|
||||
@@ -118,7 +117,17 @@ class MonthWidget : GlanceAppWidget() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Step the displayed month by the `delta` action parameter (±1). */
|
||||
/**
|
||||
* Step the displayed month by the `delta` action parameter (±1).
|
||||
*
|
||||
* Redrawn through [GlanceAppWidget.update] with the id the callback was handed,
|
||||
* never `updateAll`. `updateAll` resolves its targets through the provider-name
|
||||
* -> app-widget-id map Glance persists for the *receiver*, and in a process that
|
||||
* has done nothing else yet — the one a tap wakes after a reboot — that lookup
|
||||
* comes back empty and the redraw is dropped: the state write lands, nothing
|
||||
* recomposes, and the arrows read as dead until something else opens the app and
|
||||
* starts a session (#18). The tapped widget's own id needs no lookup.
|
||||
*/
|
||||
class ShiftMonthAction : ActionCallback {
|
||||
override suspend fun onAction(context: Context, glanceId: GlanceId, parameters: ActionParameters) {
|
||||
val delta = parameters[deltaKey] ?: 0
|
||||
@@ -126,7 +135,7 @@ class ShiftMonthAction : ActionCallback {
|
||||
val cur = prefs[MONTH_INDEX_KEY] ?: currentMonthIndex(systemZone())
|
||||
prefs[MONTH_INDEX_KEY] = cur + delta
|
||||
}
|
||||
MonthWidget().updateAll(context.applicationContext)
|
||||
MonthWidget().update(context.applicationContext, glanceId)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -134,11 +143,11 @@ class ShiftMonthAction : ActionCallback {
|
||||
}
|
||||
}
|
||||
|
||||
/** Jump the displayed month back to the current month. */
|
||||
/** Jump the displayed month back to the current month. See [ShiftMonthAction]. */
|
||||
class ResetMonthAction : ActionCallback {
|
||||
override suspend fun onAction(context: Context, glanceId: GlanceId, parameters: ActionParameters) {
|
||||
updateAppWidgetState(context, glanceId) { prefs -> prefs.remove(MONTH_INDEX_KEY) }
|
||||
MonthWidget().updateAll(context.applicationContext)
|
||||
MonthWidget().update(context.applicationContext, glanceId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user