Fix library sorting
This commit is contained in:
parent
bcad021e00
commit
3da9f2e067
@ -164,15 +164,21 @@ class LibraryScreenModel(
|
|||||||
getTracksPerManga.subscribe(),
|
getTracksPerManga.subscribe(),
|
||||||
getTrackingFilterFlow(),
|
getTrackingFilterFlow(),
|
||||||
// SY -->
|
// SY -->
|
||||||
combine(state.map { it.groupType }.distinctUntilChanged(), libraryPreferences.libraryDisplayMode().changes()) { a, b -> a to b },
|
combine(
|
||||||
|
state.map { it.groupType }.distinctUntilChanged(),
|
||||||
|
libraryPreferences.libraryDisplayMode().changes(),
|
||||||
|
libraryPreferences.librarySortingMode().changes()
|
||||||
|
) { a, b, c ->
|
||||||
|
Triple(a, b, c)
|
||||||
|
},
|
||||||
// SY <--
|
// SY <--
|
||||||
) { searchQuery, library, tracks, loggedInTrackServices, (groupType, displayMode) ->
|
) { searchQuery, library, tracks, loggedInTrackServices, (groupType, displayMode, sort) ->
|
||||||
library
|
library
|
||||||
.applyFilters(tracks, loggedInTrackServices)
|
.applyFilters(tracks, loggedInTrackServices)
|
||||||
.applySort(/* SY --> */groupType/* SY <-- */)
|
|
||||||
// SY -->
|
// SY -->
|
||||||
.applyGrouping(groupType, displayMode)
|
.applyGrouping(groupType, displayMode)
|
||||||
// SY <--
|
// SY <--
|
||||||
|
.applySort(/* SY --> */sort.takeIf { groupType != LibraryGroup.BY_DEFAULT }/* SY <-- */)
|
||||||
.mapValues { (_, value) ->
|
.mapValues { (_, value) ->
|
||||||
if (searchQuery != null) {
|
if (searchQuery != null) {
|
||||||
// Filter query
|
// Filter query
|
||||||
@ -395,7 +401,7 @@ class LibraryScreenModel(
|
|||||||
/**
|
/**
|
||||||
* Applies library sorting to the given map of manga.
|
* Applies library sorting to the given map of manga.
|
||||||
*/
|
*/
|
||||||
private fun LibraryMap.applySort(/* SY --> */ groupType: Int /* SY <-- */): LibraryMap {
|
private fun LibraryMap.applySort(/* SY --> */ groupSort: LibrarySort? = null /* SY <-- */): LibraryMap {
|
||||||
// SY -->
|
// SY -->
|
||||||
val listOfTags by lazy {
|
val listOfTags by lazy {
|
||||||
libraryPreferences.sortTagsForLibrary().get()
|
libraryPreferences.sortTagsForLibrary().get()
|
||||||
@ -408,7 +414,6 @@ class LibraryScreenModel(
|
|||||||
.map { it.second }
|
.map { it.second }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
val groupSort = libraryPreferences.librarySortingMode().get()
|
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
val locale = Locale.getDefault()
|
val locale = Locale.getDefault()
|
||||||
@ -421,10 +426,7 @@ class LibraryScreenModel(
|
|||||||
|
|
||||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
||||||
// SY -->
|
// SY -->
|
||||||
val sort = when (groupType) {
|
val sort = groupSort ?: keys.find { it.id == i1.libraryManga.category }!!.sort
|
||||||
LibraryGroup.BY_DEFAULT -> keys.find { it.id == i1.libraryManga.category }!!.sort
|
|
||||||
else -> groupSort
|
|
||||||
}
|
|
||||||
// SY <--
|
// SY <--
|
||||||
when (sort.type) {
|
when (sort.type) {
|
||||||
LibrarySort.Type.Alphabetical -> {
|
LibrarySort.Type.Alphabetical -> {
|
||||||
@ -467,11 +469,7 @@ class LibraryScreenModel(
|
|||||||
|
|
||||||
return this.mapValues { entry ->
|
return this.mapValues { entry ->
|
||||||
// SY -->
|
// SY -->
|
||||||
val isAscending = if (groupType == LibraryGroup.BY_DEFAULT) {
|
val isAscending = groupSort?.isAscending ?: keys.find { it.id == entry.key.id }!!.sort.isAscending
|
||||||
keys.find { it.id == entry.key.id }!!.sort.isAscending
|
|
||||||
} else {
|
|
||||||
groupSort.isAscending
|
|
||||||
}
|
|
||||||
// SY <--
|
// SY <--
|
||||||
val comparator = if ( /* SY --> */ isAscending /* SY <-- */) {
|
val comparator = if ( /* SY --> */ isAscending /* SY <-- */) {
|
||||||
Comparator(sortFn)
|
Comparator(sortFn)
|
||||||
@ -1175,7 +1173,11 @@ class LibraryScreenModel(
|
|||||||
return getNextChapters.await(manga.id).firstOrNull()
|
return getNextChapters.await(manga.id).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getGroupedMangaItems(groupType: Int, libraryManga: List<LibraryItem>, displayMode: LibraryDisplayMode): LibraryMap {
|
private fun getGroupedMangaItems(
|
||||||
|
groupType: Int,
|
||||||
|
libraryManga: List<LibraryItem>,
|
||||||
|
displayMode: LibraryDisplayMode
|
||||||
|
): LibraryMap {
|
||||||
val context = preferences.context
|
val context = preferences.context
|
||||||
return when (groupType) {
|
return when (groupType) {
|
||||||
LibraryGroup.BY_TRACK_STATUS -> {
|
LibraryGroup.BY_TRACK_STATUS -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user