mirror of
https://github.com/bitwarden/android.git
synced 2026-06-09 08:09:16 -05:00
Lazily determine autofill setting (#753)
This commit is contained in:
committed by
Álison Fernandes
parent
0edec8419e
commit
ee8b9563a3
@@ -87,6 +87,9 @@ interface SettingsRepository {
|
||||
|
||||
/**
|
||||
* Emits updates whenever there is a change in the app's status for supporting autofill.
|
||||
*
|
||||
* Note that the correct value is only populated upon subscription so calling [StateFlow.value]
|
||||
* may result in an out-of-date value.
|
||||
*/
|
||||
val isAutofillEnabledStateFlow: StateFlow<Boolean>
|
||||
|
||||
|
||||
@@ -12,10 +12,13 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppLanguage
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppTheme
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@@ -326,9 +329,15 @@ class SettingsRepositoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun observeAutofillEnabledChanges() {
|
||||
appForegroundManager
|
||||
.appForegroundStateFlow
|
||||
mutableIsAutofillEnabledStateFlow
|
||||
// Only observe when subscribed to.
|
||||
.subscriptionCount.map { it > 0 }
|
||||
.filter { hasSubscribers -> hasSubscribers }
|
||||
.flatMapLatest {
|
||||
appForegroundManager.appForegroundStateFlow
|
||||
}
|
||||
.onEach {
|
||||
mutableIsAutofillEnabledStateFlow.value = isAutofillEnabledAndSupported
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user