mirror of
https://github.com/null2264/yokai.git
synced 2025-06-20 18:24:42 +00:00
refactor(db): Migrate some more category queries to SQLDelight part 2
This commit is contained in:
parent
ca41e02fe1
commit
663360c283
4 changed files with 39 additions and 17 deletions
|
@ -22,5 +22,4 @@ interface CategoryQueries : DbProvider {
|
|||
|
||||
fun insertCategories(categories: List<Category>) = db.put().objects(categories).prepare()
|
||||
|
||||
fun deleteCategory(category: Category) = db.delete().`object`(category).prepare()
|
||||
}
|
||||
|
|
|
@ -7,12 +7,7 @@ import android.os.Bundle
|
|||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import eu.kanade.tachiyomi.core.preference.Preference
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
@ -27,6 +22,9 @@ import eu.kanade.tachiyomi.widget.TriStateCheckBox
|
|||
import kotlinx.coroutines.runBlocking
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.category.interactor.GetCategories
|
||||
import yokai.domain.category.interactor.InsertCategories
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import android.R as AR
|
||||
|
||||
class ManageCategoryDialog(bundle: Bundle? = null) :
|
||||
|
@ -41,8 +39,8 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||
private var category: Category? = null
|
||||
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
private val db by injectLazy<DatabaseHelper>()
|
||||
private val getCategories by injectLazy<GetCategories>()
|
||||
private val insertCategories by injectLazy<InsertCategories>()
|
||||
|
||||
lateinit var binding: MangaCategoryDialogBinding
|
||||
|
||||
|
@ -96,11 +94,10 @@ class ManageCategoryDialog(bundle: Bundle? = null) :
|
|||
val categories = runBlocking { getCategories.await() }
|
||||
category.order = (categories.maxOfOrNull { it.order } ?: 0) + 1
|
||||
category.mangaSort = LibrarySort.Title.categoryValue
|
||||
val dbCategory = db.insertCategory(category).executeAsBlocking()
|
||||
category.id = dbCategory.insertedId()?.toInt()
|
||||
category.id = runBlocking { insertCategories.awaitOne(category) }?.toInt()
|
||||
this.category = category
|
||||
} else {
|
||||
db.insertCategory(category).executeAsBlocking()
|
||||
runBlocking { insertCategories.awaitOne(category) }
|
||||
}
|
||||
} else if (categoryExists) {
|
||||
binding.categoryTextLayout.error =
|
||||
|
|
|
@ -44,7 +44,6 @@ import eu.kanade.tachiyomi.util.lang.chopByWords
|
|||
import eu.kanade.tachiyomi.util.lang.removeArticles
|
||||
import eu.kanade.tachiyomi.util.manga.MangaCoverMetadata
|
||||
import eu.kanade.tachiyomi.util.mapStatus
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import eu.kanade.tachiyomi.util.system.launchIO
|
||||
import eu.kanade.tachiyomi.util.system.launchNonCancellableIO
|
||||
import eu.kanade.tachiyomi.util.system.launchUI
|
||||
|
@ -66,6 +65,8 @@ import uy.kohesive.injekt.Injekt
|
|||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.category.interactor.GetCategories
|
||||
import yokai.domain.category.interactor.UpdateCategories
|
||||
import yokai.domain.category.models.CategoryUpdate
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.chapter.interactor.UpdateChapter
|
||||
import yokai.domain.chapter.models.ChapterUpdate
|
||||
|
@ -91,6 +92,7 @@ class LibraryPresenter(
|
|||
private val trackManager: TrackManager = Injekt.get(),
|
||||
) : BaseCoroutinePresenter<LibraryController>(), DownloadQueue.DownloadListener {
|
||||
private val getCategories: GetCategories by injectLazy()
|
||||
private val updateCategories: UpdateCategories by injectLazy()
|
||||
private val getLibraryManga: GetLibraryManga by injectLazy()
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
private val updateChapter: UpdateChapter by injectLazy()
|
||||
|
@ -640,6 +642,10 @@ class LibraryPresenter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun onCategoryUpdate(update: CategoryUpdate) {
|
||||
presenterScope.launchNonCancellableIO { updateCategories.awaitOne(update) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies library sorting to the given list of manga.
|
||||
*
|
||||
|
@ -654,7 +660,14 @@ class LibraryPresenter(
|
|||
if (category.id == 0) {
|
||||
preferences.defaultMangaOrder()
|
||||
.set(category.mangaSort.toString())
|
||||
} else if (!category.isDynamic) db.insertCategory(category).executeAsBlocking()
|
||||
} else if (!category.isDynamic) {
|
||||
onCategoryUpdate(
|
||||
CategoryUpdate(
|
||||
id = category.id!!.toLong(),
|
||||
mangaOrder = category.mangaOrderToString(),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
val compare = when {
|
||||
category.mangaSort != null -> {
|
||||
|
@ -1320,7 +1333,12 @@ class LibraryPresenter(
|
|||
if (category.id == 0) {
|
||||
preferences.defaultMangaOrder().set(category.mangaSort.toString())
|
||||
} else {
|
||||
Injekt.get<DatabaseHelper>().insertCategory(category).executeAsBlocking()
|
||||
onCategoryUpdate(
|
||||
CategoryUpdate(
|
||||
id = catId.toLong(),
|
||||
mangaOrder = category.mangaOrderToString(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
requestSortUpdate()
|
||||
|
@ -1336,7 +1354,12 @@ class LibraryPresenter(
|
|||
if (category.id == 0) {
|
||||
preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
|
||||
} else {
|
||||
db.insertCategory(category).executeOnIO()
|
||||
updateCategories.awaitOne(
|
||||
CategoryUpdate(
|
||||
id = category.id!!.toLong(),
|
||||
mangaOrder = category.mangaOrderToString(),
|
||||
),
|
||||
)
|
||||
}
|
||||
requestSortUpdate()
|
||||
}
|
||||
|
@ -1380,7 +1403,12 @@ class LibraryPresenter(
|
|||
preferences.defaultMangaOrder()
|
||||
.set(mangaIds.joinToString("/"))
|
||||
} else {
|
||||
db.insertCategory(category).executeAsBlocking()
|
||||
updateCategories.awaitOne(
|
||||
CategoryUpdate(
|
||||
id = category.id!!.toLong(),
|
||||
mangaOrder = category.mangaOrderToString(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
getLibrary()
|
||||
|
|
|
@ -2,10 +2,8 @@ package yokai.data.category
|
|||
|
||||
import co.touchlab.kermit.Logger
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.tables.CategoryTable.COL_MANGA_ORDER
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import yokai.data.DatabaseHandler
|
||||
import yokai.data.updateStrategyAdapter
|
||||
import yokai.domain.category.CategoryRepository
|
||||
import yokai.domain.category.models.CategoryUpdate
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue