Use SQLDelight for a Category related queries (#7438)
(cherry picked from commit 2674570792)
# Conflicts:
# app/src/main/java/eu/kanade/data/category/CategoryRepositoryImpl.kt
# app/src/main/java/eu/kanade/domain/category/model/Category.kt
# app/src/main/java/eu/kanade/domain/category/repository/CategoryRepository.kt
# app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt
# app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt
# app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt
# app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt
# app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt
# app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
# app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt
This commit is contained in:
@@ -4,6 +4,7 @@ import eu.kanade.data.manga.MangaMergeRepositoryImpl
|
||||
import eu.kanade.data.manga.MangaMetadataRepositoryImpl
|
||||
import eu.kanade.domain.chapter.interactor.GetMergedChapterByMangaId
|
||||
import eu.kanade.domain.manga.interactor.GetFlatMetadataById
|
||||
import eu.kanade.domain.manga.interactor.GetMangaByUrlAndSource
|
||||
import eu.kanade.domain.manga.interactor.GetMergedManga
|
||||
import eu.kanade.domain.manga.interactor.GetMergedMangaById
|
||||
import eu.kanade.domain.manga.interactor.GetMergedReferencesById
|
||||
@@ -30,6 +31,7 @@ class SYDomainModule : InjektModule {
|
||||
addFactory { SetSourceCategories(get()) }
|
||||
addFactory { ToggleSources(get()) }
|
||||
addFactory { SetMangaFilteredScanlators(get()) }
|
||||
addFactory { GetMangaByUrlAndSource(get()) }
|
||||
|
||||
addSingletonFactory<MangaMetadataRepository> { MangaMetadataRepositoryImpl(get()) }
|
||||
addFactory { GetFlatMetadataById(get()) }
|
||||
|
||||
@@ -8,20 +8,18 @@ class GetCategories(
|
||||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
// SY -->
|
||||
suspend fun await(): List<Category> {
|
||||
return categoryRepository.awaitAll()
|
||||
}
|
||||
// SY <--
|
||||
|
||||
fun subscribe(): Flow<List<Category>> {
|
||||
return categoryRepository.getAll()
|
||||
return categoryRepository.getAllAsFlow()
|
||||
}
|
||||
|
||||
fun subscribe(mangaId: Long): Flow<List<Category>> {
|
||||
return categoryRepository.getCategoriesByMangaIdAsFlow(mangaId)
|
||||
}
|
||||
|
||||
suspend fun await(): List<Category> {
|
||||
return categoryRepository.getAll()
|
||||
}
|
||||
|
||||
suspend fun await(mangaId: Long): List<Category> {
|
||||
return categoryRepository.getCategoriesByMangaId(mangaId)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package eu.kanade.domain.category.model
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.R
|
||||
import java.io.Serializable
|
||||
import eu.kanade.tachiyomi.data.database.models.Category as DbCategory
|
||||
|
||||
@@ -11,7 +13,20 @@ data class Category(
|
||||
// SY -->
|
||||
val mangaOrder: List<Long>,
|
||||
// SY <--
|
||||
) : Serializable
|
||||
) : Serializable {
|
||||
|
||||
companion object {
|
||||
val default = { context: Context ->
|
||||
Category(
|
||||
id = 0,
|
||||
name = context.getString(R.string.default_category),
|
||||
order = 0,
|
||||
flags = 0,
|
||||
mangaOrder = emptyList()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Category.toDbCategory(): DbCategory = DbCategory.create(name).also {
|
||||
it.id = id.toInt()
|
||||
|
||||
@@ -6,11 +6,9 @@ import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface CategoryRepository {
|
||||
|
||||
// SY -->
|
||||
suspend fun awaitAll(): List<Category>
|
||||
// SY <--
|
||||
suspend fun getAll(): List<Category>
|
||||
|
||||
fun getAll(): Flow<List<Category>>
|
||||
fun getAllAsFlow(): Flow<List<Category>>
|
||||
|
||||
suspend fun getCategoriesByMangaId(mangaId: Long): List<Category>
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package eu.kanade.domain.manga.interactor
|
||||
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.repository.MangaRepository
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import logcat.LogPriority
|
||||
|
||||
class GetMangaByUrlAndSource(
|
||||
private val mangaRepository: MangaRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(url: String, sourceId: Long): Manga? {
|
||||
return try {
|
||||
mangaRepository.getMangaByUrlAndSource(url, sourceId)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun subscribe(url: String, sourceId: Long): Flow<Manga?> {
|
||||
return mangaRepository.subscribeMangaByUrlAndSource(url, sourceId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ interface MangaRepository {
|
||||
|
||||
suspend fun getMangaByIdAsFlow(id: Long): Flow<Manga>
|
||||
|
||||
suspend fun getMangaByUrlAndSource(url: String, sourceId: Long): Manga?
|
||||
|
||||
suspend fun subscribeMangaByUrlAndSource(url: String, sourceId: Long): Flow<Manga?>
|
||||
|
||||
suspend fun getFavorites(): List<Manga>
|
||||
|
||||
fun getFavoritesBySourceId(sourceId: Long): Flow<List<Manga>>
|
||||
|
||||
Reference in New Issue
Block a user