Use SQLDelight for a Category related queries (#7438)

This commit is contained in:
Andreas
2022-07-02 22:12:06 +02:00
committed by GitHub
parent 21771e62aa
commit 2674570792
14 changed files with 96 additions and 99 deletions

View File

@@ -9,13 +9,17 @@ class GetCategories(
) {
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)
}

View File

@@ -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
@@ -8,7 +10,19 @@ data class Category(
val name: String,
val order: Long,
val flags: Long,
) : Serializable
) : Serializable {
companion object {
val default = { context: Context ->
Category(
id = 0,
name = context.getString(R.string.default_category),
order = 0,
flags = 0,
)
}
}
}
fun Category.toDbCategory(): DbCategory = DbCategory.create(name).also {
it.id = id.toInt()

View File

@@ -6,7 +6,9 @@ import kotlinx.coroutines.flow.Flow
interface CategoryRepository {
fun getAll(): Flow<List<Category>>
suspend fun getAll(): List<Category>
fun getAllAsFlow(): Flow<List<Category>>
suspend fun getCategoriesByMangaId(mangaId: Long): List<Category>