Fix crashing library

This commit is contained in:
Jobobby04 2021-06-29 00:05:49 -04:00
parent b7b1175207
commit ee73c0e282

View File

@ -352,17 +352,28 @@ class LibraryPresenter(
} }
// SY <-- // SY <--
val defaultSortingMode = SortModeSetting.get(preferences, null)
val sortingModes = categories.associate { category -> val sortingModes = categories.associate { category ->
(category.id ?: 0) to SortModeSetting.get(preferences, category) (category.id ?: 0) to SortModeSetting.get(preferences, category)
} }
val defaultSortAscending = SortDirectionSetting.get(preferences, null)
val sortAscending = categories.associate { category -> val sortAscending = categories.associate { category ->
(category.id ?: 0) to SortDirectionSetting.get(preferences, category) (category.id ?: 0) to SortDirectionSetting.get(preferences, category)
} }
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 -> val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
val sortingMode = sortingModes[i1.manga.category]!! val sortingMode = if (groupType == LibraryGroup.BY_DEFAULT) {
val sortAscending = sortAscending[i1.manga.category]!! == SortDirectionSetting.ASCENDING sortingModes[i1.manga.category] ?: defaultSortingMode
} else {
defaultSortingMode
}
val sortAscending = if (groupType == LibraryGroup.BY_DEFAULT) {
sortAscending[i1.manga.category] ?: defaultSortAscending
} else {
defaultSortAscending
} == SortDirectionSetting.ASCENDING
when (sortingMode) { when (sortingMode) {
SortModeSetting.ALPHABETICAL -> i1.manga.title.compareTo(i2.manga.title, true) SortModeSetting.ALPHABETICAL -> i1.manga.title.compareTo(i2.manga.title, true)
SortModeSetting.LAST_READ -> { SortModeSetting.LAST_READ -> {
@ -413,7 +424,11 @@ class LibraryPresenter(
} }
return map.mapValues { entry -> return map.mapValues { entry ->
val sortAscending = sortAscending[entry.key]!! == SortDirectionSetting.ASCENDING val sortAscending = if (groupType == LibraryGroup.BY_DEFAULT) {
sortAscending[entry.key] ?: defaultSortAscending
} else {
defaultSortAscending
} == SortDirectionSetting.ASCENDING
val comparator = if (sortAscending) { val comparator = if (sortAscending) {
Comparator(sortFn) Comparator(sortFn)
@ -834,18 +849,13 @@ class LibraryPresenter(
} }
} }
val categories = ( val categories = when (groupType) {
when (groupType) { LibraryGroup.BY_SOURCE -> grouping.sortedBy { it.third.lowercase() }
LibraryGroup.BY_SOURCE -> grouping.sortedBy { it.third.lowercase() } LibraryGroup.BY_TRACK_STATUS, LibraryGroup.BY_STATUS -> grouping.filter { it.second in map.keys }
LibraryGroup.BY_TRACK_STATUS, LibraryGroup.BY_STATUS -> grouping.filter { it.second in map.keys } else -> grouping
else -> grouping }.map { (_, id, name) ->
} Category.create(name).also { it.id = id }
) }
.map {
val category = Category.create(it.third)
category.id = it.second
category
}
return map to categories return map to categories
} }