mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 10:48:47 +03:00
Modified the isIconLoadingDisabled setting to be a flow (#626)
This commit is contained in:
parent
cd4db46e13
commit
f0e2548f65
5 changed files with 53 additions and 8 deletions
|
@ -9,15 +9,20 @@ import kotlinx.coroutines.flow.Flow
|
|||
*/
|
||||
interface SettingsDiskSource {
|
||||
|
||||
/**
|
||||
* The currently persisted app language (or `null` if not set).
|
||||
*/
|
||||
var appLanguage: AppLanguage?
|
||||
|
||||
/**
|
||||
* The currently persisted setting for getting login item icons (or `null` if not set).
|
||||
*/
|
||||
var isIconLoadingDisabled: Boolean?
|
||||
|
||||
/**
|
||||
* The currently persisted app language (or `null` if not set).
|
||||
* Emits updates that track [isIconLoadingDisabled].
|
||||
*/
|
||||
var appLanguage: AppLanguage?
|
||||
val isIconLoadingDisabledFlow: Flow<Boolean?>
|
||||
|
||||
/**
|
||||
* Clears all the settings data for the given user.
|
||||
|
|
|
@ -32,6 +32,9 @@ class SettingsDiskSourceImpl(
|
|||
private val mutablePullToRefreshEnabledFlowMap =
|
||||
mutableMapOf<String, MutableSharedFlow<Boolean?>>()
|
||||
|
||||
private val mutableIsIconLoadingDisabledFlow =
|
||||
bufferedMutableSharedFlow<Boolean?>()
|
||||
|
||||
override var appLanguage: AppLanguage?
|
||||
get() = getString(key = APP_LANGUAGE_KEY)
|
||||
?.let { storedValue ->
|
||||
|
@ -47,12 +50,14 @@ class SettingsDiskSourceImpl(
|
|||
override var isIconLoadingDisabled: Boolean?
|
||||
get() = getBoolean(key = DISABLE_ICON_LOADING_KEY)
|
||||
set(value) {
|
||||
putBoolean(
|
||||
key = DISABLE_ICON_LOADING_KEY,
|
||||
value = value,
|
||||
)
|
||||
putBoolean(key = DISABLE_ICON_LOADING_KEY, value = value)
|
||||
mutableIsIconLoadingDisabledFlow.tryEmit(value)
|
||||
}
|
||||
|
||||
override val isIconLoadingDisabledFlow: Flow<Boolean?>
|
||||
get() = mutableIsIconLoadingDisabledFlow
|
||||
.onSubscription { emit(getBoolean(DISABLE_ICON_LOADING_KEY)) }
|
||||
|
||||
override fun clearData(userId: String) {
|
||||
storeVaultTimeoutInMinutes(userId = userId, vaultTimeoutInMinutes = null)
|
||||
storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null)
|
||||
|
|
|
@ -3,11 +3,13 @@ package com.x8bit.bitwarden.data.platform.repository
|
|||
import com.x8bit.bitwarden.data.platform.repository.model.VaultTimeout
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.VaultTimeoutAction
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppLanguage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* Provides an API for observing and modifying settings state.
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
interface SettingsRepository {
|
||||
/**
|
||||
* The [AppLanguage] for the current user.
|
||||
|
@ -15,10 +17,15 @@ interface SettingsRepository {
|
|||
var appLanguage: AppLanguage
|
||||
|
||||
/**
|
||||
* Is icon loading for login items disabled.
|
||||
* The current setting for getting login item icons.
|
||||
*/
|
||||
var isIconLoadingDisabled: Boolean
|
||||
|
||||
/**
|
||||
* Emits updates that track the [isIconLoadingDisabled] value.
|
||||
*/
|
||||
val isIconLoadingDisabledFlow: Flow<Boolean>
|
||||
|
||||
/**
|
||||
* The [VaultTimeout] for the current user.
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.stateIn
|
|||
/**
|
||||
* Primary implementation of [SettingsRepository].
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class SettingsRepositoryImpl(
|
||||
private val authDiskSource: AuthDiskSource,
|
||||
private val settingsDiskSource: SettingsDiskSource,
|
||||
|
@ -37,6 +38,18 @@ class SettingsRepositoryImpl(
|
|||
settingsDiskSource.isIconLoadingDisabled = value
|
||||
}
|
||||
|
||||
override val isIconLoadingDisabledFlow: StateFlow<Boolean>
|
||||
get() = settingsDiskSource
|
||||
.isIconLoadingDisabledFlow
|
||||
.map { it ?: false }
|
||||
.stateIn(
|
||||
scope = unconfinedScope,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = settingsDiskSource
|
||||
.isIconLoadingDisabled
|
||||
?: false,
|
||||
)
|
||||
|
||||
override var vaultTimeout: VaultTimeout
|
||||
get() = activeUserId
|
||||
?.let {
|
||||
|
|
|
@ -22,14 +22,29 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
|||
private val mutablePullToRefreshEnabledFlowMap =
|
||||
mutableMapOf<String, MutableSharedFlow<Boolean?>>()
|
||||
|
||||
private val mutableIsIconLoadingDisabled =
|
||||
bufferedMutableSharedFlow<Boolean?>()
|
||||
|
||||
private val storedVaultTimeoutActions = mutableMapOf<String, VaultTimeoutAction?>()
|
||||
private val storedVaultTimeoutInMinutes = mutableMapOf<String, Int?>()
|
||||
|
||||
private val storedPullToRefreshEnabled = mutableMapOf<String, Boolean?>()
|
||||
|
||||
private var storedIsIconLoadingDisabled: Boolean? = null
|
||||
|
||||
override var appLanguage: AppLanguage? = null
|
||||
|
||||
override var isIconLoadingDisabled: Boolean? = null
|
||||
override var isIconLoadingDisabled: Boolean?
|
||||
get() = storedIsIconLoadingDisabled
|
||||
set(value) {
|
||||
storedIsIconLoadingDisabled = value
|
||||
mutableIsIconLoadingDisabled.tryEmit(value)
|
||||
}
|
||||
|
||||
override val isIconLoadingDisabledFlow: Flow<Boolean?>
|
||||
get() = mutableIsIconLoadingDisabled.onSubscription {
|
||||
emit(isIconLoadingDisabled)
|
||||
}
|
||||
|
||||
override fun clearData(userId: String) {
|
||||
storedVaultTimeoutActions.remove(userId)
|
||||
|
|
Loading…
Add table
Reference in a new issue