New alphabetical chapter sort (#10073)

* added alphabetical chapter sorting

* Deleted sort_by_alphabet and re-utilized action_sort_alpha

* Accidentally deleted wrong string. Now solved

* Accidentally deleted wrong string. Now solved

Deleted sort_by_source instead of sort_by_alphabet in strings.xml.
Now reverted.

* Alphabetical sorting now uses Collator

* Clean up repeated Collator instances

---------

Co-authored-by: arkon <eugcheung94@gmail.com>
This commit is contained in:
Ota
2023-11-05 04:47:32 +09:00
committed by GitHub
parent 5d91b77c93
commit f30ab56fd0
6 changed files with 26 additions and 14 deletions

View File

@@ -41,6 +41,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import tachiyomi.core.preference.CheckboxState
import tachiyomi.core.preference.TriState
import tachiyomi.core.util.lang.compareToWithCollator
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable
import tachiyomi.core.util.lang.withIOContext
@@ -65,9 +66,7 @@ import tachiyomi.domain.track.model.Track
import tachiyomi.source.local.isLocal
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.Collator
import java.util.Collections
import java.util.Locale
/**
* Typealias for the library manga, using the category as keys, and list of manga as values.
@@ -243,12 +242,8 @@ class LibraryScreenModel(
// Map<MangaId, List<Track>>
trackMap: Map<Long, List<Track>>,
): LibraryMap {
val locale = Locale.getDefault()
val collator = Collator.getInstance(locale).apply {
strength = Collator.PRIMARY
}
val sortAlphabetically: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
collator.compare(i1.libraryManga.manga.title.lowercase(locale), i2.libraryManga.manga.title.lowercase(locale))
i1.libraryManga.manga.title.lowercase().compareToWithCollator(i2.libraryManga.manga.title.lowercase())
}
val defaultTrackerScoreSortValue = -1.0