ui: replace deprecated string operations
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
3474849b1d
commit
e71c84a785
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
package com.wireguard.android.model
|
package com.wireguard.android.model
|
||||||
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
object TunnelComparator : Comparator<String> {
|
object TunnelComparator : Comparator<String> {
|
||||||
private class NaturalSortString(originalString: String) {
|
private class NaturalSortString(originalString: String) {
|
||||||
class NaturalSortToken(val maybeString: String?, val maybeNumber: Int?) : Comparable<NaturalSortToken> {
|
class NaturalSortToken(val maybeString: String?, val maybeNumber: Int?) : Comparable<NaturalSortToken> {
|
||||||
@ -29,7 +27,7 @@ object TunnelComparator : Comparator<String> {
|
|||||||
val tokens: MutableList<NaturalSortToken> = ArrayList()
|
val tokens: MutableList<NaturalSortToken> = ArrayList()
|
||||||
|
|
||||||
init {
|
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 {
|
try {
|
||||||
val n = s.value.toInt()
|
val n = s.value.toInt()
|
||||||
tokens.add(NaturalSortToken(null, n))
|
tokens.add(NaturalSortToken(null, n))
|
||||||
|
@ -20,7 +20,6 @@ import com.wireguard.android.util.lifecycleScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
class VersionPreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
|
class VersionPreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
|
||||||
private var versionSummary: String? = null
|
private var versionSummary: String? = null
|
||||||
@ -49,12 +48,12 @@ class VersionPreference(context: Context, attrs: AttributeSet?) : Preference(con
|
|||||||
init {
|
init {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val backend = Application.getBackend()
|
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()
|
notifyChanged()
|
||||||
versionSummary = try {
|
versionSummary = try {
|
||||||
getContext().getString(R.string.version_summary, getBackendPrettyName(context, backend), withContext(Dispatchers.IO) { backend.version })
|
getContext().getString(R.string.version_summary, getBackendPrettyName(context, backend), withContext(Dispatchers.IO) { backend.version })
|
||||||
} catch (_: Throwable) {
|
} 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()
|
notifyChanged()
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import java.io.ByteArrayInputStream
|
|||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.Locale
|
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
@ -50,8 +49,8 @@ object TunnelImporter {
|
|||||||
require(idx < name.length - 1) { context.getString(R.string.illegal_filename_error, name) }
|
require(idx < name.length - 1) { context.getString(R.string.illegal_filename_error, name) }
|
||||||
name = name.substring(idx + 1)
|
name = name.substring(idx + 1)
|
||||||
}
|
}
|
||||||
val isZip = name.toLowerCase(Locale.ROOT).endsWith(".zip")
|
val isZip = name.lowercase().endsWith(".zip")
|
||||||
if (name.toLowerCase(Locale.ROOT).endsWith(".conf")) {
|
if (name.lowercase().endsWith(".conf")) {
|
||||||
name = name.substring(0, name.length - ".conf".length)
|
name = name.substring(0, name.length - ".conf".length)
|
||||||
} else {
|
} else {
|
||||||
require(isZip) { context.getString(R.string.bad_extension_error) }
|
require(isZip) { context.getString(R.string.bad_extension_error) }
|
||||||
@ -71,7 +70,7 @@ object TunnelImporter {
|
|||||||
}
|
}
|
||||||
name = name.substring(name.lastIndexOf('/') + 1)
|
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)
|
name = name.substring(0, name.length - ".conf".length)
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user