Use current locale when sorting library "alphabetically" (closes #5281)

This _should_ handle things like Chinese that aren't actually alphabetical.

(cherry picked from commit 568c4d8c8e67f681002a1f9bb1e9500ad2cd592c)
This commit is contained in:
arkon 2021-07-02 22:48:16 -04:00 committed by Jobobby04
parent e480001585
commit dc6906250d
2 changed files with 10 additions and 2 deletions

View File

@ -40,8 +40,10 @@ import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.text.Collator
import java.util.Collections import java.util.Collections
import java.util.Comparator import java.util.Comparator
import java.util.Locale
/** /**
* Class containing library information. * Class containing library information.
@ -362,6 +364,10 @@ class LibraryPresenter(
(category.id ?: 0) to SortDirectionSetting.get(preferences, category) (category.id ?: 0) to SortDirectionSetting.get(preferences, category)
} }
val locale = Locale.getDefault()
val collator = Collator.getInstance(locale).apply {
strength = Collator.PRIMARY
}
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 -> val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
val sortingMode = if (groupType == LibraryGroup.BY_DEFAULT) { val sortingMode = if (groupType == LibraryGroup.BY_DEFAULT) {
sortingModes[i1.manga.category] ?: defaultSortingMode sortingModes[i1.manga.category] ?: defaultSortingMode
@ -375,7 +381,9 @@ class LibraryPresenter(
} == SortDirectionSetting.ASCENDING } == SortDirectionSetting.ASCENDING
when (sortingMode) { when (sortingMode) {
SortModeSetting.ALPHABETICAL -> i1.manga.title.compareTo(i2.manga.title, true) SortModeSetting.ALPHABETICAL -> {
collator.compare(i1.manga.title.lowercase(locale), i2.manga.title.lowercase(locale))
}
SortModeSetting.LAST_READ -> { SortModeSetting.LAST_READ -> {
// Get index of manga, set equal to list if size unknown. // Get index of manga, set equal to list if size unknown.
val manga1LastRead = lastReadManga[i1.manga.id!!] ?: lastReadManga.size val manga1LastRead = lastReadManga[i1.manga.id!!] ?: lastReadManga.size

View File

@ -130,7 +130,7 @@ object LocaleHelper {
val resources = app.resources val resources = app.resources
resources.updateConfiguration(newConfig, resources.displayMetrics) resources.updateConfiguration(newConfig, resources.displayMetrics)
Locale.setDefault(currentLocale) Locale.setDefault(currentLocale!!)
} }
/** /**