mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 05:01:52 +01:00
parent
27e5256305
commit
6635dd2990
@ -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,
|
||||
)
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
@ -20,6 +20,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||
@Composable
|
||||
fun LibraryComfortableGrid(
|
||||
items: List<LibraryItem>,
|
||||
showDownloadBadges: Boolean,
|
||||
showUnreadBadges: Boolean,
|
||||
showLocalBadges: Boolean,
|
||||
showLanguageBadges: Boolean,
|
||||
columns: Int,
|
||||
contentPadding: PaddingValues,
|
||||
selection: List<LibraryManga>,
|
||||
@ -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,
|
||||
|
@ -29,6 +29,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||
@Composable
|
||||
fun LibraryCompactGrid(
|
||||
items: List<LibraryItem>,
|
||||
showDownloadBadges: Boolean,
|
||||
showUnreadBadges: Boolean,
|
||||
showLocalBadges: Boolean,
|
||||
showLanguageBadges: Boolean,
|
||||
columns: Int,
|
||||
contentPadding: PaddingValues,
|
||||
selection: List<LibraryManga>,
|
||||
@ -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
|
||||
|
@ -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<Int>,
|
||||
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
|
||||
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,
|
||||
|
@ -12,6 +12,10 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||
@Composable
|
||||
fun LibraryCoverOnlyGrid(
|
||||
items: List<LibraryItem>,
|
||||
showDownloadBadges: Boolean,
|
||||
showUnreadBadges: Boolean,
|
||||
showLocalBadges: Boolean,
|
||||
showLanguageBadges: Boolean,
|
||||
columns: Int,
|
||||
contentPadding: PaddingValues,
|
||||
selection: List<LibraryManga>,
|
||||
@ -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,
|
||||
)
|
||||
}
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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<LibraryItem>,
|
||||
showDownloadBadges: Boolean,
|
||||
showUnreadBadges: Boolean,
|
||||
showLocalBadges: Boolean,
|
||||
showLanguageBadges: Boolean,
|
||||
contentPadding: PaddingValues,
|
||||
selection: List<LibraryManga>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,10 @@ fun LibraryPager(
|
||||
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
|
||||
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
||||
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
|
||||
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,
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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<Map<Long, Map<Long, Boolean>>> {
|
||||
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<Map<Long, Map<Long, Boolean>>> {
|
||||
private fun getTracksFlow(): Flow<Map<Long, Map<Long, Boolean>>> {
|
||||
// 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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user