chore(library): Optimize library grouping (#1153)
* chore(library): Optimize library grouping (cherry picked from commit 2f89d98cf9f0568401b39c09fdffe9fb3ece1fda) * refactor(library): Avoiding a redundant iteration when grouping by Track Status * fix(strings): Remove unnecessary period from search/filtering string
This commit is contained in:
parent
f15ce1b433
commit
296a314429
2 changed files with 28 additions and 29 deletions
|
|
@ -1470,15 +1470,15 @@ class LibraryScreenModel(
|
||||||
}
|
}
|
||||||
// KMK <--
|
// KMK <--
|
||||||
groupCache.mapKeys { (id) ->
|
groupCache.mapKeys { (id) ->
|
||||||
|
// KMK -->
|
||||||
|
val trackStatus = TrackStatus.entries.find { it.int == id } ?: TrackStatus.OTHER
|
||||||
|
// KMK <--
|
||||||
Category(
|
Category(
|
||||||
id = id.toLong(),
|
id = id.toLong(),
|
||||||
name = TrackStatus.entries
|
// KMK -->
|
||||||
.find { it.int == id }
|
name = context.stringResource(trackStatus.res),
|
||||||
.let { it ?: TrackStatus.OTHER }
|
order = trackStatus.ordinal.toLong(),
|
||||||
.let { context.stringResource(it.res) },
|
// KMK <--
|
||||||
order = TrackStatus.entries.indexOfFirst {
|
|
||||||
it.int == id
|
|
||||||
}.takeUnless { it == -1 }?.toLong() ?: TrackStatus.OTHER.ordinal.toLong(),
|
|
||||||
flags = 0,
|
flags = 0,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
hidden = false,
|
hidden = false,
|
||||||
|
|
@ -1498,6 +1498,7 @@ class LibraryScreenModel(
|
||||||
val sources = groupCache.keys
|
val sources = groupCache.keys
|
||||||
.map { sourceManager.getOrStub(it) }
|
.map { sourceManager.getOrStub(it) }
|
||||||
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name.ifBlank { it.id.toString() } })
|
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name.ifBlank { it.id.toString() } })
|
||||||
|
val sourceOrderMap = sources.withIndex().associate { (index, source) -> source.id to index.toLong() }
|
||||||
|
|
||||||
sources.associate {
|
sources.associate {
|
||||||
val category = Category(
|
val category = Category(
|
||||||
|
|
@ -1507,13 +1508,13 @@ class LibraryScreenModel(
|
||||||
} else {
|
} else {
|
||||||
it.name.ifBlank { it.id.toString() }
|
it.name.ifBlank { it.id.toString() }
|
||||||
},
|
},
|
||||||
order = sources.indexOf(it).toLong(),
|
order = sourceOrderMap[it.id] ?: Long.MAX_VALUE,
|
||||||
flags = 0,
|
flags = 0,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
hidden = false,
|
hidden = false,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
)
|
)
|
||||||
category to groupCache[it.id]?.distinct().orEmpty()
|
category to groupCache[it.id].orEmpty()
|
||||||
}
|
}
|
||||||
// KMK <--
|
// KMK <--
|
||||||
}
|
}
|
||||||
|
|
@ -1521,26 +1522,13 @@ class LibraryScreenModel(
|
||||||
groupBy { item ->
|
groupBy { item ->
|
||||||
item.libraryManga.manga.status
|
item.libraryManga.manga.status
|
||||||
}.mapKeys {
|
}.mapKeys {
|
||||||
|
// KMK -->
|
||||||
|
val (nameRes, order) = statusMap[it.key] ?: (MR.strings.unknown to 7L)
|
||||||
|
// KMK <--
|
||||||
Category(
|
Category(
|
||||||
id = it.key + 1,
|
id = it.key + 1,
|
||||||
name = when (it.key) {
|
name = context.stringResource(nameRes),
|
||||||
SManga.ONGOING.toLong() -> context.stringResource(MR.strings.ongoing)
|
order = order,
|
||||||
SManga.LICENSED.toLong() -> context.stringResource(MR.strings.licensed)
|
|
||||||
SManga.CANCELLED.toLong() -> context.stringResource(MR.strings.cancelled)
|
|
||||||
SManga.ON_HIATUS.toLong() -> context.stringResource(MR.strings.on_hiatus)
|
|
||||||
SManga.PUBLISHING_FINISHED.toLong() -> context.stringResource(MR.strings.publishing_finished)
|
|
||||||
SManga.COMPLETED.toLong() -> context.stringResource(MR.strings.completed)
|
|
||||||
else -> context.stringResource(MR.strings.unknown)
|
|
||||||
},
|
|
||||||
order = when (it.key) {
|
|
||||||
SManga.ONGOING.toLong() -> 1
|
|
||||||
SManga.LICENSED.toLong() -> 2
|
|
||||||
SManga.CANCELLED.toLong() -> 3
|
|
||||||
SManga.ON_HIATUS.toLong() -> 4
|
|
||||||
SManga.PUBLISHING_FINISHED.toLong() -> 5
|
|
||||||
SManga.COMPLETED.toLong() -> 6
|
|
||||||
else -> 7
|
|
||||||
},
|
|
||||||
flags = 0,
|
flags = 0,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
hidden = false,
|
hidden = false,
|
||||||
|
|
@ -1548,13 +1536,24 @@ class LibraryScreenModel(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// KMK -->
|
// KMK -->
|
||||||
.mapValues { (_, libraryItem) -> libraryItem.fastMap { it.id }.distinct() }
|
.mapValues { (_, libraryItem) -> libraryItem.fastMap { it.id } }
|
||||||
// KMK <--
|
// KMK <--
|
||||||
}
|
}
|
||||||
else -> emptyMap()
|
else -> emptyMap()
|
||||||
}.toSortedMap(compareBy { it.order })
|
}.toSortedMap(compareBy { it.order })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
private val statusMap = mapOf(
|
||||||
|
SManga.ONGOING.toLong() to (MR.strings.ongoing to 1L),
|
||||||
|
SManga.COMPLETED.toLong() to (MR.strings.completed to 2L),
|
||||||
|
SManga.PUBLISHING_FINISHED.toLong() to (MR.strings.publishing_finished to 3L),
|
||||||
|
SManga.LICENSED.toLong() to (MR.strings.licensed to 4L),
|
||||||
|
SManga.ON_HIATUS.toLong() to (MR.strings.on_hiatus to 5L),
|
||||||
|
SManga.CANCELLED.toLong() to (MR.strings.cancelled to 6L),
|
||||||
|
)
|
||||||
|
// KMK <--
|
||||||
|
|
||||||
fun runRecommendationSearch(selection: List<Manga>) {
|
fun runRecommendationSearch(selection: List<Manga>) {
|
||||||
recommendationSearch.runSearch(screenModelScope, selection)?.let {
|
recommendationSearch.runSearch(screenModelScope, selection)?.let {
|
||||||
recommendationSearchJob = it
|
recommendationSearchJob = it
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@
|
||||||
<string name="action_display_language_icon">Use language icon</string>
|
<string name="action_display_language_icon">Use language icon</string>
|
||||||
<string name="pref_library_filter_categories_details">Entries in excluded categories will not be shown even if they are also in included categories.</string>
|
<string name="pref_library_filter_categories_details">Entries in excluded categories will not be shown even if they are also in included categories.</string>
|
||||||
<string name="updating">Updating</string>
|
<string name="updating">Updating</string>
|
||||||
<string name="pref_show_empty_categories_search">Show empty categories during search/filtering.</string>
|
<string name="pref_show_empty_categories_search">Show empty categories during search/filtering</string>
|
||||||
<!-- Extension section -->
|
<!-- Extension section -->
|
||||||
<string name="extensions_page_need_refresh">Refresh extension page to update list.</string>
|
<string name="extensions_page_need_refresh">Refresh extension page to update list.</string>
|
||||||
<string name="extensions_page_more">More extensions...</string>
|
<string name="extensions_page_more">More extensions...</string>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue