Cleanup LibraryScreenModel
LibraryMap.applySort
and some more
(cherry picked from commit 2beb89d53163a6d288f8acdebe0f5d26fea8ab3e) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt
This commit is contained in:
parent
ea0816a6c1
commit
bd278b1878
@ -117,7 +117,6 @@ import tachiyomi.source.local.LocalSource
|
|||||||
import tachiyomi.source.local.isLocal
|
import tachiyomi.source.local.isLocal
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.util.Collections
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Typealias for the library manga, using the category as keys, and list of manga as values.
|
* Typealias for the library manga, using the category as keys, and list of manga as values.
|
||||||
@ -178,25 +177,23 @@ class LibraryScreenModel(
|
|||||||
::Pair,
|
::Pair,
|
||||||
),
|
),
|
||||||
// SY <--
|
// SY <--
|
||||||
) { searchQuery, library, tracks, (trackingFiler, _), (groupType, sort) ->
|
) { searchQuery, library, tracks, (trackingFilter, _), (groupType, sort) ->
|
||||||
library
|
library
|
||||||
// SY -->
|
// SY -->
|
||||||
.applyGrouping(groupType)
|
.applyGrouping(groupType)
|
||||||
// SY <--
|
// SY <--
|
||||||
.applyFilters(tracks, trackingFiler)
|
.applyFilters(tracks, trackingFilter)
|
||||||
.applySort(
|
.applySort(
|
||||||
tracks, trackingFiler.keys, /* SY --> */sort.takeIf {
|
tracks, trackingFilter.keys, /* SY --> */sort.takeIf {
|
||||||
groupType != LibraryGroup.BY_DEFAULT
|
groupType != LibraryGroup.BY_DEFAULT
|
||||||
}, /* SY <-- */
|
}, /* SY <-- */
|
||||||
)
|
)
|
||||||
.mapValues { (_, value) ->
|
.mapValues { (_, value) ->
|
||||||
if (searchQuery != null) {
|
if (searchQuery != null) {
|
||||||
// Filter query
|
|
||||||
// SY -->
|
// SY -->
|
||||||
filterLibrary(value, searchQuery, trackingFiler)
|
filterLibrary(value, searchQuery, trackingFilter)
|
||||||
// SY <--
|
// SY <--
|
||||||
} else {
|
} else {
|
||||||
// Don't do anything
|
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,12 +276,9 @@ class LibraryScreenModel(
|
|||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies library filters to the given map of manga.
|
|
||||||
*/
|
|
||||||
private suspend fun LibraryMap.applyFilters(
|
private suspend fun LibraryMap.applyFilters(
|
||||||
trackMap: Map<Long, List<Track>>,
|
trackMap: Map<Long, List<Track>>,
|
||||||
trackingFiler: Map<Long, TriState>,
|
trackingFilter: Map<Long, TriState>,
|
||||||
): LibraryMap {
|
): LibraryMap {
|
||||||
val prefs = getLibraryItemPreferencesFlow().first()
|
val prefs = getLibraryItemPreferencesFlow().first()
|
||||||
val downloadedOnly = prefs.globalFilterDownloaded
|
val downloadedOnly = prefs.globalFilterDownloaded
|
||||||
@ -296,10 +290,10 @@ class LibraryScreenModel(
|
|||||||
val filterCompleted = prefs.filterCompleted
|
val filterCompleted = prefs.filterCompleted
|
||||||
val filterIntervalCustom = prefs.filterIntervalCustom
|
val filterIntervalCustom = prefs.filterIntervalCustom
|
||||||
|
|
||||||
val isNotLoggedInAnyTrack = trackingFiler.isEmpty()
|
val isNotLoggedInAnyTrack = trackingFilter.isEmpty()
|
||||||
|
|
||||||
val excludedTracks = trackingFiler.mapNotNull { if (it.value == TriState.ENABLED_NOT) it.key else null }
|
val excludedTracks = trackingFilter.mapNotNull { if (it.value == TriState.ENABLED_NOT) it.key else null }
|
||||||
val includedTracks = trackingFiler.mapNotNull { if (it.value == TriState.ENABLED_IS) it.key else null }
|
val includedTracks = trackingFilter.mapNotNull { if (it.value == TriState.ENABLED_IS) it.key else null }
|
||||||
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
|
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -370,14 +364,13 @@ class LibraryScreenModel(
|
|||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mapValues { entry -> entry.value.fastFilter(filterFn) }
|
return mapValues { (_, value) -> value.fastFilter(filterFn) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies library sorting to the given map of manga.
|
* Applies library sorting to the given map of manga.
|
||||||
*/
|
*/
|
||||||
private fun LibraryMap.applySort(
|
private fun LibraryMap.applySort(
|
||||||
// Map<MangaId, List<Track>>
|
|
||||||
trackMap: Map<Long, List<Track>>,
|
trackMap: Map<Long, List<Track>>,
|
||||||
loggedInTrackerIds: Set<Long>,
|
loggedInTrackerIds: Set<Long>,
|
||||||
/* SY --> */
|
/* SY --> */
|
||||||
@ -416,9 +409,9 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
fun LibrarySort.comparator(): Comparator<LibraryItem> = Comparator { i1, i2 ->
|
||||||
// SY -->
|
// SY -->
|
||||||
val sort = groupSort ?: keys.find { it.id == i1.libraryManga.category }!!.sort
|
val sort = groupSort ?: this
|
||||||
// SY <--
|
// SY <--
|
||||||
when (sort.type) {
|
when (sort.type) {
|
||||||
LibrarySort.Type.Alphabetical -> {
|
LibrarySort.Type.Alphabetical -> {
|
||||||
@ -468,17 +461,15 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mapValues { entry ->
|
return mapValues { (key, value) ->
|
||||||
// SY -->
|
// SY -->
|
||||||
val isAscending = groupSort?.isAscending ?: keys.find { it.id == entry.key.id }!!.sort.isAscending
|
val isAscending = groupSort?.isAscending ?: key.sort.isAscending
|
||||||
// SY <--
|
// SY <--
|
||||||
val comparator = if ( /* SY --> */ isAscending /* SY <-- */) {
|
val comparator = key.sort.comparator()
|
||||||
Comparator(sortFn)
|
.let { if (/* SY --> */ isAscending /* SY <-- */) it else it.reversed() }
|
||||||
} else {
|
.thenComparator(sortAlphabetically)
|
||||||
Collections.reverseOrder(sortFn)
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.value.sortedWith(comparator.thenComparator(sortAlphabetically))
|
value.sortedWith(comparator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user