diff --git a/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt index ef724393e..5083b5479 100644 --- a/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt @@ -81,6 +81,10 @@ class ChapterRepositoryImpl( return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) } } + override suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List { + return handler.awaitList { chaptersQueries.getBookmarkedChaptersByMangaId(mangaId, chapterMapper) } + } + override suspend fun getChapterById(id: Long): Chapter? { return handler.awaitOneOrNull { chaptersQueries.getChapterById(id, chapterMapper) } } diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index b4047afef..ead3841e6 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -19,6 +19,7 @@ import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.interactor.SetSortModeForCategory import eu.kanade.domain.category.interactor.UpdateCategory import eu.kanade.domain.category.repository.CategoryRepository +import eu.kanade.domain.chapter.interactor.GetBookmarkedChaptersByMangaId import eu.kanade.domain.chapter.interactor.GetChapter import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags @@ -110,6 +111,7 @@ class DomainModule : InjektModule { addSingletonFactory { ChapterRepositoryImpl(get()) } addFactory { GetChapter(get()) } addFactory { GetChapterByMangaId(get()) } + addFactory { GetBookmarkedChaptersByMangaId(get()) } addFactory { UpdateChapter(get()) } addFactory { SetReadStatus(get(), get(), get(), get()) } addFactory { ShouldUpdateDbChapter() } diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/GetBookmarkedChaptersByMangaId.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/GetBookmarkedChaptersByMangaId.kt new file mode 100644 index 000000000..05e03a5be --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/GetBookmarkedChaptersByMangaId.kt @@ -0,0 +1,20 @@ +package eu.kanade.domain.chapter.interactor + +import eu.kanade.domain.chapter.model.Chapter +import eu.kanade.domain.chapter.repository.ChapterRepository +import eu.kanade.tachiyomi.util.system.logcat +import logcat.LogPriority + +class GetBookmarkedChaptersByMangaId( + private val chapterRepository: ChapterRepository, +) { + + suspend fun await(mangaId: Long): List { + return try { + chapterRepository.getBookmarkedChaptersByMangaId(mangaId) + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) + emptyList() + } + } +} diff --git a/app/src/main/java/eu/kanade/domain/chapter/repository/ChapterRepository.kt b/app/src/main/java/eu/kanade/domain/chapter/repository/ChapterRepository.kt index 311ad4b8d..4b16ffadd 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/repository/ChapterRepository.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/repository/ChapterRepository.kt @@ -16,6 +16,8 @@ interface ChapterRepository { suspend fun getChapterByMangaId(mangaId: Long): List + suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List + suspend fun getChapterById(id: Long): Chapter? suspend fun getChapterByMangaIdAsFlow(mangaId: Long): Flow> diff --git a/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt b/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt index e13f27363..18a8aac07 100644 --- a/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt +++ b/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt @@ -40,6 +40,8 @@ class LibraryPreferences( fun filterStarted() = preferenceStore.getInt("pref_filter_library_started", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) + fun filterBookmarked() = preferenceStore.getInt("pref_filter_library_bookmarked", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) + fun filterCompleted() = preferenceStore.getInt("pref_filter_library_completed", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) fun filterTracking(name: Int) = preferenceStore.getInt("pref_filter_library_tracked_$name", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index b3e17b893..d8fde9334 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -20,6 +20,7 @@ import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.model.Category +import eu.kanade.domain.chapter.interactor.GetBookmarkedChaptersByMangaId import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.model.toDbChapter @@ -85,6 +86,7 @@ class LibraryPresenter( private val getLibraryManga: GetLibraryManga = Injekt.get(), private val getTracks: GetTracks = Injekt.get(), private val getCategories: GetCategories = Injekt.get(), + private val getBookmarkedChaptersByMangaId: GetBookmarkedChaptersByMangaId = Injekt.get(), private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(), private val setReadStatus: SetReadStatus = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(), @@ -174,6 +176,7 @@ class LibraryPresenter( val filterDownloaded = libraryPreferences.filterDownloaded().get() val filterUnread = libraryPreferences.filterUnread().get() val filterStarted = libraryPreferences.filterStarted().get() + val filterBookmarked = libraryPreferences.filterBookmarked().get() val filterCompleted = libraryPreferences.filterCompleted().get() val loggedInServices = trackManager.services.filter { trackService -> trackService.isLogged } .associate { trackService -> @@ -218,6 +221,19 @@ class LibraryPresenter( } } + val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{ item -> + if (filterBookmarked == State.IGNORE.value) return@bookmarked true + return@bookmarked runBlocking { + val isBookmarked = getBookmarkedChaptersByMangaId.await(item.libraryManga.manga.id).isNotEmpty() + + return@runBlocking if (filterBookmarked == State.INCLUDE.value) { + isBookmarked + } else { + !isBookmarked + } + } + } + val filterFnCompleted: (LibraryItem) -> Boolean = completed@{ item -> if (filterCompleted == State.IGNORE.value) return@completed true val isCompleted = item.libraryManga.manga.status.toInt() == SManga.COMPLETED @@ -258,6 +274,7 @@ class LibraryPresenter( !filterFnDownloaded(item) || !filterFnUnread(item) || !filterFnStarted(item) || + !filterFnBookmarked(item) || !filterFnCompleted(item) || !filterFnTracking(item) ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 2e5062e48..1ed4a31fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -100,6 +100,7 @@ class LibrarySettingsSheet( private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this) private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val started = Item.TriStateGroup(R.string.action_filter_started, this) + private val bookmarked = Item.TriStateGroup(R.string.action_filter_bookmarked, this) private val completed = Item.TriStateGroup(R.string.completed, this) private val trackFilters: Map @@ -114,7 +115,7 @@ class LibrarySettingsSheet( trackFilters = services.associate { service -> Pair(service.id, Item.TriStateGroup(getServiceResId(service, size), this)) } - val list: MutableList = mutableListOf(downloaded, unread, started, completed) + val list: MutableList = mutableListOf(downloaded, unread, started, bookmarked, completed) if (size > 1) list.add(Item.Header(R.string.action_filter_tracked)) list.addAll(trackFilters.values) items = list @@ -134,6 +135,7 @@ class LibrarySettingsSheet( } unread.state = libraryPreferences.filterUnread().get() started.state = libraryPreferences.filterStarted().get() + bookmarked.state = libraryPreferences.filterBookmarked().get() completed.state = libraryPreferences.filterCompleted().get() trackFilters.forEach { trackFilter -> @@ -154,6 +156,7 @@ class LibrarySettingsSheet( downloaded -> libraryPreferences.filterDownloaded().set(newState) unread -> libraryPreferences.filterUnread().set(newState) started -> libraryPreferences.filterStarted().set(newState) + bookmarked -> libraryPreferences.filterBookmarked().set(newState) completed -> libraryPreferences.filterCompleted().set(newState) else -> { trackFilters.forEach { trackFilter -> diff --git a/app/src/main/sqldelight/data/chapters.sq b/app/src/main/sqldelight/data/chapters.sq index 4452d3233..165916241 100644 --- a/app/src/main/sqldelight/data/chapters.sq +++ b/app/src/main/sqldelight/data/chapters.sq @@ -28,6 +28,12 @@ SELECT * FROM chapters WHERE manga_id = :mangaId; +getBookmarkedChaptersByMangaId: +SELECT * +FROM chapters +WHERE bookmark +AND manga_id = :mangaId; + getChapterByUrl: SELECT * FROM chapters