From 2a0afb33501eeb8a2684d8564eaf9bf00bae9cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=C2=A0Koby=C5=82ko?= Date: Mon, 12 Aug 2024 00:16:15 +0200 Subject: [PATCH] Fix WidgetSettings activity launch mode --- feature/widget/src/main/AndroidManifest.xml | 3 ++- .../widget/ui/settings/WidgetSettingsActivity.kt | 5 +---- .../feature/widget/ui/settings/WidgetSettingsScreen.kt | 10 ++++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/feature/widget/src/main/AndroidManifest.xml b/feature/widget/src/main/AndroidManifest.xml index 9bc268fb..49c8a14f 100644 --- a/feature/widget/src/main/AndroidManifest.xml +++ b/feature/widget/src/main/AndroidManifest.xml @@ -5,7 +5,8 @@ + android:label="Widget Setup" + android:launchMode="singleInstance"> diff --git a/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsActivity.kt b/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsActivity.kt index 05d20dfa..cbd1f8be 100644 --- a/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsActivity.kt +++ b/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsActivity.kt @@ -33,9 +33,6 @@ class WidgetSettingsActivity : ComponentActivity(), AuthAware { AppWidgetManager.INVALID_APPWIDGET_ID ) ?: AppWidgetManager.INVALID_APPWIDGET_ID - val resultValue = Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) - setResult(Activity.RESULT_CANCELED, resultValue) - authTracker.onWidgetSettingsScreen() lifecycle.addObserver( @@ -52,7 +49,7 @@ class WidgetSettingsActivity : ComponentActivity(), AuthAware { appWidgetId = appWidgetId, ) { setResult(Activity.RESULT_OK, Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)) - finish() + finishAndRemoveTask() } } } diff --git a/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsScreen.kt b/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsScreen.kt index 6fd499f0..ae7212e7 100644 --- a/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsScreen.kt +++ b/feature/widget/src/main/java/com/twofasapp/feature/widget/ui/settings/WidgetSettingsScreen.kt @@ -1,5 +1,6 @@ package com.twofasapp.feature.widget.ui.settings +import androidx.activity.compose.BackHandler import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth @@ -26,6 +27,7 @@ import com.twofasapp.designsystem.common.TwCircularProgressIndicator import com.twofasapp.designsystem.common.TwSwitch import com.twofasapp.designsystem.common.TwTextButton import com.twofasapp.designsystem.common.TwTopAppBar +import com.twofasapp.designsystem.ktx.currentActivity import com.twofasapp.designsystem.service.DsServiceSimple import com.twofasapp.designsystem.service.asState import com.twofasapp.feature.widget.GlanceWidget @@ -40,9 +42,13 @@ internal fun WidgetSettingsScreen( onSuccess: () -> Unit, ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() - val context = LocalContext.current + val activity = LocalContext.currentActivity val scope = rememberCoroutineScope() + BackHandler { + activity.finishAndRemoveTask() + } + LaunchedEffect(Unit) { viewModel.updateAppWidgetId(appWidgetId) } @@ -52,7 +58,7 @@ internal fun WidgetSettingsScreen( onToggleService = { viewModel.toggleService(it) }, onSave = { scope.launch { - GlanceWidget().updateAll(context) + GlanceWidget().updateAll(activity) viewModel.save() onSuccess() }