From e71c84a7857bb0ad637175ba938d08fcb86053b1 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 5 May 2021 16:56:56 +0530 Subject: ui: replace deprecated string operations Signed-off-by: Harsh Shandilya --- ui/src/main/java/com/wireguard/android/model/TunnelComparator.kt | 4 +--- .../java/com/wireguard/android/preference/VersionPreference.kt | 5 ++--- ui/src/main/java/com/wireguard/android/util/TunnelImporter.kt | 7 +++---- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'ui/src/main/java/com/wireguard') diff --git a/ui/src/main/java/com/wireguard/android/model/TunnelComparator.kt b/ui/src/main/java/com/wireguard/android/model/TunnelComparator.kt index 9fb96cab..9e72f4ee 100644 --- a/ui/src/main/java/com/wireguard/android/model/TunnelComparator.kt +++ b/ui/src/main/java/com/wireguard/android/model/TunnelComparator.kt @@ -5,8 +5,6 @@ package com.wireguard.android.model -import java.util.Locale - object TunnelComparator : Comparator { private class NaturalSortString(originalString: String) { class NaturalSortToken(val maybeString: String?, val maybeNumber: Int?) : Comparable { @@ -29,7 +27,7 @@ object TunnelComparator : Comparator { val tokens: MutableList = ArrayList() init { - for (s in NATURAL_SORT_DIGIT_FINDER.findAll(originalString.split(WHITESPACE_FINDER).joinToString(" ").toLowerCase(Locale.ENGLISH))) { + for (s in NATURAL_SORT_DIGIT_FINDER.findAll(originalString.split(WHITESPACE_FINDER).joinToString(" ").lowercase())) { try { val n = s.value.toInt() tokens.add(NaturalSortToken(null, n)) diff --git a/ui/src/main/java/com/wireguard/android/preference/VersionPreference.kt b/ui/src/main/java/com/wireguard/android/preference/VersionPreference.kt index 1ae4e9e6..a0c9e027 100644 --- a/ui/src/main/java/com/wireguard/android/preference/VersionPreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/VersionPreference.kt @@ -20,7 +20,6 @@ import com.wireguard.android.util.lifecycleScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import java.util.Locale class VersionPreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) { private var versionSummary: String? = null @@ -49,12 +48,12 @@ class VersionPreference(context: Context, attrs: AttributeSet?) : Preference(con init { lifecycleScope.launch { val backend = Application.getBackend() - versionSummary = getContext().getString(R.string.version_summary_checking, getBackendPrettyName(context, backend).toLowerCase(Locale.ENGLISH)) + versionSummary = getContext().getString(R.string.version_summary_checking, getBackendPrettyName(context, backend).lowercase()) notifyChanged() versionSummary = try { getContext().getString(R.string.version_summary, getBackendPrettyName(context, backend), withContext(Dispatchers.IO) { backend.version }) } catch (_: Throwable) { - getContext().getString(R.string.version_summary_unknown, getBackendPrettyName(context, backend).toLowerCase(Locale.ENGLISH)) + getContext().getString(R.string.version_summary_unknown, getBackendPrettyName(context, backend).lowercase()) } notifyChanged() } diff --git a/ui/src/main/java/com/wireguard/android/util/TunnelImporter.kt b/ui/src/main/java/com/wireguard/android/util/TunnelImporter.kt index a197bd7b..2af31993 100644 --- a/ui/src/main/java/com/wireguard/android/util/TunnelImporter.kt +++ b/ui/src/main/java/com/wireguard/android/util/TunnelImporter.kt @@ -25,7 +25,6 @@ import java.io.ByteArrayInputStream import java.io.InputStreamReader import java.nio.charset.StandardCharsets import java.util.ArrayList -import java.util.Locale import java.util.zip.ZipEntry import java.util.zip.ZipInputStream @@ -50,8 +49,8 @@ object TunnelImporter { require(idx < name.length - 1) { context.getString(R.string.illegal_filename_error, name) } name = name.substring(idx + 1) } - val isZip = name.toLowerCase(Locale.ROOT).endsWith(".zip") - if (name.toLowerCase(Locale.ROOT).endsWith(".conf")) { + val isZip = name.lowercase().endsWith(".zip") + if (name.lowercase().endsWith(".conf")) { name = name.substring(0, name.length - ".conf".length) } else { require(isZip) { context.getString(R.string.bad_extension_error) } @@ -71,7 +70,7 @@ object TunnelImporter { } name = name.substring(name.lastIndexOf('/') + 1) } - if (name.toLowerCase(Locale.ROOT).endsWith(".conf")) { + if (name.lowercase().endsWith(".conf")) { name = name.substring(0, name.length - ".conf".length) } else { continue -- cgit v1.2.3