From f39669e6153ff7781d5b405c2320b8f04613b14b Mon Sep 17 00:00:00 2001 From: Patrick Honkonen <1883101+SaintPatrck@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:48:54 -0400 Subject: [PATCH] Display correct icons when app overrides system theme. (#56) --- .../feature/itemlisting/ItemListingScreen.kt | 12 +- .../itemlisting/ItemListingViewModel.kt | 24 +++ .../res/drawable-night/ic_empty_vault.xml | 146 +++++++++--------- .../main/res/drawable/ic_empty_vault_dark.xml | 77 +++++++++ .../res/drawable/ic_empty_vault_light.xml | 77 +++++++++ 5 files changed, 262 insertions(+), 74 deletions(-) create mode 100644 app/src/main/res/drawable/ic_empty_vault_dark.xml create mode 100644 app/src/main/res/drawable/ic_empty_vault_light.xml diff --git a/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingScreen.kt b/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingScreen.kt index aec2ad06e..c4774f955 100644 --- a/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingScreen.kt +++ b/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingScreen.kt @@ -61,6 +61,7 @@ import com.bitwarden.authenticator.ui.platform.components.icon.BitwardenIcon import com.bitwarden.authenticator.ui.platform.components.model.IconData import com.bitwarden.authenticator.ui.platform.components.model.IconResource import com.bitwarden.authenticator.ui.platform.components.scaffold.BitwardenScaffold +import com.bitwarden.authenticator.ui.platform.feature.settings.appearance.model.AppTheme import com.bitwarden.authenticator.ui.platform.manager.intent.IntentManager import com.bitwarden.authenticator.ui.platform.manager.permissions.PermissionsManager import com.bitwarden.authenticator.ui.platform.theme.LocalIntentManager @@ -275,6 +276,7 @@ fun ItemListingScreen( ItemListingState.ViewState.Loading, -> { EmptyItemListingContent( + appTheme = state.appTheme, onAddCodeClick = remember(viewModel) { { launcher.launch(Manifest.permission.CAMERA) @@ -336,6 +338,7 @@ private fun ItemListingDialogs( @Composable fun EmptyItemListingContent( modifier: Modifier = Modifier, + appTheme: AppTheme, onAddCodeClick: () -> Unit = {}, ) { Column( @@ -347,7 +350,13 @@ fun EmptyItemListingContent( ) { Image( modifier = Modifier.fillMaxWidth(), - painter = painterResource(id = R.drawable.ic_empty_vault), + painter = painterResource( + id = when (appTheme) { + AppTheme.DARK -> R.drawable.ic_empty_vault_dark + AppTheme.LIGHT -> R.drawable.ic_empty_vault_light + AppTheme.DEFAULT -> R.drawable.ic_empty_vault + } + ), contentDescription = stringResource( id = R.string.empty_item_list, ), @@ -379,6 +388,7 @@ fun EmptyItemListingContent( @Preview(showBackground = true) fun EmptyListingContentPreview() { EmptyItemListingContent( + appTheme = AppTheme.DEFAULT, modifier = Modifier.padding(horizontal = 16.dp), ) } diff --git a/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingViewModel.kt b/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingViewModel.kt index 6738a737e..4d7f56ee4 100644 --- a/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingViewModel.kt +++ b/app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingViewModel.kt @@ -21,6 +21,7 @@ import com.bitwarden.authenticator.ui.platform.base.BaseViewModel import com.bitwarden.authenticator.ui.platform.base.util.Text import com.bitwarden.authenticator.ui.platform.base.util.asText import com.bitwarden.authenticator.ui.platform.base.util.concat +import com.bitwarden.authenticator.ui.platform.feature.settings.appearance.model.AppTheme import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map @@ -41,6 +42,7 @@ class ItemListingViewModel @Inject constructor( settingsRepository: SettingsRepository, ) : BaseViewModel( initialState = ItemListingState( + settingsRepository.appTheme, settingsRepository.authenticatorAlertThresholdSeconds, viewState = ItemListingState.ViewState.Loading, dialog = null @@ -55,6 +57,12 @@ class ItemListingViewModel @Inject constructor( .onEach(::sendAction) .launchIn(viewModelScope) + settingsRepository + .appThemeStateFlow + .map { ItemListingAction.Internal.AppThemeChangeReceive(it) } + .onEach(::sendAction) + .launchIn(viewModelScope) + authenticatorRepository .getAuthCodesFlow() .map { ItemListingAction.Internal.AuthCodesUpdated(it) } @@ -181,6 +189,16 @@ class ItemListingViewModel @Inject constructor( is ItemListingAction.Internal.DeleteItemReceive -> { handleDeleteItemReceive(internalAction.result) } + + is ItemListingAction.Internal.AppThemeChangeReceive -> { + handleAppThemeChangeReceive(internalAction.appTheme) + } + } + } + + private fun handleAppThemeChangeReceive(appTheme: AppTheme) { + mutableStateFlow.update { + it.copy(appTheme = appTheme) } } @@ -444,6 +462,7 @@ private const val ISSUER = "issuer" */ @Parcelize data class ItemListingState( + val appTheme: AppTheme, val alertThresholdSeconds: Int, val viewState: ViewState, val dialog: DialogState?, @@ -640,6 +659,11 @@ sealed class ItemListingAction { * Indicates a result for deleting an item has been received. */ data class DeleteItemReceive(val result: DeleteItemResult) : Internal() + + /** + * Indicates app theme change has been received. + */ + data class AppThemeChangeReceive(val appTheme: AppTheme) : Internal() } /** diff --git a/app/src/main/res/drawable-night/ic_empty_vault.xml b/app/src/main/res/drawable-night/ic_empty_vault.xml index e8b7a3095..784404200 100644 --- a/app/src/main/res/drawable-night/ic_empty_vault.xml +++ b/app/src/main/res/drawable-night/ic_empty_vault.xml @@ -1,77 +1,77 @@ - - - - - - - - - - - - - - - - - - + android:viewportHeight="161" + android:viewportWidth="180"> + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_empty_vault_dark.xml b/app/src/main/res/drawable/ic_empty_vault_dark.xml new file mode 100644 index 000000000..784404200 --- /dev/null +++ b/app/src/main/res/drawable/ic_empty_vault_dark.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_empty_vault_light.xml b/app/src/main/res/drawable/ic_empty_vault_light.xml new file mode 100644 index 000000000..b14c68cd7 --- /dev/null +++ b/app/src/main/res/drawable/ic_empty_vault_light.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + +