Improve error management on login screens
This commit is contained in:
parent
b3930d38f5
commit
4722ed58b6
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue