Show number of unique library items (closes #6522)
- Filters do affect this - Won't be shown if tabs aren't visible and there's more than 1 category (so it'd always show the per-category count), but a separate stats page should show that info instead (cherry picked from commit 8a3a7418d055b500517ef6c9c5623328ae01bc10) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
This commit is contained in:
parent
dbcc744e1f
commit
829bd7b247
@ -143,19 +143,16 @@ class LibraryPresenter(
|
||||
// SY <--
|
||||
) : BasePresenter<LibraryController>(), LibraryState by state {
|
||||
|
||||
var loadedManga by mutableStateOf(emptyMap<Long, List<LibraryItem>>())
|
||||
private set
|
||||
private var loadedManga by mutableStateOf(emptyMap<Long, List<LibraryItem>>())
|
||||
|
||||
val isLibraryEmpty by derivedStateOf { loadedManga.isEmpty() }
|
||||
|
||||
val tabVisibility by preferences.categoryTabs().asState()
|
||||
|
||||
val mangaCountVisibility by preferences.categoryNumberOfItems().asState()
|
||||
|
||||
var activeCategory: Int by preferences.lastUsedCategory().asState()
|
||||
|
||||
val isDownloadOnly: Boolean by preferences.downloadedOnly().asState()
|
||||
|
||||
val isIncognitoMode: Boolean by preferences.incognitoMode().asState()
|
||||
|
||||
/**
|
||||
@ -225,7 +222,7 @@ class LibraryPresenter(
|
||||
*/
|
||||
if (librarySubscription == null || librarySubscription!!.isCancelled) {
|
||||
librarySubscription = presenterScope.launchIO {
|
||||
getLibraryObservable()
|
||||
getLibraryFlow().asObservable()
|
||||
.combineLatest(badgeTriggerRelay.observeOn(Schedulers.io())) { lib, _ ->
|
||||
lib.apply { setBadges(mangaMap) }
|
||||
}
|
||||
@ -572,8 +569,16 @@ class LibraryPresenter(
|
||||
*
|
||||
* @return an observable of the categories and its manga.
|
||||
*/
|
||||
private fun getLibraryObservable(): Observable<Library> {
|
||||
return combine(getCategoriesFlow(), getLibraryMangasFlow()) { dbCategories, libraryManga ->
|
||||
private fun getLibraryFlow(): Flow<Library> {
|
||||
val categoriesFlow = getCategories.subscribe()
|
||||
val libraryMangasFlow = getLibraryManga.subscribe()
|
||||
.map { list ->
|
||||
list.map { libraryManga ->
|
||||
// Display mode based on user preference: take it from global library setting or category
|
||||
LibraryItem(libraryManga)
|
||||
}.groupBy { it.manga.category.toLong() }
|
||||
}
|
||||
return combine(categoriesFlow, libraryMangasFlow) { dbCategories, libraryManga ->
|
||||
val categories = if (libraryManga.isNotEmpty() && libraryManga.containsKey(0).not()) {
|
||||
dbCategories.filterNot { it.isSystemCategory }
|
||||
} else {
|
||||
@ -584,7 +589,7 @@ class LibraryPresenter(
|
||||
state.ogCategories = categories
|
||||
// SY <--
|
||||
Library(categories, libraryManga)
|
||||
}.asObservable()
|
||||
}
|
||||
}
|
||||
|
||||
// SY -->
|
||||
@ -613,31 +618,6 @@ class LibraryPresenter(
|
||||
}
|
||||
// SY <--
|
||||
|
||||
/**
|
||||
* Get the categories from the database.
|
||||
*
|
||||
* @return an observable of the categories.
|
||||
*/
|
||||
private fun getCategoriesFlow(): Flow<List<Category>> {
|
||||
return getCategories.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the manga grouped by categories.
|
||||
*
|
||||
* @return an observable containing a map with the category id as key and a list of manga as the
|
||||
* value.
|
||||
*/
|
||||
private fun getLibraryMangasFlow(): Flow<LibraryMap> {
|
||||
return getLibraryManga.subscribe()
|
||||
.map { list ->
|
||||
list.map { libraryManga ->
|
||||
// Display mode based on user preference: take it from global library setting or category
|
||||
LibraryItem(libraryManga)
|
||||
}.groupBy { it.manga.category.toLong() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tracked manga from the database and checks if the filter gets changed
|
||||
*
|
||||
@ -746,8 +726,8 @@ class LibraryPresenter(
|
||||
* @param mangas the list of manga.
|
||||
*/
|
||||
fun downloadUnreadChapters(mangas: List<Manga>) {
|
||||
mangas.forEach { manga ->
|
||||
launchIO {
|
||||
launchIO {
|
||||
mangas.forEach { manga ->
|
||||
if (manga.source == MERGED_SOURCE_ID) {
|
||||
val mergedSource = sourceManager.get(MERGED_SOURCE_ID) as MergedSource
|
||||
val mergedMangas = getMergedMangaById.await(manga.id)
|
||||
@ -816,8 +796,8 @@ class LibraryPresenter(
|
||||
* @param mangas the list of manga.
|
||||
*/
|
||||
fun markReadStatus(mangas: List<Manga>, read: Boolean) {
|
||||
mangas.forEach { manga ->
|
||||
launchIO {
|
||||
launchIO {
|
||||
mangas.forEach { manga ->
|
||||
setReadStatus.await(
|
||||
manga = manga,
|
||||
read = read,
|
||||
@ -913,14 +893,15 @@ class LibraryPresenter(
|
||||
val title = if (tabVisibility.not()) {
|
||||
getCategoryName(context, category, groupType, categoryName)
|
||||
} else defaultTitle
|
||||
val count = when {
|
||||
category == null || mangaCountVisibility.not() -> null
|
||||
tabVisibility.not() -> loadedManga[category.id]?.size
|
||||
else -> loadedManga.values.flatten().distinct().size
|
||||
}
|
||||
|
||||
value = when {
|
||||
category == null -> default
|
||||
(tabVisibility.not() && mangaCountVisibility.not()) -> LibraryToolbarTitle(title)
|
||||
tabVisibility.not() && mangaCountVisibility -> LibraryToolbarTitle(title, loadedManga[category.id]?.size)
|
||||
(tabVisibility && categories.size > 1) && mangaCountVisibility -> LibraryToolbarTitle(title)
|
||||
tabVisibility && mangaCountVisibility -> LibraryToolbarTitle(title, loadedManga[category.id]?.size)
|
||||
else -> default
|
||||
value = when (category) {
|
||||
null -> default
|
||||
else -> LibraryToolbarTitle(title, count)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1118,10 +1099,6 @@ class LibraryPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun hasSelection(): Boolean {
|
||||
return selection.isNotEmpty()
|
||||
}
|
||||
|
||||
fun clearSelection() {
|
||||
state.selection = emptyList()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user