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() {
CoroutineScope(Dispatchers.Main).launch {
repository.updateApiVersion()
}
val intent = Intent(this, HomeActivity::class.java)
startActivity(intent)
finish()

View File

@ -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<SelfossModel.Item> {
@ -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()) {