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() }