mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Migrate even more stuff to use SQLDelight
This commit is contained in:
parent
4af54a906a
commit
0934e7518b
3 changed files with 37 additions and 42 deletions
|
@ -6,9 +6,6 @@ import com.pushtorefresh.storio.sqlite.queries.Query
|
||||||
import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
||||||
import eu.kanade.tachiyomi.data.database.DbProvider
|
import eu.kanade.tachiyomi.data.database.DbProvider
|
||||||
import eu.kanade.tachiyomi.data.database.models.SourceIdMangaCount
|
import eu.kanade.tachiyomi.data.database.models.SourceIdMangaCount
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.MangaDateAddedPutResolver
|
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.MangaFavoritePutResolver
|
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.MangaTitlePutResolver
|
|
||||||
import eu.kanade.tachiyomi.data.database.resolvers.SourceIdMangaCountGetResolver
|
import eu.kanade.tachiyomi.data.database.resolvers.SourceIdMangaCountGetResolver
|
||||||
import eu.kanade.tachiyomi.data.database.tables.ChapterTable
|
import eu.kanade.tachiyomi.data.database.tables.ChapterTable
|
||||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||||
|
@ -78,24 +75,6 @@ interface MangaQueries : DbProvider {
|
||||||
|
|
||||||
fun insertManga(manga: Manga) = db.put().`object`(manga).prepare()
|
fun insertManga(manga: Manga) = db.put().`object`(manga).prepare()
|
||||||
|
|
||||||
// FIXME: Migrate to SQLDelight, on halt: used by StorIO's inTransaction
|
|
||||||
fun updateMangaFavorite(manga: Manga) = db.put()
|
|
||||||
.`object`(manga)
|
|
||||||
.withPutResolver(MangaFavoritePutResolver())
|
|
||||||
.prepare()
|
|
||||||
|
|
||||||
// FIXME: Migrate to SQLDelight, on halt: used by StorIO's inTransaction
|
|
||||||
fun updateMangaAdded(manga: Manga) = db.put()
|
|
||||||
.`object`(manga)
|
|
||||||
.withPutResolver(MangaDateAddedPutResolver())
|
|
||||||
.prepare()
|
|
||||||
|
|
||||||
// FIXME: Migrate to SQLDelight, on halt: used by StorIO's inTransaction
|
|
||||||
fun updateMangaTitle(manga: Manga) = db.put()
|
|
||||||
.`object`(manga)
|
|
||||||
.withPutResolver(MangaTitlePutResolver())
|
|
||||||
.prepare()
|
|
||||||
|
|
||||||
fun deleteMangasNotInLibraryBySourceIds(sourceIds: List<Long>) = db.delete()
|
fun deleteMangasNotInLibraryBySourceIds(sourceIds: List<Long>) = db.delete()
|
||||||
.byQuery(
|
.byQuery(
|
||||||
DeleteQuery.builder()
|
DeleteQuery.builder()
|
||||||
|
|
|
@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.ui.migration.MigrationFlags
|
import eu.kanade.tachiyomi.ui.migration.MigrationFlags
|
||||||
import eu.kanade.tachiyomi.util.system.launchNow
|
|
||||||
import eu.kanade.tachiyomi.util.system.launchUI
|
import eu.kanade.tachiyomi.util.system.launchUI
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -24,7 +23,11 @@ import kotlinx.coroutines.withContext
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import yokai.domain.chapter.interactor.GetChapter
|
||||||
import yokai.domain.library.custom.model.CustomMangaInfo.Companion.getMangaInfo
|
import yokai.domain.library.custom.model.CustomMangaInfo.Companion.getMangaInfo
|
||||||
|
import yokai.domain.manga.interactor.GetManga
|
||||||
|
import yokai.domain.manga.interactor.UpdateManga
|
||||||
|
import yokai.domain.manga.models.MangaUpdate
|
||||||
import yokai.domain.ui.UiPreferences
|
import yokai.domain.ui.UiPreferences
|
||||||
|
|
||||||
class MigrationProcessAdapter(
|
class MigrationProcessAdapter(
|
||||||
|
@ -32,12 +35,15 @@ class MigrationProcessAdapter(
|
||||||
) : FlexibleAdapter<MigrationProcessItem>(null, controller, true) {
|
) : FlexibleAdapter<MigrationProcessItem>(null, controller, true) {
|
||||||
|
|
||||||
private val db: DatabaseHelper by injectLazy()
|
private val db: DatabaseHelper by injectLazy()
|
||||||
|
|
||||||
|
private val getManga: GetManga by injectLazy()
|
||||||
|
|
||||||
var items: List<MigrationProcessItem> = emptyList()
|
var items: List<MigrationProcessItem> = emptyList()
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
val uiPreferences: UiPreferences by injectLazy()
|
val uiPreferences: UiPreferences by injectLazy()
|
||||||
val sourceManager: SourceManager by injectLazy()
|
val sourceManager: SourceManager by injectLazy()
|
||||||
val coverCache: CoverCache by injectLazy()
|
val coverCache: CoverCache by injectLazy()
|
||||||
val customMangaManager: CustomMangaManager by injectLazy()
|
private val customMangaManager: CustomMangaManager by injectLazy()
|
||||||
|
|
||||||
var showOutline = uiPreferences.outlineOnCovers().get()
|
var showOutline = uiPreferences.outlineOnCovers().get()
|
||||||
val menuItemListener: MigrationProcessInterface = controller
|
val menuItemListener: MigrationProcessInterface = controller
|
||||||
|
@ -80,9 +86,7 @@ class MigrationProcessAdapter(
|
||||||
val manga = migratingManga.manga
|
val manga = migratingManga.manga
|
||||||
if (manga.searchResult.initialized) {
|
if (manga.searchResult.initialized) {
|
||||||
val toMangaObj =
|
val toMangaObj =
|
||||||
db.getManga(manga.searchResult.get() ?: return@forEach)
|
getManga.awaitById(manga.searchResult.get() ?: return@forEach) ?: return@forEach
|
||||||
.executeAsBlocking()
|
|
||||||
?: return@forEach
|
|
||||||
val prevManga = manga.manga() ?: return@forEach
|
val prevManga = manga.manga() ?: return@forEach
|
||||||
val source = sourceManager.get(toMangaObj.source) ?: return@forEach
|
val source = sourceManager.get(toMangaObj.source) ?: return@forEach
|
||||||
val prevSource = sourceManager.get(prevManga.source)
|
val prevSource = sourceManager.get(prevManga.source)
|
||||||
|
@ -103,9 +107,7 @@ class MigrationProcessAdapter(
|
||||||
launchUI {
|
launchUI {
|
||||||
val manga = getItem(position)?.manga ?: return@launchUI
|
val manga = getItem(position)?.manga ?: return@launchUI
|
||||||
db.inTransaction {
|
db.inTransaction {
|
||||||
val toMangaObj =
|
val toMangaObj = getManga.awaitById(manga.searchResult.get() ?: return@launchUI) ?: return@launchUI
|
||||||
db.getManga(manga.searchResult.get() ?: return@launchUI).executeAsBlocking()
|
|
||||||
?: return@launchUI
|
|
||||||
val prevManga = manga.manga() ?: return@launchUI
|
val prevManga = manga.manga() ?: return@launchUI
|
||||||
val source = sourceManager.get(toMangaObj.source) ?: return@launchUI
|
val source = sourceManager.get(toMangaObj.source) ?: return@launchUI
|
||||||
val prevSource = sourceManager.get(prevManga.source)
|
val prevSource = sourceManager.get(prevManga.source)
|
||||||
|
@ -131,7 +133,7 @@ class MigrationProcessAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Migrate to SQLDelight, on halt: in StorIO transaction
|
// FIXME: Migrate to SQLDelight, on halt: in StorIO transaction
|
||||||
private fun migrateMangaInternal(
|
private suspend fun migrateMangaInternal(
|
||||||
prevSource: Source?,
|
prevSource: Source?,
|
||||||
source: Source,
|
source: Source,
|
||||||
prevManga: Manga,
|
prevManga: Manga,
|
||||||
|
@ -146,7 +148,7 @@ class MigrationProcessAdapter(
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
// FIXME: Migrate to SQLDelight, on halt: in StorIO transaction
|
// FIXME: Migrate to SQLDelight, on halt: in StorIO transaction
|
||||||
fun migrateMangaInternal(
|
suspend fun migrateMangaInternal(
|
||||||
flags: Int,
|
flags: Int,
|
||||||
db: DatabaseHelper,
|
db: DatabaseHelper,
|
||||||
enhancedServices: List<EnhancedTrackService>,
|
enhancedServices: List<EnhancedTrackService>,
|
||||||
|
@ -157,13 +159,16 @@ class MigrationProcessAdapter(
|
||||||
prevManga: Manga,
|
prevManga: Manga,
|
||||||
manga: Manga,
|
manga: Manga,
|
||||||
replace: Boolean,
|
replace: Boolean,
|
||||||
|
getChapter: GetChapter = Injekt.get(),
|
||||||
|
//insertChapter: InsertChapter = Injekt.get(),
|
||||||
|
updateManga: UpdateManga = Injekt.get(),
|
||||||
) {
|
) {
|
||||||
// Update chapters read
|
// Update chapters read
|
||||||
if (MigrationFlags.hasChapters(flags)) {
|
if (MigrationFlags.hasChapters(flags)) {
|
||||||
val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking()
|
val prevMangaChapters = getChapter.awaitAll(prevManga.id!!, false)
|
||||||
val maxChapterRead =
|
val maxChapterRead =
|
||||||
prevMangaChapters.filter { it.read }.maxOfOrNull { it.chapter_number } ?: 0f
|
prevMangaChapters.filter { it.read }.maxOfOrNull { it.chapter_number } ?: 0f
|
||||||
val dbChapters = db.getChapters(manga).executeAsBlocking()
|
val dbChapters = getChapter.awaitAll(manga.id!!, false)
|
||||||
val prevHistoryList = db.getHistoryByMangaId(prevManga.id!!).executeAsBlocking()
|
val prevHistoryList = db.getHistoryByMangaId(prevManga.id!!).executeAsBlocking()
|
||||||
val historyList = mutableListOf<History>()
|
val historyList = mutableListOf<History>()
|
||||||
for (chapter in dbChapters) {
|
for (chapter in dbChapters) {
|
||||||
|
@ -188,6 +193,8 @@ class MigrationProcessAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// FIXME: Probably gonna mess with StorIO's transaction since it's also uses transaction
|
||||||
|
//insertChapter.awaitBulk(dbChapters)
|
||||||
db.insertChapters(dbChapters).executeAsBlocking()
|
db.insertChapters(dbChapters).executeAsBlocking()
|
||||||
db.upsertHistoryLastRead(historyList).executeAsBlocking()
|
db.upsertHistoryLastRead(historyList).executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
@ -217,7 +224,12 @@ class MigrationProcessAdapter(
|
||||||
// Update favorite status
|
// Update favorite status
|
||||||
if (replace) {
|
if (replace) {
|
||||||
prevManga.favorite = false
|
prevManga.favorite = false
|
||||||
db.updateMangaFavorite(prevManga).executeAsBlocking()
|
updateManga.await(
|
||||||
|
MangaUpdate(
|
||||||
|
id = manga.id!!,
|
||||||
|
favorite = manga.favorite,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
manga.favorite = true
|
manga.favorite = true
|
||||||
if (replace) {
|
if (replace) {
|
||||||
|
@ -230,18 +242,21 @@ class MigrationProcessAdapter(
|
||||||
if (MigrationFlags.hasCustomMangaInfo(flags)) {
|
if (MigrationFlags.hasCustomMangaInfo(flags)) {
|
||||||
if (coverCache.getCustomCoverFile(prevManga).exists()) {
|
if (coverCache.getCustomCoverFile(prevManga).exists()) {
|
||||||
coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga).inputStream())
|
coverCache.setCustomCoverToCache(manga, coverCache.getCustomCoverFile(prevManga).inputStream())
|
||||||
launchNow { manga.updateCoverLastModified() }
|
manga.updateCoverLastModified()
|
||||||
}
|
}
|
||||||
customMangaManager.getManga(prevManga)?.let { customManga ->
|
customMangaManager.getManga(prevManga)?.let { customManga ->
|
||||||
launchNow {
|
customMangaManager.updateMangaInfo(prevManga.id, manga.id, customManga.getMangaInfo())
|
||||||
customMangaManager.updateMangaInfo(prevManga.id, manga.id, customManga.getMangaInfo())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.updateMangaFavorite(manga).executeAsBlocking()
|
updateManga.await(
|
||||||
db.updateMangaAdded(manga).executeAsBlocking()
|
MangaUpdate(
|
||||||
db.updateMangaTitle(manga).executeAsBlocking()
|
id = manga.id!!,
|
||||||
|
favorite = manga.favorite,
|
||||||
|
dateAdded = manga.date_added,
|
||||||
|
title = manga.title,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcessAdapter
|
||||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay
|
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay
|
||||||
import eu.kanade.tachiyomi.util.lang.asButton
|
import eu.kanade.tachiyomi.util.lang.asButton
|
||||||
import eu.kanade.tachiyomi.util.system.launchIO
|
import eu.kanade.tachiyomi.util.system.launchIO
|
||||||
|
import eu.kanade.tachiyomi.util.system.launchUI
|
||||||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
||||||
import eu.kanade.tachiyomi.util.system.setCustomTitleAndMessage
|
import eu.kanade.tachiyomi.util.system.setCustomTitleAndMessage
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
|
@ -329,7 +330,7 @@ private fun showAddDuplicateDialog(
|
||||||
val source = sourceManager.getOrStub(libraryManga.source)
|
val source = sourceManager.getOrStub(libraryManga.source)
|
||||||
|
|
||||||
val titles by lazy { MigrationFlags.titles(activity, libraryManga) }
|
val titles by lazy { MigrationFlags.titles(activity, libraryManga) }
|
||||||
fun migrateManga(mDialog: DialogInterface, replace: Boolean) {
|
fun migrateManga(mDialog: DialogInterface, replace: Boolean) = launchUI {
|
||||||
val listView = (mDialog as AlertDialog).listView
|
val listView = (mDialog as AlertDialog).listView
|
||||||
val enabled = titles.indices.map { listView.isItemChecked(it) }.toTypedArray()
|
val enabled = titles.indices.map { listView.isItemChecked(it) }.toTypedArray()
|
||||||
val flags = MigrationFlags.getFlagsFromPositions(enabled, libraryManga)
|
val flags = MigrationFlags.getFlagsFromPositions(enabled, libraryManga)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue