From 1a414ae3bc8116d1c3dc0d8541f469549bc1ab46 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Dec 2020 17:38:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/utils/StringExtensions.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index a75811931..4263fc896 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -2,15 +2,15 @@ package io.legado.app.utils +import android.icu.text.Collator +import android.icu.util.ULocale import android.net.Uri import java.io.File -import java.text.Collator import java.util.* val removeHtmlRegex = "]*>".toRegex() val imgRegex = "]*>".toRegex() val notImgHtmlRegex = "]*>".toRegex() -val cnCollator: Collator = Collator.getInstance(Locale.CHINA) fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() @@ -71,7 +71,11 @@ fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array = run { } fun String.cnCompare(other: String): Int { - return cnCollator.compare(this, other) + return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + Collator.getInstance(ULocale.SIMPLIFIED_CHINESE).compare(this, other) + } else { + java.text.Collator.getInstance(Locale.CHINA).compare(this, other) + } } /**