Improve error management on login screens

This commit is contained in:
Benoit Marty
2022-11-24 17:59:13 +01:00
parent 3225719c65
commit b1ad191740
7 changed files with 88 additions and 9 deletions
@@ -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
}
}