Fix crash when adding a Fever account (#200)

This commit is contained in:
Shinokuni 2024-09-20 12:36:24 +02:00
parent 6a28aa2578
commit bf3c654a25
2 changed files with 16 additions and 5 deletions

View File

@ -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,

View File

@ -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("/")
}
}
}
}