aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-08-24 21:33:29 +0530
committerGitHub <noreply@github.com>2021-08-24 16:03:29 +0000
commit8c56a1d7b84d898714d7ca7d167bd60df033ab57 (patch)
tree043be3fb9bb7e61b0133681ddb400e42173746c2 /app/src/main/java
parentd59d1770ea6624234d29410a43e299929d18f850 (diff)
Update AndroidX deps (#1491)
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/proxy/ProxySelectorActivity.kt15
1 files changed, 11 insertions, 4 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/proxy/ProxySelectorActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/proxy/ProxySelectorActivity.kt
index b69267cf..6fc63673 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/proxy/ProxySelectorActivity.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/proxy/ProxySelectorActivity.kt
@@ -6,6 +6,8 @@
package dev.msfjarvis.aps.ui.proxy
import android.content.SharedPreferences
+import android.net.InetAddresses
+import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
@@ -25,7 +27,6 @@ import dev.msfjarvis.aps.util.settings.GitSettings
import dev.msfjarvis.aps.util.settings.PreferenceKeys
import javax.inject.Inject
-private val IP_ADDRESS_REGEX = Patterns.IP_ADDRESS.toRegex()
private val WEB_ADDRESS_REGEX = Patterns.WEB_URL.toRegex()
@AndroidEntryPoint
@@ -34,9 +35,7 @@ class ProxySelectorActivity : AppCompatActivity() {
@Inject lateinit var gitSettings: GitSettings
@ProxyPreferences @Inject lateinit var proxyPrefs: SharedPreferences
@Inject lateinit var proxyUtils: ProxyUtils
-
private val binding by viewBinding(ActivityProxySelectorBinding::inflate)
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
@@ -51,7 +50,7 @@ class ProxySelectorActivity : AppCompatActivity() {
proxyHost.doOnTextChanged { text, _, _, _ ->
if (text != null) {
proxyHost.error =
- if (text.matches(IP_ADDRESS_REGEX) || text.matches(WEB_ADDRESS_REGEX)) {
+ if (isNumericAddress(text) || text.matches(WEB_ADDRESS_REGEX)) {
null
} else {
getString(R.string.invalid_proxy_url)
@@ -61,6 +60,14 @@ class ProxySelectorActivity : AppCompatActivity() {
}
}
+ private fun isNumericAddress(text: CharSequence): Boolean {
+ return if (Build.VERSION.SDK_INT >= 29) {
+ InetAddresses.isNumericAddress(text as String)
+ } else {
+ @Suppress("DEPRECATION") Patterns.IP_ADDRESS.matcher(text).matches()
+ }
+ }
+
private fun saveSettings() {
proxyPrefs.edit {
binding.proxyHost.text?.toString()?.takeIf { it.isNotEmpty() }.let {