From 53b1d1f8b241c1acfc868375536ebfbc204d95e1 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 21 Oct 2022 22:42:32 +0200 Subject: [PATCH] Rework repository initialization --- .../apps/readerforselfossv2/android/LoginActivity.kt | 3 +++ .../readerforselfossv2/repository/RepositoryImpl.kt | 12 +----------- 2 files changed, 4 insertions(+), 11 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 00e1e7e..a5ad48e 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 @@ -93,6 +93,9 @@ class LoginActivity : AppCompatActivity(), DIAware { } private fun goToMain() { + CoroutineScope(Dispatchers.Main).launch { + repository.updateApiVersion() + } val intent = Intent(this, HomeActivity::class.java) startActivity(intent) finish() 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 8ed6387..2b1a8aa 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 @@ -41,14 +41,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap private var fetchedTags = false init { - // TODO: Dispatchers.IO not available in KMM, an alternative solution should be found connectivityStatus.start() - if (appSettingsService.getBaseUrl() != "") { - runBlocking { - updateApiVersion() - reloadBadges() - } - } } suspend fun getNewerItems(): ArrayList { @@ -384,9 +377,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap try { val response = api.login() result = response.isSuccess == true - if (result) { - updateApiVersion() - } } catch (cause: Throwable) { Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.updateRemote") } @@ -400,7 +390,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap api.refreshLoginInformation() } - private suspend fun updateApiVersion() { + suspend fun updateApiVersion() { val apiMajorVersion = appSettingsService.getApiVersion() if (isNetworkAvailable()) {