소스 검색

fix 服务器支持IP填写

RobinTan1024 4 년 전
부모
커밋
83b401ebfd

+ 1 - 1
app/build.gradle

@@ -14,7 +14,7 @@ android {
         minSdkVersion 22
         targetSdkVersion 26
         versionCode 1
-        versionName "1.0.0"
+        versionName "1.0.2"
         archivesBaseName = versionName + "." + getTime()
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

+ 2 - 0
app/src/main/java/com/doverfuelingsolutions/issp/utils/ValidateUtil.kt

@@ -7,10 +7,12 @@ class ValidateUtil {
         private val regexIP: Regex by lazyOf(Regex("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\$"))
         private val regexPositiveInt: Regex by lazyOf(Regex("^[1-9]\\d*$"))
         private val regexUrl: Regex by lazyOf(Regex("^(https?|ftp|file)://([\\da-z.-]+)\\.([a-z.]{2,6})([/\\w .-]*)*/?\$"))
+        private val regexIPHost: Regex by lazyOf(Regex("^(https?|ftp|file)://(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\$"))
 
         fun isIP(ip: String): Boolean = regexIP.matches(ip)
         fun isPositiveInt(num: String): Boolean = regexPositiveInt.matches(num)
         fun isUrl(url: String): Boolean = regexUrl.matches(url)
+        fun isIPHost(url: String): Boolean = regexIPHost.matches(url)
         fun isPort(port: String): Boolean = isPositiveInt(port) && port.toInt() < 65535
     }
 }

+ 1 - 1
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentPreference.kt

@@ -48,7 +48,7 @@ class FragmentPreference : PreferenceFragmentCompat(), EditTextPreference.OnBind
             SPKeys.FUEL_PORT -> ValidateUtil.isPort(value)
             SPKeys.FUEL_IP,
             SPKeys.MIDDLE_IP -> ValidateUtil.isIP(value)
-            SPKeys.SERVER_DOMAIN -> ValidateUtil.isUrl(value)
+            SPKeys.SERVER_DOMAIN -> ValidateUtil.isUrl(value) || ValidateUtil.isIPHost(value)
             else -> false
         }
         if (!result) {