mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(db): Migrate insertManga queries to SQLDelight
This commit is contained in:
parent
aae9a68c8b
commit
333a7eea68
4 changed files with 62 additions and 14 deletions
|
@ -21,8 +21,6 @@ interface MangaQueries : DbProvider {
|
|||
)
|
||||
.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)
|
||||
|
|
|
@ -452,7 +452,7 @@ class MangaDetailsPresenter(
|
|||
manga.copyFrom(networkManga)
|
||||
manga.initialized = true
|
||||
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
updateManga.await(manga.toMangaUpdate())
|
||||
|
||||
launchIO {
|
||||
val request =
|
||||
|
|
|
@ -37,7 +37,6 @@ import eu.kanade.tachiyomi.ui.migration.SearchController
|
|||
import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.toNormalized
|
||||
import eu.kanade.tachiyomi.util.system.e
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import eu.kanade.tachiyomi.util.system.getParcelableCompat
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
|
@ -53,6 +52,8 @@ import eu.kanade.tachiyomi.util.view.setPositiveButton
|
|||
import eu.kanade.tachiyomi.util.view.setTextColorAlpha
|
||||
import eu.kanade.tachiyomi.util.view.setTitle
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -64,10 +65,9 @@ import kotlinx.coroutines.sync.Semaphore
|
|||
import kotlinx.coroutines.sync.withPermit
|
||||
import kotlinx.coroutines.withContext
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import java.util.concurrent.atomic.*
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import android.R as AR
|
||||
|
||||
class MigrationListController(bundle: Bundle? = null) :
|
||||
|
@ -88,6 +88,8 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||
val config = args.getParcelableCompat(CONFIG_EXTRA, MigrationProcedureConfig::class.java)
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
|
@ -269,7 +271,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||
sourceManager.getOrStub(result.source).getMangaDetails(result)
|
||||
result.copyFrom(newManga)
|
||||
|
||||
db.insertManga(result).executeAsBlocking()
|
||||
updateManga.await(result.toMangaUpdate())
|
||||
} catch (e: CancellationException) {
|
||||
// Ignore cancellations
|
||||
throw e
|
||||
|
@ -385,7 +387,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||
sourceManager.getOrStub(result.source).getMangaDetails(result)
|
||||
result.copyFrom(newManga)
|
||||
|
||||
db.insertManga(result).executeAsBlocking()
|
||||
updateManga.await(result.toMangaUpdate())
|
||||
} catch (e: CancellationException) {
|
||||
// Ignore cancellations
|
||||
throw e
|
||||
|
|
|
@ -49,6 +49,8 @@ import uy.kohesive.injekt.api.get
|
|||
import yokai.domain.category.interactor.GetCategories
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.domain.manga.models.MangaUpdate
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import android.R as AR
|
||||
|
@ -156,8 +158,9 @@ fun Manga.addOrRemoveToFavorites(
|
|||
onMangaAdded: (Pair<Long, Boolean>?) -> Unit,
|
||||
onMangaMoved: () -> Unit,
|
||||
onMangaDeleted: () -> Unit,
|
||||
getManga: GetManga = Injekt.get(),
|
||||
getCategories: GetCategories = Injekt.get(),
|
||||
getManga: GetManga = Injekt.get(),
|
||||
updateManga: UpdateManga = Injekt.get(),
|
||||
): Snackbar? {
|
||||
if (!favorite) {
|
||||
if (checkForDupes) {
|
||||
|
@ -209,7 +212,16 @@ fun Manga.addOrRemoveToFavorites(
|
|||
favorite = true
|
||||
date_added = Date().time
|
||||
autoAddTrack(db, onMangaMoved)
|
||||
db.insertManga(this).executeAsBlocking()
|
||||
// FIXME: Don't do blocking
|
||||
runBlocking {
|
||||
updateManga.await(
|
||||
MangaUpdate(
|
||||
id = this@addOrRemoveToFavorites.id!!,
|
||||
favorite = true,
|
||||
dateAdded = this@addOrRemoveToFavorites.date_added,
|
||||
)
|
||||
)
|
||||
}
|
||||
val mc = MangaCategory.create(this, defaultCategory)
|
||||
db.setMangaCategories(listOf(mc), listOf(this))
|
||||
(activity as? MainActivity)?.showNotificationPermissionPrompt()
|
||||
|
@ -227,7 +239,16 @@ fun Manga.addOrRemoveToFavorites(
|
|||
favorite = true
|
||||
date_added = Date().time
|
||||
autoAddTrack(db, onMangaMoved)
|
||||
db.insertManga(this).executeAsBlocking()
|
||||
// FIXME: Don't do blocking
|
||||
runBlocking {
|
||||
updateManga.await(
|
||||
MangaUpdate(
|
||||
id = this@addOrRemoveToFavorites.id!!,
|
||||
favorite = true,
|
||||
dateAdded = this@addOrRemoveToFavorites.date_added,
|
||||
)
|
||||
)
|
||||
}
|
||||
db.setMangaCategories(
|
||||
lastUsedCategories.map { MangaCategory.create(this, it) },
|
||||
listOf(this),
|
||||
|
@ -257,7 +278,16 @@ fun Manga.addOrRemoveToFavorites(
|
|||
favorite = true
|
||||
date_added = Date().time
|
||||
autoAddTrack(db, onMangaMoved)
|
||||
db.insertManga(this).executeAsBlocking()
|
||||
// FIXME: Don't do blocking
|
||||
runBlocking {
|
||||
updateManga.await(
|
||||
MangaUpdate(
|
||||
id = this@addOrRemoveToFavorites.id!!,
|
||||
favorite = true,
|
||||
dateAdded = this@addOrRemoveToFavorites.date_added,
|
||||
)
|
||||
)
|
||||
}
|
||||
db.setMangaCategories(emptyList(), listOf(this))
|
||||
onMangaMoved()
|
||||
(activity as? MainActivity)?.showNotificationPermissionPrompt()
|
||||
|
@ -279,13 +309,31 @@ fun Manga.addOrRemoveToFavorites(
|
|||
val lastAddedDate = date_added
|
||||
favorite = false
|
||||
date_added = 0
|
||||
db.insertManga(this).executeAsBlocking()
|
||||
// FIXME: Don't do blocking
|
||||
runBlocking {
|
||||
updateManga.await(
|
||||
MangaUpdate(
|
||||
id = this@addOrRemoveToFavorites.id!!,
|
||||
favorite = false,
|
||||
dateAdded = 0,
|
||||
)
|
||||
)
|
||||
}
|
||||
onMangaMoved()
|
||||
return view.snack(view.context.getString(MR.strings.removed_from_library), Snackbar.LENGTH_INDEFINITE) {
|
||||
setAction(MR.strings.undo) {
|
||||
favorite = true
|
||||
date_added = lastAddedDate
|
||||
db.insertManga(this@addOrRemoveToFavorites).executeAsBlocking()
|
||||
// FIXME: Don't do blocking
|
||||
runBlocking {
|
||||
updateManga.await(
|
||||
MangaUpdate(
|
||||
id = this@addOrRemoveToFavorites.id!!,
|
||||
favorite = true,
|
||||
dateAdded = lastAddedDate,
|
||||
)
|
||||
)
|
||||
}
|
||||
onMangaMoved()
|
||||
}
|
||||
addCallback(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue