mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
refactor(db): Migrate last manga queries (that can be migrated) to SQLDelight
This commit is contained in:
parent
17b07cd836
commit
93ec13f324
7 changed files with 22 additions and 20 deletions
|
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.domain.manga.models.Manga
|
|||
|
||||
interface MangaQueries : DbProvider {
|
||||
|
||||
// FIXME: Migrate to SQLDelight, on halt: in StorIO transaction
|
||||
fun getManga(id: Long) = db.get()
|
||||
.`object`(Manga::class.java)
|
||||
.withQuery(
|
||||
|
|
|
@ -1082,7 +1082,7 @@ open class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||
controller?.showSheet()
|
||||
}
|
||||
}
|
||||
SHORTCUT_MANGA -> {
|
||||
Constants.SHORTCUT_MANGA -> {
|
||||
val extras = intent.extras ?: return false
|
||||
if (router.backstack.isEmpty()) nav.selectedItemId = R.id.nav_library
|
||||
router.pushController(MangaDetailsController(extras).withFadeTransaction())
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.bluelinelabs.conductor.Controller
|
|||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.ui.base.SmallToolbarInterface
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BaseLegacyController
|
||||
|
@ -26,15 +25,15 @@ import eu.kanade.tachiyomi.util.chapter.ChapterSort
|
|||
import eu.kanade.tachiyomi.util.system.extensionIntentForText
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.presentation.core.Constants
|
||||
import yokai.presentation.core.util.IntentCommon
|
||||
|
||||
class SearchActivity : MainActivity() {
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
private val getManga: GetManga by injectLazy()
|
||||
|
||||
private var backToMain = false
|
||||
|
||||
|
@ -151,13 +150,12 @@ class SearchActivity : MainActivity() {
|
|||
router.replaceTopController(GlobalSearchController(query, filter).withFadeTransaction())
|
||||
}
|
||||
}
|
||||
SHORTCUT_MANGA, SHORTCUT_MANGA_BACK -> {
|
||||
Constants.SHORTCUT_MANGA, Constants.SHORTCUT_MANGA_BACK -> {
|
||||
val extras = intent.extras ?: return false
|
||||
if (intent.action == SHORTCUT_MANGA_BACK && preferences.openChapterInShortcuts().get()) {
|
||||
if (intent.action == Constants.SHORTCUT_MANGA_BACK && preferences.openChapterInShortcuts().get()) {
|
||||
val mangaId = extras.getLong(Constants.MANGA_EXTRA)
|
||||
if (mangaId != 0L) {
|
||||
val db = Injekt.get<DatabaseHelper>()
|
||||
db.getManga(mangaId).executeAsBlocking()?.let { manga ->
|
||||
runBlocking { getManga.awaitById(mangaId) }?.let { manga ->
|
||||
val chapters = runBlocking { getChapter.awaitAll(manga) }
|
||||
val nextUnreadChapter = ChapterSort(manga).getNextUnreadChapter(chapters, false)
|
||||
if (nextUnreadChapter != null) {
|
||||
|
@ -170,7 +168,7 @@ class SearchActivity : MainActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (intent.action == SHORTCUT_MANGA_BACK) {
|
||||
if (intent.action == Constants.SHORTCUT_MANGA_BACK) {
|
||||
SecureActivityDelegate.promptLockIfNeeded(this, true)
|
||||
}
|
||||
router.replaceTopController(
|
||||
|
|
|
@ -18,7 +18,6 @@ import com.google.android.material.chip.Chip
|
|||
import com.google.android.material.chip.ChipGroup
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.coil.useCustomCover
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.seriesType
|
||||
import eu.kanade.tachiyomi.databinding.EditMangaDialogBinding
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
|
@ -37,9 +36,11 @@ import eu.kanade.tachiyomi.util.system.isInNightMode
|
|||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
||||
import eu.kanade.tachiyomi.util.view.setPositiveButton
|
||||
import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.domain.manga.models.cover
|
||||
import yokai.i18n.MR
|
||||
import yokai.presentation.core.util.coil.asTarget
|
||||
|
@ -73,8 +74,7 @@ class EditMangaDialog : DialogController {
|
|||
|
||||
@Suppress("unused")
|
||||
constructor(bundle: Bundle) : super(bundle) {
|
||||
manga = Injekt.get<DatabaseHelper>().getManga(bundle.getLong(KEY_MANGA))
|
||||
.executeAsBlocking()!!
|
||||
manga = runBlocking { Injekt.get<GetManga>().awaitById(bundle.getLong(KEY_MANGA))!! }
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.view.Menu
|
|||
import android.view.MenuInflater
|
||||
import androidx.core.os.bundleOf
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
|
@ -15,9 +14,11 @@ import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchCardAdapter
|
|||
import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchController
|
||||
import eu.kanade.tachiyomi.util.view.activityBinding
|
||||
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
|
||||
class SearchController(
|
||||
private var manga: Manga? = null,
|
||||
|
@ -40,7 +41,7 @@ class SearchController(
|
|||
|
||||
constructor(mangaId: Long, sources: LongArray) :
|
||||
this(
|
||||
Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking(),
|
||||
runBlocking { Injekt.get<GetManga>().awaitById(mangaId) },
|
||||
sources.map { Injekt.get<SourceManager>().getOrStub(it) }.filterIsInstance<CatalogueSource>(),
|
||||
)
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@ import eu.kanade.tachiyomi.domain.manga.models.Manga
|
|||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.view.DeferredField
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
|
||||
class MigratingManga(
|
||||
private val db: DatabaseHelper,
|
||||
|
@ -16,6 +18,7 @@ class MigratingManga(
|
|||
val mangaId: Long,
|
||||
parentContext: CoroutineContext,
|
||||
) {
|
||||
private val getManga: GetManga by injectLazy()
|
||||
val searchResult = DeferredField<Long?>()
|
||||
|
||||
// <MAX, PROGRESS>
|
||||
|
@ -28,7 +31,7 @@ class MigratingManga(
|
|||
@Volatile
|
||||
private var manga: Manga? = null
|
||||
suspend fun manga(): Manga? {
|
||||
if (manga == null) manga = db.getManga(mangaId).executeAsBlocking()
|
||||
if (manga == null) manga = getManga.awaitById(mangaId)
|
||||
return manga
|
||||
}
|
||||
|
||||
|
|
|
@ -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.executeOnIO
|
||||
import eu.kanade.tachiyomi.util.system.getParcelableCompat
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
|
@ -65,6 +64,7 @@ import kotlinx.coroutines.sync.Semaphore
|
|||
import kotlinx.coroutines.sync.withPermit
|
||||
import kotlinx.coroutines.withContext
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
@ -88,6 +88,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||
val config = args.getParcelableCompat(CONFIG_EXTRA, MigrationProcedureConfig::class.java)
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
private val getManga: GetManga by injectLazy()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
@ -424,9 +425,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||
launchUI {
|
||||
val hasDetails = router.backstack.any { it.controller is MangaDetailsController }
|
||||
if (hasDetails) {
|
||||
val manga = migratingManga?.firstOrNull()?.searchResult?.get()?.let {
|
||||
db.getManga(it).executeOnIO()
|
||||
}
|
||||
val manga = migratingManga?.firstOrNull()?.searchResult?.get()?.let { getManga.awaitById(it) }
|
||||
if (manga != null) {
|
||||
val newStack = router.backstack.filter {
|
||||
it.controller !is MangaDetailsController &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue