diff --git a/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt b/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt index 208769f..7ce0658 100644 --- a/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt +++ b/domains/android/push/src/main/kotlin/app/dapk/st/push/PushTokenRegistrars.kt @@ -4,7 +4,6 @@ import android.content.Context import app.dapk.st.domain.push.PushTokenRegistrarPreferences import app.dapk.st.push.firebase.FirebasePushTokenRegistrar import app.dapk.st.push.unifiedpush.UnifiedPushRegistrar -import kotlinx.coroutines.runBlocking import org.unifiedpush.android.connector.UnifiedPush private val FIREBASE_OPTION = Registrar("Google - Firebase (FCM)") @@ -17,13 +16,13 @@ class PushTokenRegistrars( private val pushTokenStore: PushTokenRegistrarPreferences, ) : PushTokenRegistrar { - private var selection: Registrar = runBlocking { pushTokenStore.currentSelection()?.let { Registrar(it) } } ?: FIREBASE_OPTION + private var selection: Registrar? = null fun options(): List { return listOf(NONE, FIREBASE_OPTION) + UnifiedPush.getDistributors(context).map { Registrar(it) } } - fun currentSelection() = selection + suspend fun currentSelection() = selection ?: (pushTokenStore.currentSelection()?.let { Registrar(it) } ?: FIREBASE_OPTION).also { selection = it } suspend fun makeSelection(option: Registrar) { selection = option diff --git a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt index 99d1250..fbb7547 100644 --- a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt +++ b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt @@ -8,7 +8,7 @@ internal class SettingsItemFactory( private val pushTokenRegistrars: PushTokenRegistrars, ) { - fun root() = listOf( + suspend fun root() = listOf( SettingItem.Header("General"), SettingItem.Text(SettingItem.Id.Encryption, "Encryption"), SettingItem.Text(SettingItem.Id.EventLog, "Event log"), diff --git a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsViewModel.kt b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsViewModel.kt index af6f273..6644542 100644 --- a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsViewModel.kt +++ b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsViewModel.kt @@ -101,10 +101,12 @@ internal class SettingsViewModel( fun fetchPushProviders() { updatePageState { copy(options = Lce.Loading()) } viewModelScope.launch { + val currentSelection = pushTokenRegistrars.currentSelection() + val options = pushTokenRegistrars.options() updatePageState { copy( - selection = pushTokenRegistrars.currentSelection(), - options = Lce.Content(pushTokenRegistrars.options()) + selection = currentSelection, + options = Lce.Content(options) ) } } diff --git a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt index d3368b5..2c4c5e9 100644 --- a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt +++ b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt @@ -10,7 +10,7 @@ class SettingsItemFactoryTest { private val buildMeta = BuildMeta(versionName = "a-version-name", versionCode = 100) - private val settingsItemFactory = SettingsItemFactory(buildMeta) + private val settingsItemFactory = SettingsItemFactory(buildMeta, ) @Test fun `when creating root items, then is expected`() {