Use SQLDelight for a Category related queries (#7438)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user