From 330eb1f8ecb9a2561b29754251b11fb04e3acbaf Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Thu, 12 Aug 2021 12:21:39 -0400 Subject: [PATCH] Use new natural sort library to sort local manga page files Fixes #964 Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com> --- app/build.gradle.kts | 3 +++ .../java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2dbc423c9b..07b50be4c8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -209,6 +209,9 @@ dependencies { // Logging implementation("com.jakewharton.timber:timber:${Versions.TIMBER}") + // Sort + implementation("com.github.gpanther:java-nat-sort:natural-comparator-1.1") + // UI implementation("com.dmitrymalkovich.android:material-design-dimens:1.4") implementation("br.com.simplepass:loading-button-android:2.2.0") diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt index 2ea9ef383e..e3f79ffb50 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt @@ -15,6 +15,7 @@ import androidx.annotation.ColorInt import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor +import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator import kotlin.math.floor /** @@ -89,7 +90,8 @@ fun String.capitalizeWords(): String { * Case-insensitive natural comparator for strings. */ fun String.compareToCaseInsensitiveNaturalOrder(other: String): Int { - return String.CASE_INSENSITIVE_ORDER.then(naturalOrder()).compare(this, other) + val comparator = CaseInsensitiveSimpleNaturalComparator.getInstance() + return comparator.compare(this, other) } fun CharSequence.tintText(@ColorInt color: Int): Spanned {