mirror of https://github.com/readrops/Readrops.git
Fix crash when adding a Fever account (#200)
This commit is contained in:
parent
6a28aa2578
commit
bf3c654a25
|
@ -5,6 +5,7 @@ import android.util.Patterns
|
|||
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.readrops.app.repositories.BaseRepository
|
||||
import com.readrops.app.util.Utils
|
||||
import com.readrops.app.util.components.TextFieldError
|
||||
import com.readrops.db.Database
|
||||
import com.readrops.db.entities.account.Account
|
||||
|
@ -56,11 +57,7 @@ class AccountCredentialsScreenModel(
|
|||
mutableState.update { it.copy(isLoginOnGoing = true) }
|
||||
|
||||
with(state.value) {
|
||||
val normalizedUrl = if (!url.contains("https://") && !url.contains("http://")) {
|
||||
"https://$url"
|
||||
} else {
|
||||
url
|
||||
}
|
||||
val normalizedUrl = Utils.normalizeUrl(url)
|
||||
|
||||
val newAccount = account.copy(
|
||||
url = normalizedUrl,
|
||||
|
|
|
@ -22,4 +22,18 @@ object Utils {
|
|||
Color.alpha(color) / 255.0
|
||||
)
|
||||
}
|
||||
|
||||
fun normalizeUrl(url: String): String {
|
||||
return buildString {
|
||||
if (!url.contains("https://") && !url.contains("http://")) {
|
||||
append("https://$url")
|
||||
} else {
|
||||
append(url)
|
||||
}
|
||||
|
||||
if (!url.endsWith("/")) {
|
||||
append("/")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue