From 568c4d8c8e67f681002a1f9bb1e9500ad2cd592c Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 2 Jul 2021 22:48:16 -0400 Subject: [PATCH] Use current locale when sorting library "alphabetically" (closes #5281) This _should_ handle things like Chinese that aren't actually alphabetical. --- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 10 +++++++++- .../eu/kanade/tachiyomi/util/system/LocaleHelper.kt | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 88ff44dd99..e7eaeda6f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -29,8 +29,10 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.text.Collator import java.util.Collections import java.util.Comparator +import java.util.Locale /** * Class containing library information. @@ -256,11 +258,17 @@ class LibraryPresenter( (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 sortingMode = sortingModes[i1.manga.category]!! val sortAscending = sortAscending[i1.manga.category]!! == SortDirectionSetting.ASCENDING 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 -> { // Get index of manga, set equal to list if size unknown. val manga1LastRead = lastReadManga[i1.manga.id!!] ?: lastReadManga.size diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt index f488234ef9..ae0ad923d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt @@ -125,7 +125,7 @@ object LocaleHelper { val resources = app.resources resources.updateConfiguration(newConfig, resources.displayMetrics) - Locale.setDefault(currentLocale) + Locale.setDefault(currentLocale!!) } /**