Skip to content
Snippets Groups Projects
Unverified Commit 3be0e1a7 authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

Fix ANR during onboarding (DEV) (#1718)


* Don't launch a blocking operation in `init`.

* Switch to IO dispatcher.

* Return to previous name.

Co-authored-by: default avatarKolya Opahle <k.opahle@sap.com>
Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent 8b4b7897
No related branches found
No related tags found
No related merge requests found
......@@ -5,9 +5,12 @@ import androidx.lifecycle.asLiveData
import de.rki.coronawarnapp.appconfig.AppConfigProvider
import de.rki.coronawarnapp.storage.LocalData
import de.rki.coronawarnapp.ui.Country
import de.rki.coronawarnapp.util.coroutine.AppScope
import de.rki.coronawarnapp.util.coroutine.DefaultDispatcherProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.Locale
import javax.inject.Inject
......@@ -15,13 +18,11 @@ import javax.inject.Singleton
@Singleton
class InteroperabilityRepository @Inject constructor(
private val appConfigProvider: AppConfigProvider
private val appConfigProvider: AppConfigProvider,
@AppScope private val appScope: CoroutineScope,
private val dispatcherProvider: DefaultDispatcherProvider
) {
fun saveInteroperabilityUsed() {
LocalData.isInteroperabilityShownAtLeastOnce = true
}
private val countryListFlowInternal = MutableStateFlow(listOf<Country>())
val countryListFlow: Flow<List<Country>> = countryListFlowInternal
......@@ -32,12 +33,9 @@ class InteroperabilityRepository @Inject constructor(
getAllCountries()
}
/**
* Gets all countries from @see ApplicationConfigurationService.asyncRetrieveApplicationConfiguration
* Also changes every country code to lower case
*/
fun getAllCountries() {
runBlocking {
// TODO Make this reactive, the AppConfigProvider should refresh itself on network changes.
appScope.launch(context = dispatcherProvider.IO) {
try {
val countries = appConfigProvider.getAppConfig()
.supportedCountries
......@@ -60,4 +58,8 @@ class InteroperabilityRepository @Inject constructor(
fun clear() {
countryListFlowInternal.value = emptyList()
}
fun saveInteroperabilityUsed() {
LocalData.isInteroperabilityShownAtLeastOnce = true
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment