Fix clearing database freezes the app (#8492)
This commit is contained in:
parent
d0236aaecf
commit
6ce54eb845
@ -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<ClearDatabaseScreenMod
|
||||
}
|
||||
}
|
||||
|
||||
fun removeMangaBySourceId() {
|
||||
val state = state.value as? State.Ready ?: return
|
||||
suspend fun removeMangaBySourceId() = withNonCancellableContext {
|
||||
val state = state.value as? State.Ready ?: return@withNonCancellableContext
|
||||
database.mangasQueries.deleteMangasNotInLibraryBySourceIds(state.selection)
|
||||
database.historyQueries.removeResettedHistory()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user