Restrict raw database access to the data module
app no longer touches the database directly. Backup restore's queries move into a new RestoreRepository in :data, which restores a batch of entries all or nothing, stopping between entries if cancelled, as before. The remaining direct calls (excluded scanlators, clear database, backup creation, store and category restore) go through their repositories, and the database bindings move from AppBindings into :data.
This commit is contained in:
+6
-5
@@ -51,9 +51,9 @@ import mihon.icons.materialsymbols.rounded.FlipToBack
|
||||
import mihon.icons.materialsymbols.rounded.SelectAll
|
||||
import tachiyomi.core.common.util.lang.launchIO
|
||||
import tachiyomi.core.common.util.lang.launchUI
|
||||
import tachiyomi.core.common.util.lang.toLong
|
||||
import tachiyomi.core.common.util.lang.withNonCancellableContext
|
||||
import tachiyomi.data.Database
|
||||
import tachiyomi.domain.history.repository.HistoryRepository
|
||||
import tachiyomi.domain.manga.repository.MangaRepository
|
||||
import tachiyomi.domain.source.interactor.GetSourcesWithNonLibraryManga
|
||||
import tachiyomi.domain.source.model.Source
|
||||
import tachiyomi.domain.source.model.SourceWithCount
|
||||
@@ -229,7 +229,8 @@ class ClearDatabaseScreen : Screen() {
|
||||
@ViewModelKey
|
||||
@ContributesIntoMap(AppScope::class, binding = binding<ViewModel>())
|
||||
class ClearDatabaseViewModel(
|
||||
private val database: Database,
|
||||
private val mangaRepository: MangaRepository,
|
||||
private val historyRepository: HistoryRepository,
|
||||
private val getSourcesWithNonLibraryManga: GetSourcesWithNonLibraryManga,
|
||||
) : ViewModel() {
|
||||
|
||||
@@ -253,8 +254,8 @@ class ClearDatabaseViewModel(
|
||||
|
||||
suspend fun removeMangaBySourceId(keepReadManga: Boolean) = withNonCancellableContext {
|
||||
val state = state.value as? State.Ready ?: return@withNonCancellableContext
|
||||
database.mangasQueries.deleteNonLibraryManga(state.selection, keepReadManga.toLong())
|
||||
database.historyQueries.removeResettedHistory()
|
||||
mangaRepository.deleteNonLibraryManga(state.selection, keepReadManga)
|
||||
historyRepository.deleteResetHistory()
|
||||
}
|
||||
|
||||
fun toggleSelection(source: Source) = state.update { state ->
|
||||
|
||||
Reference in New Issue
Block a user