Extract badge data separately when forming LibraryItem (#3382)

This commit is contained in:
AntsyLich
2026-06-05 00:25:42 +06:00
committed by GitHub
parent a1ad33baef
commit c612a6ca8d
7 changed files with 53 additions and 47 deletions
+1
View File
@@ -20,6 +20,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
### Fixed
- Add missing `outlineVariant` color to Nord theme ([@CompileConnected](https://github.com/CompileConnected)) ([#3184](https://github.com/mihonapp/mihon/pull/3184))
- Continue reading button missing when unread filter is off ([@AntsyLich](https://github.com/AntsyLich)) ([#3382](https://github.com/mihonapp/mihon/pull/3382))
## [v0.19.9] - 2026-04-11
### Fixed
@@ -10,7 +10,7 @@ import eu.kanade.presentation.theme.TachiyomiPreviewTheme
import tachiyomi.presentation.core.components.Badge
@Composable
internal fun DownloadsBadge(count: Long) {
internal fun DownloadsBadge(count: Int) {
if (count > 0) {
Badge(
text = "$count",
@@ -44,13 +44,13 @@ internal fun LibraryComfortableGrid(
lastModified = manga.coverLastModified,
),
coverBadgeStart = {
DownloadsBadge(count = libraryItem.downloadCount)
UnreadBadge(count = libraryItem.unreadCount)
DownloadsBadge(count = libraryItem.badges.downloadCount)
UnreadBadge(count = libraryItem.badges.unreadCount)
},
coverBadgeEnd = {
LanguageBadge(
isLocal = libraryItem.isLocal,
sourceLanguage = libraryItem.sourceLanguage,
isLocal = libraryItem.badges.isLocal,
sourceLanguage = libraryItem.badges.sourceLanguage,
)
},
onLongClick = { onLongClick(libraryItem.libraryManga) },
@@ -45,13 +45,13 @@ internal fun LibraryCompactGrid(
lastModified = manga.coverLastModified,
),
coverBadgeStart = {
DownloadsBadge(count = libraryItem.downloadCount)
UnreadBadge(count = libraryItem.unreadCount)
DownloadsBadge(count = libraryItem.badges.downloadCount)
UnreadBadge(count = libraryItem.badges.unreadCount)
},
coverBadgeEnd = {
LanguageBadge(
isLocal = libraryItem.isLocal,
sourceLanguage = libraryItem.sourceLanguage,
isLocal = libraryItem.badges.isLocal,
sourceLanguage = libraryItem.badges.sourceLanguage,
)
},
onLongClick = { onLongClick(libraryItem.libraryManga) },
@@ -54,11 +54,11 @@ internal fun LibraryList(
lastModified = manga.coverLastModified,
),
badge = {
DownloadsBadge(count = libraryItem.downloadCount)
UnreadBadge(count = libraryItem.unreadCount)
DownloadsBadge(count = libraryItem.badges.downloadCount)
UnreadBadge(count = libraryItem.badges.unreadCount)
LanguageBadge(
isLocal = libraryItem.isLocal,
sourceLanguage = libraryItem.sourceLanguage,
isLocal = libraryItem.badges.isLocal,
sourceLanguage = libraryItem.badges.sourceLanguage,
)
},
onLongClick = { onLongClick(libraryItem.libraryManga) },
@@ -4,18 +4,15 @@ import eu.kanade.tachiyomi.source.getNameForMangaInfo
import tachiyomi.domain.library.model.LibraryManga
import tachiyomi.domain.source.service.SourceManager
import tachiyomi.source.local.LocalSource
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
private const val LOCAL_SOURCE_ID_ALIAS = "local"
data class LibraryItem(
val libraryManga: LibraryManga,
val downloadCount: Long = -1,
val unreadCount: Long = -1,
val isLocal: Boolean = false,
val sourceLanguage: String = "",
private val sourceManager: SourceManager = Injekt.get(),
val downloadCount: Int,
val unreadCount: Long,
val isLocal: Boolean,
val badges: Badges,
) {
val id: Long = libraryManga.id
@@ -25,7 +22,7 @@ data class LibraryItem(
* @param constraint the query to check.
* @return true if the manga matches the query, false otherwise.
*/
fun matches(constraint: String): Boolean {
fun matches(constraint: String, sourceManager: SourceManager): Boolean {
val source = sourceManager.getOrStub(libraryManga.manga.source)
val sourceName by lazy { source.getNameForMangaInfo() }
if (constraint.startsWith("id:", true)) {
@@ -68,4 +65,11 @@ data class LibraryItem(
predicate(constraint)
}
}
data class Badges(
val downloadCount: Int,
val unreadCount: Long,
val isLocal: Boolean,
val sourceLanguage: String,
)
}
@@ -100,7 +100,7 @@ class LibraryScreenModel(
val showSystemCategory = favorites.any { it.libraryManga.categories.contains(0) }
val filteredFavorites = favorites
.applyFilters(tracksMap, trackingFilters, itemPreferences)
.let { if (searchQuery == null) it else it.filter { m -> m.matches(searchQuery) } }
.let { if (searchQuery == null) it else it.filter { m -> m.matches(searchQuery, sourceManager) } }
LibraryData(
isInitialized = true,
@@ -200,11 +200,7 @@ class LibraryScreenModel(
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
val filterFnDownloaded: (LibraryItem) -> Boolean = {
applyFilter(filterDownloaded) {
it.libraryManga.manga.isLocal() ||
it.downloadCount > 0 ||
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
}
applyFilter(filterDownloaded) { it.isLocal || it.downloadCount > 0 }
}
val filterFnUnread: (LibraryItem) -> Boolean = {
@@ -390,26 +386,31 @@ class LibraryScreenModel(
libraryManga.map { manga ->
LibraryItem(
libraryManga = manga,
downloadCount = if (preferences.downloadBadge) {
downloadManager.getDownloadCount(manga.manga).toLong()
} else {
0
},
unreadCount = if (preferences.unreadBadge) {
manga.unreadCount
} else {
0
},
isLocal = if (preferences.localBadge) {
manga.manga.isLocal()
} else {
false
},
sourceLanguage = if (preferences.languageBadge) {
sourceManager.getOrStub(manga.manga.source).lang
} else {
""
},
downloadCount = downloadManager.getDownloadCount(manga.manga),
unreadCount = manga.unreadCount,
isLocal = manga.manga.isLocal(),
badges = LibraryItem.Badges(
downloadCount = if (preferences.downloadBadge) {
downloadManager.getDownloadCount(manga.manga)
} else {
0
},
unreadCount = if (preferences.unreadBadge) {
manga.unreadCount
} else {
0
},
isLocal = if (preferences.localBadge) {
manga.manga.isLocal()
} else {
false
},
sourceLanguage = if (preferences.languageBadge) {
sourceManager.getOrStub(manga.manga.source).lang
} else {
""
},
),
)
}
}