mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Improve error management on login screens
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user