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