|
|
|
@ -1,11 +1,14 @@
|
|
|
|
package org.koitharu.kotatsu.settings
|
|
|
|
package org.koitharu.kotatsu.settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import okhttp3.HttpUrl
|
|
|
|
import okhttp3.internal.toCanonicalHost
|
|
|
|
import okhttp3.internal.toCanonicalHost
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.utils.EditTextValidator
|
|
|
|
import org.koitharu.kotatsu.utils.EditTextValidator
|
|
|
|
|
|
|
|
|
|
|
|
class DomainValidator : EditTextValidator() {
|
|
|
|
class DomainValidator : EditTextValidator() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val urlBuilder = HttpUrl.Builder()
|
|
|
|
|
|
|
|
|
|
|
|
override fun validate(text: String): ValidationResult {
|
|
|
|
override fun validate(text: String): ValidationResult {
|
|
|
|
val trimmed = text.trim()
|
|
|
|
val trimmed = text.trim()
|
|
|
|
if (trimmed.isEmpty()) {
|
|
|
|
if (trimmed.isEmpty()) {
|
|
|
|
@ -18,13 +21,7 @@ class DomainValidator : EditTextValidator() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun checkCharacters(value: String): Boolean {
|
|
|
|
private fun checkCharacters(value: String): Boolean = runCatching {
|
|
|
|
for (i in value.indices) {
|
|
|
|
urlBuilder.host(value)
|
|
|
|
val c = value[i]
|
|
|
|
}.isSuccess
|
|
|
|
if (c !in '\u0020'..'\u007e') {
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|