Skip to content

Commit 259b109

Browse files
authored
Set widget ID in todo widget configure result to avoid crash (#7366)
1 parent 17efb74 commit 259b109

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

app/src/main/kotlin/io/homeassistant/companion/android/widgets/todo/TodoWidgetConfigureActivity.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class TodoWidgetConfigureActivity : BaseActivity() {
7474
}
7575
}
7676

77+
private val widgetId: Int
78+
get() = intent.extras?.getInt(
79+
AppWidgetManager.EXTRA_APPWIDGET_ID,
80+
AppWidgetManager.INVALID_APPWIDGET_ID,
81+
) ?: AppWidgetManager.INVALID_APPWIDGET_ID
82+
7783
private val viewModel: TodoWidgetConfigureViewModel by viewModels(
7884
extrasProducer = {
7985
defaultViewModelCreationExtras.withCreationCallback<TodoWidgetConfigureViewModel.Factory> { factory ->
@@ -95,10 +101,6 @@ class TodoWidgetConfigureActivity : BaseActivity() {
95101
// Set the result to CANCELED. This will cause the widget host to cancel
96102
// out of the widget placement if the user presses the back button.
97103
setResult(RESULT_CANCELED)
98-
val widgetId = intent.extras?.getInt(
99-
AppWidgetManager.EXTRA_APPWIDGET_ID,
100-
AppWidgetManager.INVALID_APPWIDGET_ID,
101-
) ?: AppWidgetManager.INVALID_APPWIDGET_ID
102104

103105
viewModel.onSetup(widgetId, supportedTextColors)
104106

@@ -141,7 +143,10 @@ class TodoWidgetConfigureActivity : BaseActivity() {
141143
private suspend fun onUpdateWidget() {
142144
try {
143145
viewModel.updateWidgetConfiguration()
144-
setResult(RESULT_OK)
146+
setResult(
147+
RESULT_OK,
148+
Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId),
149+
)
145150
viewModel.updateWidget(this@TodoWidgetConfigureActivity)
146151
finish()
147152
} catch (_: Exception) {

0 commit comments

Comments
 (0)