diff --git a/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreenModel.kt b/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreenModel.kt index 1c79cb6f..ee7200f4 100644 --- a/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreenModel.kt +++ b/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreenModel.kt @@ -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, diff --git a/app/src/main/java/com/readrops/app/util/Utils.kt b/app/src/main/java/com/readrops/app/util/Utils.kt index 0f5b9179..e667344c 100644 --- a/app/src/main/java/com/readrops/app/util/Utils.kt +++ b/app/src/main/java/com/readrops/app/util/Utils.kt @@ -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("/") + } + } + } } \ No newline at end of file