Add persistence for isImageLoadingEnabled appearance setting (#612)

This commit is contained in:
Oleg Semenenko
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 561aabc528
commit 80084ff0fb
9 changed files with 92 additions and 7 deletions
@@ -8,6 +8,12 @@ import kotlinx.coroutines.flow.Flow
* Primary access point for general settings-related disk information.
*/
interface SettingsDiskSource {
/**
* 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).
*/
@@ -13,6 +13,7 @@ private const val APP_LANGUAGE_KEY = "$BASE_KEY:appLocale"
private const val PULL_TO_REFRESH_KEY = "$BASE_KEY:syncOnRefresh"
private const val VAULT_TIMEOUT_ACTION_KEY = "$BASE_KEY:vaultTimeoutAction"
private const val VAULT_TIME_IN_MINUTES_KEY = "$BASE_KEY:vaultTimeout"
private const val DISABLE_ICON_LOADING_KEY = "$BASE_KEY:disableFavicon"
/**
* Primary implementation of [SettingsDiskSource].
@@ -43,6 +44,15 @@ class SettingsDiskSourceImpl(
)
}
override var isIconLoadingDisabled: Boolean?
get() = getBoolean(key = DISABLE_ICON_LOADING_KEY)
set(value) {
putBoolean(
key = DISABLE_ICON_LOADING_KEY,
value = value,
)
}
override fun clearData(userId: String) {
storeVaultTimeoutInMinutes(userId = userId, vaultTimeoutInMinutes = null)
storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null)
@@ -14,6 +14,11 @@ interface SettingsRepository {
*/
var appLanguage: AppLanguage
/**
* Is icon loading for login items disabled.
*/
var isIconLoadingDisabled: Boolean
/**
* The [VaultTimeout] for the current user.
*/
@@ -31,6 +31,12 @@ class SettingsRepositoryImpl(
settingsDiskSource.appLanguage = value
}
override var isIconLoadingDisabled: Boolean
get() = settingsDiskSource.isIconLoadingDisabled ?: false
set(value) {
settingsDiskSource.isIconLoadingDisabled = value
}
override var vaultTimeout: VaultTimeout
get() = activeUserId
?.let {
@@ -28,7 +28,7 @@ class AppearanceViewModel @Inject constructor(
initialState = savedStateHandle[KEY_STATE]
?: AppearanceState(
language = settingsRepository.appLanguage,
showWebsiteIcons = false,
showWebsiteIcons = !settingsRepository.isIconLoadingDisabled,
theme = AppearanceState.Theme.DEFAULT,
),
) {
@@ -54,8 +54,12 @@ class AppearanceViewModel @Inject constructor(
}
private fun handleShowWebsiteIconsToggled(action: AppearanceAction.ShowWebsiteIconsToggle) {
// TODO: BIT-541 add website icon support
mutableStateFlow.update { it.copy(showWebsiteIcons = action.showWebsiteIcons) }
mutableStateFlow.update {
it.copy(showWebsiteIcons = action.showWebsiteIcons)
}
// Negate the boolean to properly update the settings repository
settingsRepository.isIconLoadingDisabled = !action.showWebsiteIcons
}
private fun handleThemeChanged(action: AppearanceAction.ThemeChange) {