fix: Prevent potential "Comparison method violates its general contract!" crash

This commit is contained in:
Ahmad Ansori Palembani 2025-04-17 17:09:00 +07:00
parent 8be33e0f81
commit 271e440014
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 9 additions and 8 deletions

View file

@ -16,6 +16,7 @@ The format is simplified version of [Keep a Changelog](https://keepachangelog.co
### Changes
- Temporarily disable log file
- Categories' header now show filtered count when you search the library (If you have "Show number of items" enabled)
### Fixes
- Allow users to bypass onboarding's permission step if Shizuku is installed
@ -23,6 +24,7 @@ The format is simplified version of [Keep a Changelog](https://keepachangelog.co
- Fix not fully loaded entries can't be selected on Library page
- Fix certain Infinix devices being unable to use any "Open link in browser" actions, including tracker setup (@MajorTanya)
- Fix source filter bottom sheet unable to be fully scrolled to the bottom
- Prevent potential "Comparison method violates its general contract!" crash
### Translation
- Update translations from Weblate

View file

@ -660,6 +660,9 @@ class LibraryPresenter(
* @param itemList the map to sort.
*/
private fun LibraryMap.applySort(): LibraryMap {
// Making sure `allCategories` is stable for `.sort()`
val categoryOrderMap = allCategories.associate { it.id to it.order }
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
val category = i1.header.category
val compare = when {
@ -688,12 +691,8 @@ class LibraryPresenter(
LibrarySort.DateAdded -> i2.manga.manga.date_added.compareTo(i1.manga.manga.date_added)
LibrarySort.DragAndDrop -> {
if (category.isDynamic) {
val category1 =
allCategories.find { i1.manga.category == it.id }?.order
?: 0
val category2 =
allCategories.find { i2.manga.category == it.id }?.order
?: 0
val category1 = categoryOrderMap[i1.manga.category] ?: 0
val category2 = categoryOrderMap[i2.manga.category] ?: 0
category1.compareTo(category2)
} else {
sortAlphabetical(i1, i2)
@ -727,7 +726,7 @@ class LibraryPresenter(
}
return this.mapValues { (category, values) ->
// Making sure category has valid sort
// Making sure category has valid sort before doing the actual sorting
if (category.mangaOrder.isEmpty() && category.mangaSort == null) {
category.changeSortTo(preferences.librarySortingMode().get())
if (category.id == 0) {