From 6635dd2990851d830e83a628b7e62091bd20cb43 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 16 Oct 2022 11:30:54 -0400 Subject: [PATCH] Control library badge visibility with props instead Fixes #8174 --- .../presentation/library/LibraryScreen.kt | 4 + .../library/components/LibraryBadges.kt | 53 ++++++++++++ .../components/LibraryComfortableGrid.kt | 29 +++++-- .../library/components/LibraryCompactGrid.kt | 21 ++++- .../library/components/LibraryContent.kt | 13 ++- .../components/LibraryCoverOnlyGrid.kt | 21 ++++- .../library/components/LibraryGridCover.kt | 40 ++------- .../library/components/LibraryList.kt | 40 ++++----- .../library/components/LibraryPager.kt | 20 +++++ .../tachiyomi/ui/library/LibraryController.kt | 8 +- .../tachiyomi/ui/library/LibraryPresenter.kt | 83 ++++--------------- 11 files changed, 183 insertions(+), 149 deletions(-) create mode 100644 app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt diff --git a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt index 4fee280a6f..afd6154995 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt @@ -103,6 +103,10 @@ fun LibraryScreen( getDisplayModeForPage = { presenter.categories[it].display }, getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) }, getLibraryForPage = { presenter.getMangaForCategory(page = it) }, + showDownloadBadges = presenter.showDownloadBadges, + showUnreadBadges = presenter.showUnreadBadges, + showLocalBadges = presenter.showLocalBadges, + showLanguageBadges = presenter.showLanguageBadges, isIncognitoMode = presenter.isIncognitoMode, isDownloadOnly = presenter.isDownloadOnly, ) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt new file mode 100644 index 0000000000..878f78d67c --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt @@ -0,0 +1,53 @@ +package eu.kanade.presentation.library.components + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import eu.kanade.presentation.components.Badge +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.library.LibraryItem + +@Composable +fun DownloadsBadge( + enabled: Boolean, + item: LibraryItem, +) { + if (enabled && item.downloadCount > 0) { + Badge( + text = "${item.downloadCount}", + color = MaterialTheme.colorScheme.tertiary, + textColor = MaterialTheme.colorScheme.onTertiary, + ) + } +} + +@Composable +fun UnreadBadge( + enabled: Boolean, + item: LibraryItem, +) { + if (enabled && item.unreadCount > 0) { + Badge(text = "${item.unreadCount}") + } +} + +@Composable +fun LanguageBadge( + showLanguage: Boolean, + showLocal: Boolean, + item: LibraryItem, +) { + if (showLocal && item.isLocal) { + Badge( + text = stringResource(R.string.local_source_badge), + color = MaterialTheme.colorScheme.tertiary, + textColor = MaterialTheme.colorScheme.onTertiary, + ) + } else if (showLanguage && item.sourceLanguage.isNotEmpty()) { + Badge( + text = item.sourceLanguage.uppercase(), + color = MaterialTheme.colorScheme.tertiary, + textColor = MaterialTheme.colorScheme.onTertiary, + ) + } +} diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt index cbc37673d5..15bf4b3653 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt @@ -20,6 +20,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem @Composable fun LibraryComfortableGrid( items: List, + showDownloadBadges: Boolean, + showUnreadBadges: Boolean, + showLocalBadges: Boolean, + showLanguageBadges: Boolean, columns: Int, contentPadding: PaddingValues, selection: List, @@ -40,10 +44,14 @@ fun LibraryComfortableGrid( contentType = { "library_comfortable_grid_item" }, ) { libraryItem -> LibraryComfortableGridItem( - libraryItem, - libraryItem.libraryManga in selection, - onClick, - onLongClick, + item = libraryItem, + showDownloadBadge = showDownloadBadges, + showUnreadBadge = showUnreadBadges, + showLocalBadge = showLocalBadges, + showLanguageBadge = showLanguageBadges, + isSelected = libraryItem.libraryManga in selection, + onClick = onClick, + onLongClick = onLongClick, ) } } @@ -52,6 +60,10 @@ fun LibraryComfortableGrid( @Composable fun LibraryComfortableGridItem( item: LibraryItem, + showDownloadBadge: Boolean, + showUnreadBadge: Boolean, + showLocalBadge: Boolean, + showLanguageBadge: Boolean, isSelected: Boolean, onClick: (LibraryManga) -> Unit, onLongClick: (LibraryManga) -> Unit, @@ -78,10 +90,11 @@ fun LibraryComfortableGridItem( manga.thumbnailUrl, manga.coverLastModified, ), - downloadCount = item.downloadCount, - unreadCount = item.unreadCount, - isLocal = item.isLocal, - language = item.sourceLanguage, + item = item, + showDownloadBadge = showDownloadBadge, + showUnreadBadge = showUnreadBadge, + showLocalBadge = showLocalBadge, + showLanguageBadge = showLanguageBadge, ) MangaGridComfortableText( text = manga.title, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt index 6bf1addec6..2e2add29a9 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt @@ -29,6 +29,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem @Composable fun LibraryCompactGrid( items: List, + showDownloadBadges: Boolean, + showUnreadBadges: Boolean, + showLocalBadges: Boolean, + showLanguageBadges: Boolean, columns: Int, contentPadding: PaddingValues, selection: List, @@ -50,6 +54,10 @@ fun LibraryCompactGrid( ) { libraryItem -> LibraryCompactGridItem( item = libraryItem, + showDownloadBadge = showDownloadBadges, + showUnreadBadge = showUnreadBadges, + showLocalBadge = showLocalBadges, + showLanguageBadge = showLanguageBadges, isSelected = libraryItem.libraryManga in selection, onClick = onClick, onLongClick = onLongClick, @@ -61,6 +69,10 @@ fun LibraryCompactGrid( @Composable fun LibraryCompactGridItem( item: LibraryItem, + showDownloadBadge: Boolean, + showUnreadBadge: Boolean, + showLocalBadge: Boolean, + showLanguageBadge: Boolean, isSelected: Boolean, onClick: (LibraryManga) -> Unit, onLongClick: (LibraryManga) -> Unit, @@ -85,10 +97,11 @@ fun LibraryCompactGridItem( manga.thumbnailUrl, manga.coverLastModified, ), - downloadCount = item.downloadCount, - unreadCount = item.unreadCount, - isLocal = item.isLocal, - language = item.sourceLanguage, + item = item, + showDownloadBadge = showDownloadBadge, + showUnreadBadge = showUnreadBadge, + showLocalBadge = showLocalBadge, + showLanguageBadge = showLanguageBadge, ) { Box( modifier = Modifier diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt index 0dc752a73e..fd969b910b 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt @@ -22,7 +22,6 @@ import eu.kanade.domain.library.model.LibraryDisplayMode import eu.kanade.domain.library.model.LibraryManga import eu.kanade.presentation.components.SwipeRefresh import eu.kanade.presentation.library.LibraryState -import eu.kanade.presentation.util.plus import eu.kanade.tachiyomi.ui.library.LibraryItem import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -33,8 +32,6 @@ fun LibraryContent( contentPadding: PaddingValues, currentPage: () -> Int, isLibraryEmpty: Boolean, - isDownloadOnly: Boolean, - isIncognitoMode: Boolean, showPageTabs: Boolean, showMangaCount: Boolean, onChangeCurrentPage: (Int) -> Unit, @@ -47,6 +44,12 @@ fun LibraryContent( getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode, getColumnsForOrientation: (Boolean) -> PreferenceMutableState, getLibraryForPage: @Composable (Int) -> List, + showDownloadBadges: Boolean, + showUnreadBadges: Boolean, + showLocalBadges: Boolean, + showLanguageBadges: Boolean, + isDownloadOnly: Boolean, + isIncognitoMode: Boolean, ) { Column( modifier = Modifier.padding( @@ -106,6 +109,10 @@ fun LibraryContent( getDisplayModeForPage = getDisplayModeForPage, getColumnsForOrientation = getColumnsForOrientation, getLibraryForPage = getLibraryForPage, + showDownloadBadges = showDownloadBadges, + showUnreadBadges = showUnreadBadges, + showLocalBadges = showLocalBadges, + showLanguageBadges = showLanguageBadges, onClickManga = onClickManga, onLongClickManga = onLongClickManga, onGlobalSearchClicked = onGlobalSearchClicked, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt index 160a8ca840..fb1fa59024 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt @@ -12,6 +12,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem @Composable fun LibraryCoverOnlyGrid( items: List, + showDownloadBadges: Boolean, + showUnreadBadges: Boolean, + showLocalBadges: Boolean, + showLanguageBadges: Boolean, columns: Int, contentPadding: PaddingValues, selection: List, @@ -33,6 +37,10 @@ fun LibraryCoverOnlyGrid( ) { libraryItem -> LibraryCoverOnlyGridItem( item = libraryItem, + showDownloadBadge = showDownloadBadges, + showUnreadBadge = showUnreadBadges, + showLocalBadge = showLocalBadges, + showLanguageBadge = showLanguageBadges, isSelected = libraryItem.libraryManga in selection, onClick = onClick, onLongClick = onLongClick, @@ -44,6 +52,10 @@ fun LibraryCoverOnlyGrid( @Composable fun LibraryCoverOnlyGridItem( item: LibraryItem, + showDownloadBadge: Boolean, + showUnreadBadge: Boolean, + showLocalBadge: Boolean, + showLanguageBadge: Boolean, isSelected: Boolean, onClick: (LibraryManga) -> Unit, onLongClick: (LibraryManga) -> Unit, @@ -68,9 +80,10 @@ fun LibraryCoverOnlyGridItem( manga.thumbnailUrl, manga.coverLastModified, ), - downloadCount = item.downloadCount, - unreadCount = item.unreadCount, - isLocal = item.isLocal, - language = item.sourceLanguage, + item = item, + showDownloadBadge = showDownloadBadge, + showUnreadBadge = showUnreadBadge, + showLocalBadge = showLocalBadge, + showLanguageBadge = showLanguageBadge, ) } diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryGridCover.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryGridCover.kt index e7b110d761..6483e9affd 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryGridCover.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryGridCover.kt @@ -6,16 +6,13 @@ import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import eu.kanade.presentation.components.Badge import eu.kanade.presentation.components.BadgeGroup import eu.kanade.presentation.components.MangaCover -import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.library.LibraryItem @Composable fun MangaGridCover( @@ -56,10 +53,11 @@ fun MangaGridCover( fun LibraryGridCover( modifier: Modifier = Modifier, mangaCover: eu.kanade.domain.manga.model.MangaCover, - downloadCount: Long, - unreadCount: Long, - isLocal: Boolean, - language: String, + item: LibraryItem, + showDownloadBadge: Boolean, + showUnreadBadge: Boolean, + showLocalBadge: Boolean, + showLanguageBadge: Boolean, content: @Composable BoxScope.() -> Unit = {}, ) { MangaGridCover( @@ -71,31 +69,11 @@ fun LibraryGridCover( ) }, badgesStart = { - if (downloadCount > 0) { - Badge( - text = "$downloadCount", - color = MaterialTheme.colorScheme.tertiary, - textColor = MaterialTheme.colorScheme.onTertiary, - ) - } - if (unreadCount > 0) { - Badge(text = "$unreadCount") - } + DownloadsBadge(enabled = showDownloadBadge, item = item) + UnreadBadge(enabled = showUnreadBadge, item = item) }, badgesEnd = { - if (isLocal) { - Badge( - text = stringResource(R.string.local_source_badge), - color = MaterialTheme.colorScheme.tertiary, - textColor = MaterialTheme.colorScheme.onTertiary, - ) - } else if (language.isNotEmpty()) { - Badge( - text = language, - color = MaterialTheme.colorScheme.tertiary, - textColor = MaterialTheme.colorScheme.onTertiary, - ) - } + LanguageBadge(showLanguage = showLanguageBadge, showLocal = showLocalBadge, item = item) }, content = content, ) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt index e7644a0b3e..c56ad4bd83 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt @@ -21,7 +21,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import eu.kanade.domain.library.model.LibraryManga import eu.kanade.domain.manga.model.MangaCover -import eu.kanade.presentation.components.Badge import eu.kanade.presentation.components.BadgeGroup import eu.kanade.presentation.components.FastScrollLazyColumn import eu.kanade.presentation.components.MangaCover.Square @@ -35,6 +34,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem @Composable fun LibraryList( items: List, + showDownloadBadges: Boolean, + showUnreadBadges: Boolean, + showLocalBadges: Boolean, + showLanguageBadges: Boolean, contentPadding: PaddingValues, selection: List, onClick: (LibraryManga) -> Unit, @@ -63,6 +66,10 @@ fun LibraryList( ) { libraryItem -> LibraryListItem( item = libraryItem, + showDownloadBadge = showDownloadBadges, + showUnreadBadge = showUnreadBadges, + showLocalBadge = showLocalBadges, + showLanguageBadge = showLanguageBadges, isSelected = libraryItem.libraryManga in selection, onClick = onClick, onLongClick = onLongClick, @@ -74,6 +81,10 @@ fun LibraryList( @Composable fun LibraryListItem( item: LibraryItem, + showDownloadBadge: Boolean, + showUnreadBadge: Boolean, + showLocalBadge: Boolean, + showLanguageBadge: Boolean, isSelected: Boolean, onClick: (LibraryManga) -> Unit, onLongClick: (LibraryManga) -> Unit, @@ -93,30 +104,9 @@ fun LibraryListItem( onClick = { onClick(libraryManga) }, onLongClick = { onLongClick(libraryManga) }, ) { - if (item.downloadCount > 0) { - Badge( - text = "${item.downloadCount}", - color = MaterialTheme.colorScheme.tertiary, - textColor = MaterialTheme.colorScheme.onTertiary, - ) - } - if (item.unreadCount > 0) { - Badge(text = "${item.unreadCount}") - } - if (item.isLocal) { - Badge( - text = stringResource(R.string.local_source_badge), - color = MaterialTheme.colorScheme.tertiary, - textColor = MaterialTheme.colorScheme.onTertiary, - ) - } - if (item.isLocal.not() && item.sourceLanguage.isNotEmpty()) { - Badge( - text = item.sourceLanguage, - color = MaterialTheme.colorScheme.tertiary, - textColor = MaterialTheme.colorScheme.onTertiary, - ) - } + DownloadsBadge(enabled = showDownloadBadge, item = item) + UnreadBadge(enabled = showUnreadBadge, item = item) + LanguageBadge(showLanguage = showLanguageBadge, showLocal = showLocalBadge, item = item) } } diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt index 15a6582c53..6b889eafd3 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt @@ -28,6 +28,10 @@ fun LibraryPager( getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode, getColumnsForOrientation: (Boolean) -> PreferenceMutableState, getLibraryForPage: @Composable (Int) -> List, + showDownloadBadges: Boolean, + showUnreadBadges: Boolean, + showLocalBadges: Boolean, + showLanguageBadges: Boolean, onClickManga: (LibraryManga) -> Unit, onLongClickManga: (LibraryManga) -> Unit, ) { @@ -56,6 +60,10 @@ fun LibraryPager( LibraryDisplayMode.List -> { LibraryList( items = library, + showDownloadBadges = showDownloadBadges, + showUnreadBadges = showUnreadBadges, + showLocalBadges = showLocalBadges, + showLanguageBadges = showLanguageBadges, contentPadding = contentPadding, selection = selectedManga, onClick = onClickManga, @@ -67,6 +75,10 @@ fun LibraryPager( LibraryDisplayMode.CompactGrid -> { LibraryCompactGrid( items = library, + showDownloadBadges = showDownloadBadges, + showUnreadBadges = showUnreadBadges, + showLocalBadges = showLocalBadges, + showLanguageBadges = showLanguageBadges, columns = columns, contentPadding = contentPadding, selection = selectedManga, @@ -79,6 +91,10 @@ fun LibraryPager( LibraryDisplayMode.ComfortableGrid -> { LibraryComfortableGrid( items = library, + showDownloadBadges = showDownloadBadges, + showUnreadBadges = showUnreadBadges, + showLocalBadges = showLocalBadges, + showLanguageBadges = showLanguageBadges, columns = columns, contentPadding = contentPadding, selection = selectedManga, @@ -91,6 +107,10 @@ fun LibraryPager( LibraryDisplayMode.CoverOnlyGrid -> { LibraryCoverOnlyGrid( items = library, + showDownloadBadges = showDownloadBadges, + showUnreadBadges = showUnreadBadges, + showLocalBadges = showLocalBadges, + showLanguageBadges = showLanguageBadges, columns = columns, contentPadding = contentPadding, selection = selectedManga, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index b6eb4b90f9..50bce45589 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -127,9 +127,7 @@ class LibraryController( when (group) { is LibrarySettingsSheet.Filter.FilterGroup -> onFilterChanged() is LibrarySettingsSheet.Sort.SortGroup -> onSortChanged() - is LibrarySettingsSheet.Display.DisplayGroup -> {} - is LibrarySettingsSheet.Display.BadgeGroup -> onBadgeSettingChanged() - is LibrarySettingsSheet.Display.TabsGroup -> {} // onTabsSettingsChanged() + else -> {} // Handled via different mechanisms } } } @@ -158,10 +156,6 @@ class LibraryController( activity?.invalidateOptionsMenu() } - private fun onBadgeSettingChanged() { - presenter.requestBadgesUpdate() - } - private fun onSortChanged() { presenter.requestSortUpdate() } 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 d8fde9334b..6dd94c5b9f 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 @@ -106,6 +106,11 @@ class LibraryPresenter( val tabVisibility by libraryPreferences.categoryTabs().asState() val mangaCountVisibility by libraryPreferences.categoryNumberOfItems().asState() + val showDownloadBadges by libraryPreferences.downloadBadge().asState() + val showUnreadBadges by libraryPreferences.unreadBadge().asState() + val showLocalBadges by libraryPreferences.localBadge().asState() + val showLanguageBadges by libraryPreferences.languageBadge().asState() + var activeCategory: Int by libraryPreferences.lastUsedCategory().asState() val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() @@ -116,11 +121,6 @@ class LibraryPresenter( */ private val filterTriggerRelay = BehaviorRelay.create(Unit) - /** - * Relay used to apply the UI update to the last emission of the library. - */ - private val badgeTriggerRelay = BehaviorRelay.create(Unit) - /** * Relay used to apply the selected sorting method to the last emission of the library. */ @@ -142,14 +142,11 @@ class LibraryPresenter( * TODO: Move this to a coroutine world * - Move filter and sort to getMangaForCategory and only filter and sort the current display category instead of whole library as some has 5000+ items in the library * - Create new db view and new query to just fetch the current category save as needed to instance variable - * - Fetch badges to maps and retrive as needed instead of fetching all of them at once + * - Fetch badges to maps and retrieve as needed instead of fetching all of them at once */ if (librarySubscription == null || librarySubscription!!.isCancelled) { librarySubscription = presenterScope.launchIO { getLibraryFlow().asObservable() - .combineLatest(badgeTriggerRelay.observeOn(Schedulers.io())) { lib, _ -> - lib.apply { setBadges(mangaMap) } - } .combineLatest(getFilterObservable()) { lib, tracks -> lib.copy(mangaMap = applyFilters(lib.mangaMap, tracks)) } @@ -201,7 +198,7 @@ class LibraryPresenter( val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item -> if (filterUnread == State.IGNORE.value) return@unread true - val isUnread = item.libraryManga.unreadCount != 0L + val isUnread = item.libraryManga.unreadCount > 0 return@unread if (filterUnread == State.INCLUDE.value) { isUnread @@ -283,50 +280,6 @@ class LibraryPresenter( return map.mapValues { entry -> entry.value.filter(filterFn) } } - /** - * Sets downloaded chapter count to each manga. - * - * @param map the map of manga. - */ - private fun setBadges(map: LibraryMap) { - val showDownloadBadges = libraryPreferences.downloadBadge().get() - val showUnreadBadges = libraryPreferences.unreadBadge().get() - val showLocalBadges = libraryPreferences.localBadge().get() - val showLanguageBadges = libraryPreferences.languageBadge().get() - - for ((_, itemList) in map) { - for (item in itemList) { - item.downloadCount = if (showDownloadBadges) { - downloadManager.getDownloadCount(item.libraryManga.manga).toLong() - } else { - // Unset download count if not enabled - -1 - } - - item.unreadCount = if (showUnreadBadges) { - item.libraryManga.unreadCount - } else { - // Unset unread count if not enabled - -1 - } - - item.isLocal = if (showLocalBadges) { - item.libraryManga.manga.isLocal() - } else { - // Hide / Unset local badge if not enabled - false - } - - item.sourceLanguage = if (showLanguageBadges) { - sourceManager.getOrStub(item.libraryManga.manga.source).lang.uppercase() - } else { - // Unset source language if not enabled - "" - } - } - } - } - /** * Applies library sorting to the given map of manga. * @@ -434,8 +387,13 @@ class LibraryPresenter( .map { list -> list.map { libraryManga -> // Display mode based on user preference: take it from global library setting or category - LibraryItem(libraryManga) - }.groupBy { it.libraryManga.category.toLong() } + LibraryItem(libraryManga).apply { + downloadCount = downloadManager.getDownloadCount(libraryManga.manga).toLong() + unreadCount = libraryManga.unreadCount + isLocal = libraryManga.manga.isLocal() + sourceLanguage = sourceManager.getOrStub(libraryManga.manga.source).lang + } + }.groupBy { it.libraryManga.category } } return combine(categoriesFlow, libraryMangasFlow) { dbCategories, libraryManga -> val categories = if (libraryManga.isNotEmpty() && libraryManga.containsKey(0).not()) { @@ -456,7 +414,7 @@ class LibraryPresenter( */ private fun getFilterObservable(): Observable>> { return filterTriggerRelay.observeOn(Schedulers.io()) - .combineLatest(getTracksObservable()) { _, tracks -> tracks } + .combineLatest(getTracksFlow().asObservable().observeOn(Schedulers.io())) { _, tracks -> tracks } } /** @@ -464,7 +422,7 @@ class LibraryPresenter( * * @return an observable of tracked manga. */ - private fun getTracksObservable(): Observable>> { + private fun getTracksFlow(): Flow>> { // TODO: Move this to domain/data layer return getTracks.subscribe() .map { tracks -> @@ -477,8 +435,6 @@ class LibraryPresenter( } } } - .asObservable() - .observeOn(Schedulers.io()) } /** @@ -488,13 +444,6 @@ class LibraryPresenter( filterTriggerRelay.call(Unit) } - /** - * Requests the library to have download badges added. - */ - fun requestBadgesUpdate() { - badgeTriggerRelay.call(Unit) - } - /** * Requests the library to be sorted. */