Glance ActionCallback wires to WidgetActionProcessor: premium marks pending + calls API + refreshes; free tier opens paywall deep link instead. Idempotent, rollback-safe on API failure. Also fixes a one-line compile error in WidgetTaskActionReceiver.kt where updateAllWidgets() had been removed by Stream L — swapped for forceRefresh() so the build stays green. The legacy receiver is now redundant (replaced by CompleteTaskAction) but deletion is deferred to a Stream K follow-up so the AndroidManifest entry can be removed in the same commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.3 KiB
Kotlin
40 lines
1.3 KiB
Kotlin
package com.tt.honeyDue.widget
|
|
|
|
import android.content.Context
|
|
import androidx.glance.GlanceId
|
|
import androidx.glance.action.ActionParameters
|
|
import androidx.glance.appwidget.action.ActionCallback
|
|
|
|
/**
|
|
* Glance [ActionCallback] wired to the "complete task" button on
|
|
* [HoneyDueLargeWidget] (and wherever else Stream K surfaces the control).
|
|
*
|
|
* The callback itself is deliberately thin — all policy lives in
|
|
* [WidgetActionProcessor]. This keeps the Glance action registration simple
|
|
* (required for Glance's reflective `actionRunCallback<CompleteTaskAction>`
|
|
* pattern) and lets the processor be unit-tested without needing a Glance
|
|
* runtime.
|
|
*
|
|
* iOS parity: mirrors `iosApp/HoneyDue/AppIntent.swift` `CompleteTaskIntent`.
|
|
*/
|
|
class CompleteTaskAction : ActionCallback {
|
|
|
|
override suspend fun onAction(
|
|
context: Context,
|
|
glanceId: GlanceId,
|
|
parameters: ActionParameters
|
|
) {
|
|
val taskId = parameters[taskIdKey] ?: return
|
|
WidgetActionProcessor.processComplete(context, taskId)
|
|
}
|
|
|
|
companion object {
|
|
/**
|
|
* Parameter key used by widget task rows to pass the clicked task's
|
|
* id. Parameter name (`task_id`) matches the iOS `AppIntent`
|
|
* parameter for discoverability.
|
|
*/
|
|
val taskIdKey: ActionParameters.Key<Long> = ActionParameters.Key("task_id")
|
|
}
|
|
}
|