From 6e6bc704c92a54fd602bf5bc8b1fccf57966ea52 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 3 Jan 2024 22:21:00 +0100 Subject: [PATCH] fix: Checking selfoss instance. --- .../android/LoginActivity.kt | 25 +++++++++++-------- .../repository/RepositoryImpl.kt | 8 ++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index 686b21c..dd78a4b 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -140,20 +140,25 @@ class LoginActivity : AppCompatActivity(), DIAware { repository.refreshLoginInformation(url, login, password) CoroutineScope(Dispatchers.Main).launch { - repository.updateApiInformation() + try { + repository.updateApiInformation() + } catch (e: Exception) { + if (e.message?.startsWith("No transformation found") == true) { + Toast.makeText( + applicationContext, + R.string.application_selfoss_only, + Toast.LENGTH_LONG, + ).show() + preferenceError() + showProgress(false) + } + } val result = repository.login() if (result) { - val (errorFetching, displaySelfossOnly) = repository.shouldBeSelfossInstance() - if (!errorFetching && !displaySelfossOnly) { + val errorFetching = repository.checkIfFetchFails() + if (!errorFetching) { goToMain() } else { - if (displaySelfossOnly) { - Toast.makeText( - applicationContext, - R.string.application_selfoss_only, - Toast.LENGTH_LONG, - ).show() - } preferenceError() } } else { diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 8968313..c97d9e6 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -8,7 +8,6 @@ import bou.amine.apps.readerforselfossv2.rest.SelfossApi import bou.amine.apps.readerforselfossv2.service.AppSettingsService import bou.amine.apps.readerforselfossv2.utils.* import io.github.aakira.napier.Napier -import io.ktor.client.call.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow @@ -429,22 +428,19 @@ class Repository( return result } - suspend fun shouldBeSelfossInstance(): Pair { + suspend fun checkIfFetchFails(): Boolean { var fetchFailed = true - var showSelfossOnlyModal = false if (isNetworkAvailable()) { try { // Trying to fetch one item, and check someone is trying to use the app with // a random rss feed, that would throw a NoTransformationFoundException fetchFailed = !api.getItemsWithoutCatch().success - } catch (e: NoTransformationFoundException) { - showSelfossOnlyModal = true } catch (e: Throwable) { Napier.e(e.stackTraceToString(), tag = "RepositoryImpl.shouldBeSelfossInstance") } } - return Pair(fetchFailed, showSelfossOnlyModal) + return fetchFailed } suspend fun logout() {