Improve error management on login screens

This commit is contained in:
Benoit Marty 2022-11-24 17:59:13 +01:00
parent b3930d38f5
commit 4722ed58b6
7 changed files with 88 additions and 9 deletions

View file

@ -0,0 +1,31 @@
package io.element.android.x.core.uri
import java.net.URL
fun String.isValidUrl(): Boolean {
return try {
URL(this)
true
} catch (t: Throwable) {
false
}
}
/**
* Ensure string starts with "http". If it is not the case, "https://" is added, only if the String is not empty
*/
fun String.ensureProtocol(): String {
return when {
isEmpty() -> this
!startsWith("http") -> "https://$this"
else -> this
}
}
fun String.ensureTrailingSlash(): String {
return when {
isEmpty() -> this
!endsWith("/") -> "$this/"
else -> this
}
}