@@ -82,15 +82,15 @@ abstract class FavouritesDao {
|
|||||||
)
|
)
|
||||||
abstract suspend fun findAllManga(categoryId: Int): List<MangaEntity>
|
abstract suspend fun findAllManga(categoryId: Int): List<MangaEntity>
|
||||||
|
|
||||||
suspend fun findCovers(categoryId: Long, order: ListSortOrder, limit: Int): List<Cover> {
|
suspend fun findCovers(categoryId: Long, order: ListSortOrder): List<Cover> {
|
||||||
val orderBy = getOrderBy(order)
|
val orderBy = getOrderBy(order)
|
||||||
|
|
||||||
@Language("RoomSql")
|
@Language("RoomSql")
|
||||||
val query = SimpleSQLiteQuery(
|
val query = SimpleSQLiteQuery(
|
||||||
"SELECT manga.cover_url AS url, manga.source AS source FROM favourites " +
|
"SELECT manga.cover_url AS url, manga.source AS source FROM favourites " +
|
||||||
"LEFT JOIN manga ON favourites.manga_id = manga.manga_id " +
|
"LEFT JOIN manga ON favourites.manga_id = manga.manga_id " +
|
||||||
"WHERE favourites.category_id = ? AND deleted_at = 0 ORDER BY $orderBy LIMIT ?",
|
"WHERE favourites.category_id = ? AND deleted_at = 0 ORDER BY $orderBy",
|
||||||
arrayOf<Any>(categoryId, limit),
|
arrayOf<Any>(categoryId),
|
||||||
)
|
)
|
||||||
return findCoversImpl(query)
|
return findCoversImpl(query)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class FavouritesRepository @Inject constructor(
|
|||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeCategoriesWithCovers(coversLimit: Int): Flow<Map<FavouriteCategory, List<Cover>>> {
|
fun observeCategoriesWithCovers(): Flow<Map<FavouriteCategory, List<Cover>>> {
|
||||||
return db.getFavouriteCategoriesDao().observeAll()
|
return db.getFavouriteCategoriesDao().observeAll()
|
||||||
.map {
|
.map {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
@@ -87,7 +87,6 @@ class FavouritesRepository @Inject constructor(
|
|||||||
res[cat] = db.getFavouritesDao().findCovers(
|
res[cat] = db.getFavouritesDao().findCovers(
|
||||||
categoryId = cat.id,
|
categoryId = cat.id,
|
||||||
order = cat.order,
|
order = cat.order,
|
||||||
limit = coversLimit,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class FavouritesCategoriesViewModel @Inject constructor(
|
|||||||
private var commitJob: Job? = null
|
private var commitJob: Job? = null
|
||||||
|
|
||||||
val content = combine(
|
val content = combine(
|
||||||
repository.observeCategoriesWithCovers(coversLimit = 3),
|
repository.observeCategoriesWithCovers(),
|
||||||
observeAllCategories(),
|
observeAllCategories(),
|
||||||
settings.observeAsFlow(AppSettings.KEY_ALL_FAVOURITES_VISIBLE) { isAllFavouritesVisible },
|
settings.observeAsFlow(AppSettings.KEY_ALL_FAVOURITES_VISIBLE) { isAllFavouritesVisible },
|
||||||
) { cats, all, showAll ->
|
) { cats, all, showAll ->
|
||||||
|
|||||||
Reference in New Issue
Block a user