Rework repository initialization

This commit is contained in:
davidoskky 2022-10-21 22:42:32 +02:00
parent c25e8889a4
commit 53b1d1f8b2
2 changed files with 4 additions and 11 deletions

View File

@ -93,6 +93,9 @@ class LoginActivity : AppCompatActivity(), DIAware {
} }
private fun goToMain() { private fun goToMain() {
CoroutineScope(Dispatchers.Main).launch {
repository.updateApiVersion()
}
val intent = Intent(this, HomeActivity::class.java) val intent = Intent(this, HomeActivity::class.java)
startActivity(intent) startActivity(intent)
finish() finish()

View File

@ -41,14 +41,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
private var fetchedTags = false private var fetchedTags = false
init { init {
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
connectivityStatus.start() connectivityStatus.start()
if (appSettingsService.getBaseUrl() != "") {
runBlocking {
updateApiVersion()
reloadBadges()
}
}
} }
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> { suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
@ -384,9 +377,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
try { try {
val response = api.login() val response = api.login()
result = response.isSuccess == true result = response.isSuccess == true
if (result) {
updateApiVersion()
}
} catch (cause: Throwable) { } catch (cause: Throwable) {
Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.updateRemote") Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.updateRemote")
} }
@ -400,7 +390,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
api.refreshLoginInformation() api.refreshLoginInformation()
} }
private suspend fun updateApiVersion() { suspend fun updateApiVersion() {
val apiMajorVersion = appSettingsService.getApiVersion() val apiMajorVersion = appSettingsService.getApiVersion()
if (isNetworkAvailable()) { if (isNetworkAvailable()) {