Fix favorites counters

This commit is contained in:
Koitharu
2024-01-20 15:54:02 +02:00
parent c9fcc0f0f8
commit d56fc674ab
3 changed files with 5 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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 ->