From 1cb6c92edf34f2fe9132b0823011c063e7679d8e Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Fri, 16 Aug 2024 17:28:41 +0200 Subject: [PATCH] Fix crash when logging with an url without scheme and improve error and info messages in AccountCredentialsScreen --- .../app/account/credentials/AccountCredentialsScreen.kt | 5 ++++- .../account/credentials/AccountCredentialsScreenModel.kt | 8 +++++++- app/src/main/java/com/readrops/app/util/ErrorMessage.kt | 2 ++ app/src/main/res/values-fr/strings.xml | 3 ++- app/src/main/res/values/strings.xml | 3 ++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreen.kt b/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreen.kt index 90469f97..a7ebef3a 100644 --- a/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreen.kt +++ b/app/src/main/java/com/readrops/app/account/credentials/AccountCredentialsScreen.kt @@ -156,7 +156,10 @@ class AccountCredentialsScreen( Text(text = state.urlError!!.errorText()) } account.accountType == AccountType.FEVER -> { - Text(text = stringResource(R.string.provide_full_api)) + Text(text = stringResource(R.string.provide_full_url)) + } + else -> { + Text(text = stringResource(R.string.provide_root_url)) } } }, 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 60ab3758..1c79cb6f 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 @@ -56,8 +56,14 @@ 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 newAccount = account.copy( - url = url, + url = normalizedUrl, accountName = name, login = login, password = password, diff --git a/app/src/main/java/com/readrops/app/util/ErrorMessage.kt b/app/src/main/java/com/readrops/app/util/ErrorMessage.kt index 574c1674..d48c5733 100644 --- a/app/src/main/java/com/readrops/app/util/ErrorMessage.kt +++ b/app/src/main/java/com/readrops/app/util/ErrorMessage.kt @@ -2,6 +2,7 @@ package com.readrops.app.util import android.content.Context import com.readrops.api.utils.exceptions.HttpException +import com.readrops.api.utils.exceptions.LoginFailedException import com.readrops.api.utils.exceptions.ParseException import com.readrops.api.utils.exceptions.UnknownFormatException import com.readrops.app.R @@ -16,6 +17,7 @@ object ErrorMessage { is NoSuchFileException -> context.resources.getString(R.string.unable_open_file) is IOException -> context.resources.getString(R.string.network_failure, exception.message.orEmpty()) is ParseException, is UnknownFormatException -> context.resources.getString(R.string.processing_feed_error) + is LoginFailedException -> context.getString(R.string.login_failed) else -> "${exception.javaClass.simpleName}: ${exception.message}" } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 296a9894..99fcf567 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -218,5 +218,6 @@ "Si vous considérez que mon travail vous est utile et si vous souhaitez me soutenir, vous pouvez me faire une donation. " Ajouter un flux Fichier téléchargé ! - Merci de fournir l\'URL entière de l\'API + Merci de fournir l\'URL entière de l\'API + Merci de fournir l\'URL racine du service \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc96054b..12f19be4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -231,5 +231,6 @@ I you find my work useful and you would like to support me, you can consider making me a donation. Add feed Downloaded file! - Please provide the full API URL + Please provide the full API URL + Please provide the service root URL \ No newline at end of file