Fix WidgetSettings activity launch mode

This commit is contained in:
Rafał Kobyłko 2024-08-12 00:16:15 +02:00
parent 888dfcaa02
commit 2a0afb3350
3 changed files with 11 additions and 7 deletions

View File

@ -5,7 +5,8 @@
<activity
android:name=".ui.settings.WidgetSettingsActivity"
android:exported="true"
android:label="Widget Setup">
android:label="Widget Setup"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>

View File

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

View File

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