diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt index a1442f711..394aa1dd7 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt @@ -20,6 +20,7 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -47,6 +48,8 @@ import eu.kanade.presentation.util.selectedBackground import eu.kanade.tachiyomi.Database import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.lang.launchIO +import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.lang.withNonCancellableContext import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.update @@ -61,6 +64,7 @@ class ClearDatabaseScreen : Screen { val navigator = LocalNavigator.currentOrThrow val model = rememberScreenModel { ClearDatabaseScreenModel() } val state by model.state.collectAsState() + val scope = rememberCoroutineScope() when (val s = state) { is ClearDatabaseScreenModel.State.Loading -> LoadingScreen() @@ -71,10 +75,12 @@ class ClearDatabaseScreen : Screen { confirmButton = { TextButton( onClick = { - model.removeMangaBySourceId() - model.clearSelection() - model.hideConfirmation() - context.toast(R.string.clear_database_completed) + scope.launchUI { + model.removeMangaBySourceId() + model.clearSelection() + model.hideConfirmation() + context.toast(R.string.clear_database_completed) + } }, ) { Text(text = stringResource(android.R.string.ok)) @@ -217,8 +223,8 @@ private class ClearDatabaseScreenModel : StateScreenModel