Add bookmark filter (#8198)

* feat: add bookmark filter

* feat: add getBookmarkChaptersByMangaId query + interactor to be used for filtering
This commit is contained in:
Swords 2022-10-16 02:33:09 +11:00 committed by GitHub
parent 3d7e44726d
commit 3fdcd636d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 1 deletions

View File

@ -81,6 +81,10 @@ class ChapterRepositoryImpl(
return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) }
}
override suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List<Chapter> {
return handler.awaitList { chaptersQueries.getBookmarkedChaptersByMangaId(mangaId, chapterMapper) }
}
override suspend fun getChapterById(id: Long): Chapter? {
return handler.awaitOneOrNull { chaptersQueries.getChapterById(id, chapterMapper) }
}

View File

@ -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<ChapterRepository> { ChapterRepositoryImpl(get()) }
addFactory { GetChapter(get()) }
addFactory { GetChapterByMangaId(get()) }
addFactory { GetBookmarkedChaptersByMangaId(get()) }
addFactory { UpdateChapter(get()) }
addFactory { SetReadStatus(get(), get(), get(), get()) }
addFactory { ShouldUpdateDbChapter() }

View File

@ -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<Chapter> {
return try {
chapterRepository.getBookmarkedChaptersByMangaId(mangaId)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
emptyList()
}
}
}

View File

@ -16,6 +16,8 @@ interface ChapterRepository {
suspend fun getChapterByMangaId(mangaId: Long): List<Chapter>
suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List<Chapter>
suspend fun getChapterById(id: Long): Chapter?
suspend fun getChapterByMangaIdAsFlow(mangaId: Long): Flow<List<Chapter>>

View File

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

View File

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

View File

@ -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<Long, Item.TriStateGroup>
@ -114,7 +115,7 @@ class LibrarySettingsSheet(
trackFilters = services.associate { service ->
Pair(service.id, Item.TriStateGroup(getServiceResId(service, size), this))
}
val list: MutableList<Item> = mutableListOf(downloaded, unread, started, completed)
val list: MutableList<Item> = 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 ->

View File

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