Add category filters to Upcoming calendar (#3607)

This commit is contained in:
MajorTanya
2026-08-04 12:30:23 +02:00
committed by GitHub
parent f7a1ecd251
commit a73271aefa
11 changed files with 299 additions and 25 deletions
@@ -87,12 +87,24 @@ class MangaRepositoryImpl(
.awaitAsList()
}
override suspend fun getUpcomingManga(statuses: Set<Long>): Flow<List<Manga>> {
override suspend fun getUpcomingManga(
statuses: Set<Long>,
excludedCategories: List<Long>,
includedCategories: List<Long>,
): Flow<List<Manga>> {
val timeZone = TimeZone.currentSystemDefault()
val epochMillis =
Clock.System.now().toLocalDateTime(timeZone).date.atStartOfDayIn(timeZone).toEpochMilliseconds()
return database.mangasQueries
.getUpcomingManga(epochMillis, statuses, MangaMapper::mapManga)
.getUpcomingManga(
startOfDay = epochMillis,
statuses = statuses,
includedEmpty = includedCategories.isEmpty(),
includedCategories = includedCategories,
excludedEmpty = excludedCategories.isEmpty(),
excludedCategories = excludedCategories,
mapper = MangaMapper::mapManga,
)
.subscribeToList()
}
@@ -164,6 +164,33 @@ FROM mangas
WHERE next_update >= :startOfDay
AND favorite = 1
AND status IN :statuses
AND (
-- includedEmpty being true expresses "don't care" state and bypasses the membership filter
:includedEmpty
OR EXISTS (
SELECT 1 FROM mangas_categories
WHERE mangas_categories.manga_id = mangas._id
AND COALESCE(mangas_categories.category_id, 0) IN :includedCategories
)
OR (0 IN :includedCategories AND NOT EXISTS (
SELECT 1 FROM mangas_categories WHERE mangas_categories.manga_id = mangas._id)
)
)
AND (
-- excludedEmpty being true expresses "don't care" state and bypasses the membership filter
:excludedEmpty
OR (
NOT EXISTS (
SELECT 1 FROM mangas_categories
WHERE mangas_categories.manga_id = mangas._id
AND COALESCE(mangas_categories.category_id, 0) IN :excludedCategories
)
AND (
0 NOT IN :excludedCategories
OR EXISTS (SELECT 1 FROM mangas_categories WHERE mangas_categories.manga_id = mangas._id)
)
)
)
ORDER BY next_update ASC;
resetViewerFlags: