Fix favorites counters

(cherry picked from commit d56fc674ab)
master
Koitharu 2 years ago
parent a37e8825b0
commit cdd76f723f
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -82,15 +82,15 @@ abstract class FavouritesDao {
)
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)
@Language("RoomSql")
val query = SimpleSQLiteQuery(
"SELECT manga.cover_url AS url, manga.source AS source FROM favourites " +
"LEFT JOIN manga ON favourites.manga_id = manga.manga_id " +
"WHERE favourites.category_id = ? AND deleted_at = 0 ORDER BY $orderBy LIMIT ?",
arrayOf<Any>(categoryId, limit),
"WHERE favourites.category_id = ? AND deleted_at = 0 ORDER BY $orderBy",
arrayOf<Any>(categoryId),
)
return findCoversImpl(query)
}

@ -77,7 +77,7 @@ class FavouritesRepository @Inject constructor(
}.distinctUntilChanged()
}
fun observeCategoriesWithCovers(coversLimit: Int): Flow<Map<FavouriteCategory, List<Cover>>> {
fun observeCategoriesWithCovers(): Flow<Map<FavouriteCategory, List<Cover>>> {
return db.getFavouriteCategoriesDao().observeAll()
.map {
db.withTransaction {
@ -87,7 +87,6 @@ class FavouritesRepository @Inject constructor(
res[cat] = db.getFavouritesDao().findCovers(
categoryId = cat.id,
order = cat.order,
limit = coversLimit,
)
}
res

@ -35,7 +35,7 @@ class FavouritesCategoriesViewModel @Inject constructor(
private var commitJob: Job? = null
val content = combine(
repository.observeCategoriesWithCovers(coversLimit = 3),
repository.observeCategoriesWithCovers(),
observeAllCategories(),
settings.observeAsFlow(AppSettings.KEY_ALL_FAVOURITES_VISIBLE) { isAllFavouritesVisible },
) { cats, all, showAll ->

Loading…
Cancel
Save