Skip to content

Commit

Permalink
Display correct icons when app overrides system theme. (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored Apr 25, 2024
1 parent 1f0881f commit f39669e
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -275,6 +276,7 @@ fun ItemListingScreen(
ItemListingState.ViewState.Loading,
-> {
EmptyItemListingContent(
appTheme = state.appTheme,
onAddCodeClick = remember(viewModel) {
{
launcher.launch(Manifest.permission.CAMERA)
Expand Down Expand Up @@ -336,6 +338,7 @@ private fun ItemListingDialogs(
@Composable
fun EmptyItemListingContent(
modifier: Modifier = Modifier,
appTheme: AppTheme,
onAddCodeClick: () -> Unit = {},
) {
Column(
Expand All @@ -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,
),
Expand Down Expand Up @@ -379,6 +388,7 @@ fun EmptyItemListingContent(
@Preview(showBackground = true)
fun EmptyListingContentPreview() {
EmptyItemListingContent(
appTheme = AppTheme.DEFAULT,
modifier = Modifier.padding(horizontal = 16.dp),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,7 @@ class ItemListingViewModel @Inject constructor(
settingsRepository: SettingsRepository,
) : BaseViewModel<ItemListingState, ItemListingEvent, ItemListingAction>(
initialState = ItemListingState(
settingsRepository.appTheme,
settingsRepository.authenticatorAlertThresholdSeconds,
viewState = ItemListingState.ViewState.Loading,
dialog = null
Expand All @@ -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) }
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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?,
Expand Down Expand Up @@ -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()
}

/**
Expand Down
146 changes: 73 additions & 73 deletions app/src/main/res/drawable-night/ic_empty_vault.xml
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="180dp"
android:height="161dp"
android:viewportWidth="180"
android:viewportHeight="161">
<path
android:pathData="M134,147H161V154.57C161,156.78 159.21,158.57 157,158.57H138C135.79,158.57 134,156.78 134,154.57V147Z"
android:strokeWidth="2"
android:fillColor="#2C2C2E"
android:strokeColor="#8E8E93"/>
<path
android:pathData="M20,147H47V154.57C47,156.78 45.21,158.57 43,158.57H24C21.79,158.57 20,156.78 20,154.57V147Z"
android:strokeWidth="2"
android:fillColor="#2C2C2E"
android:strokeColor="#8E8E93"/>
<path
android:pathData="M172.38,2H7.62C4.51,2 2,4.52 2,7.62V140.56C2,143.67 4.51,146.18 7.62,146.18H172.38C175.49,146.18 178,143.67 178,140.56V7.62C178,4.52 175.49,2 172.38,2Z"
android:strokeWidth="2"
android:fillColor="#1C1C1E"
android:strokeColor="#8E8E93"/>
<path
android:pathData="M154.44,18H26.56C23.49,18 21,20.49 21,23.56V123.64C21,126.71 23.49,129.2 26.56,129.2H154.44C157.51,129.2 160,126.71 160,123.64V23.56C160,20.49 157.51,18 154.44,18Z"
android:strokeWidth="2"
android:fillColor="#2C2C2E"
android:strokeColor="#8E8E93"/>
<path
android:pathData="M154.76,129.8L49.89,135.92C46.69,136.11 44,133.57 44,130.38V17.55C44,14.36 46.69,11.82 49.89,12.01L154.76,18.13C157.7,18.3 160,20.73 160,23.67V124.26C160,127.2 157.7,129.63 154.76,129.8Z"
android:strokeWidth="2"
android:fillColor="#1C1C1E"
android:strokeColor="#8E8E93"/>
<path
android:strokeWidth="1"
android:pathData="M164.85,40.87C164.85,38.55 162.98,36.68 160.66,36.68C158.34,36.68 156.46,38.55 156.46,40.87V57.63C156.46,59.94 158.34,61.82 160.66,61.82C162.98,61.82 164.85,59.94 164.85,57.63V40.87Z"
android:fillColor="#1C1C1E"
android:strokeColor="#8E8E93"/>
<path
android:strokeWidth="1"
android:pathData="M164.85,82.77C164.85,80.45 162.98,78.58 160.66,78.58C158.34,78.58 156.46,80.45 156.46,82.77V99.53C156.46,101.84 158.34,103.71 160.66,103.71C162.98,103.71 164.85,101.84 164.85,99.53V82.77Z"
android:fillColor="#1C1C1E"
android:strokeColor="#8E8E93"/>
<path
android:pathData="M62,45C63.66,45 65,46.26 65,47.81V86.44C65,87.99 63.66,89.25 62,89.25"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#8E8E93"
android:strokeLineCap="round"/>
<path
android:pathData="M109,86.29C103.24,86.29 98.56,80.74 98.56,73.92C98.56,67.09 103.24,61.55 109,61.55C114.76,61.55 119.42,67.1 119.42,73.92C119.42,80.73 114.75,86.29 109,86.29ZM109,59.83C102.45,59.83 97.12,66.15 97.12,73.92C97.12,81.69 102.45,88.01 109,88.01C115.55,88.01 120.87,81.7 120.87,73.92C120.87,66.14 115.54,59.83 109,59.83Z"
android:fillColor="#8E8E93"/>
<path
android:pathData="M107.55,53.53C103.88,53.9 100.54,55.64 97.88,58.31L98.85,59.46C99.13,59.79 99.27,60.23 99.27,60.67C99.27,61.1 99.13,61.54 98.85,61.87C98.58,62.22 98.2,62.37 97.84,62.37C97.47,62.37 97.11,62.22 96.82,61.87L95.86,60.72C93.6,63.87 92.14,67.84 91.84,72.21H93.21C94,72.21 94.65,72.97 94.65,73.91C94.65,74.84 94,75.62 93.21,75.62H91.84C92.14,79.98 93.61,83.96 95.86,87.1L96.82,85.95C97.11,85.61 97.47,85.45 97.84,85.45C98.2,85.45 98.58,85.61 98.85,85.95C99.13,86.28 99.27,86.73 99.27,87.16C99.27,87.59 99.13,88.04 98.85,88.37L97.88,89.52C100.54,92.2 103.89,93.94 107.57,94.29V92.65C107.57,91.71 108.22,90.94 109.01,90.94C101.11,90.94 94.66,83.3 94.66,73.91C94.66,64.52 101.11,56.88 109.01,56.88C108.22,56.88 107.57,56.11 107.57,55.17V53.53M110.45,53.53V55.17C110.45,56.12 109.8,56.88 109.01,56.88C116.92,56.88 123.35,64.52 123.35,73.91C123.35,83.3 116.91,90.94 109.01,90.94C109.8,90.94 110.45,91.72 110.45,92.65V94.29C114.12,93.93 117.47,92.2 120.13,89.52L119.17,88.36C118.88,88.03 118.74,87.58 118.74,87.15C118.74,86.72 118.88,86.27 119.17,85.94C119.43,85.6 119.81,85.44 120.18,85.44C120.54,85.44 120.92,85.6 121.2,85.94L122.17,87.09C124.41,83.93 125.88,79.97 126.19,75.6H124.81C124.01,75.6 123.36,74.84 123.36,73.9C123.36,72.95 124.01,72.2 124.81,72.2H126.19C125.88,67.83 124.41,63.87 122.17,60.71L121.2,61.86C120.92,62.2 120.54,62.36 120.18,62.36C119.81,62.36 119.43,62.2 119.17,61.86C118.88,61.53 118.74,61.09 118.74,60.65C118.74,60.22 118.88,59.78 119.17,59.45L120.13,58.3C117.46,55.62 114.12,53.89 110.45,53.52"
android:fillColor="#8E8E93"/>
<path
android:pathData="M109,46C108.21,46 107.55,46.76 107.55,47.71V55.17C107.55,56.12 108.21,56.88 109,56.88C109.79,56.88 110.43,56.11 110.43,55.17V47.71C110.43,46.76 109.8,46 109,46Z"
android:fillColor="#8E8E93"/>
<path
android:pathData="M93.38,53.67C93.01,53.67 92.65,53.84 92.36,54.18C91.8,54.84 91.8,55.93 92.36,56.59L95.85,60.72L96.81,61.87C97.09,62.22 97.46,62.37 97.82,62.37C98.19,62.37 98.56,62.22 98.84,61.87C99.12,61.54 99.26,61.1 99.26,60.67C99.26,60.23 99.12,59.79 98.84,59.46L97.87,58.31L94.39,54.18C94.11,53.84 93.73,53.67 93.36,53.67"
android:fillColor="#8E8E93"/>
<path
android:pathData="M93.21,72.21H86.92C86.13,72.21 85.47,72.97 85.47,73.91C85.47,74.84 86.13,75.62 86.92,75.62H93.21C94,75.62 94.65,74.85 94.65,73.91C94.65,72.96 94,72.21 93.21,72.21Z"
android:fillColor="#8E8E93"/>
<path
android:pathData="M97.84,85.46C97.47,85.46 97.11,85.62 96.82,85.96L95.86,87.11L92.38,91.25C91.81,91.91 91.81,92.99 92.38,93.65C92.66,93.99 93.02,94.16 93.39,94.16C93.75,94.16 94.13,93.99 94.41,93.65L97.88,89.52L98.85,88.37C99.13,88.04 99.27,87.59 99.27,87.16C99.27,86.73 99.13,86.28 98.85,85.95C98.58,85.61 98.2,85.45 97.84,85.45"
android:fillColor="#8E8E93"/>
<path
android:pathData="M109,90.95C108.21,90.95 107.55,91.73 107.55,92.66V100.13C107.55,101.07 108.21,101.84 109,101.84C109.79,101.84 110.43,101.07 110.43,100.13V92.66C110.43,91.72 109.79,90.95 109,90.95Z"
android:fillColor="#8E8E93"/>
<path
android:pathData="M120.17,85.46C119.8,85.46 119.42,85.62 119.15,85.96C118.87,86.29 118.73,86.74 118.73,87.17C118.73,87.6 118.87,88.05 119.15,88.38L120.12,89.54L123.59,93.67C123.87,94 124.25,94.17 124.61,94.17C124.98,94.17 125.35,94 125.64,93.67C126.2,93.01 126.2,91.92 125.64,91.26L122.15,87.13L121.19,85.97C120.91,85.63 120.53,85.47 120.17,85.47"
android:fillColor="#8E8E93"/>
<path
android:pathData="M131.08,72.21H124.8C124,72.21 123.35,72.97 123.35,73.91C123.35,74.84 124,75.62 124.8,75.62H131.08C131.87,75.62 132.53,74.85 132.53,73.91C132.53,72.96 131.87,72.21 131.08,72.21Z"
android:fillColor="#8E8E93"/>
<path
android:pathData="M124.61,53.67C124.25,53.67 123.87,53.84 123.59,54.18L120.12,58.31L119.15,59.46C118.87,59.79 118.73,60.23 118.73,60.67C118.73,61.1 118.87,61.54 119.15,61.87C119.42,62.22 119.8,62.37 120.17,62.37C120.53,62.37 120.91,62.22 121.19,61.87L122.15,60.72L125.64,56.59C126.2,55.93 126.2,54.84 125.64,54.18C125.35,53.84 124.98,53.67 124.61,53.67Z"
android:fillColor="#8E8E93"/>
android:viewportHeight="161"
android:viewportWidth="180">
<path
android:fillColor="#2C2C2E"
android:pathData="M134,147H161V154.57C161,156.78 159.21,158.57 157,158.57H138C135.79,158.57 134,156.78 134,154.57V147Z"
android:strokeColor="#8E8E93"
android:strokeWidth="2" />
<path
android:fillColor="#2C2C2E"
android:pathData="M20,147H47V154.57C47,156.78 45.21,158.57 43,158.57H24C21.79,158.57 20,156.78 20,154.57V147Z"
android:strokeColor="#8E8E93"
android:strokeWidth="2" />
<path
android:fillColor="#1C1C1E"
android:pathData="M172.38,2H7.62C4.51,2 2,4.52 2,7.62V140.56C2,143.67 4.51,146.18 7.62,146.18H172.38C175.49,146.18 178,143.67 178,140.56V7.62C178,4.52 175.49,2 172.38,2Z"
android:strokeColor="#8E8E93"
android:strokeWidth="2" />
<path
android:fillColor="#2C2C2E"
android:pathData="M154.44,18H26.56C23.49,18 21,20.49 21,23.56V123.64C21,126.71 23.49,129.2 26.56,129.2H154.44C157.51,129.2 160,126.71 160,123.64V23.56C160,20.49 157.51,18 154.44,18Z"
android:strokeColor="#8E8E93"
android:strokeWidth="2" />
<path
android:fillColor="#1C1C1E"
android:pathData="M154.76,129.8L49.89,135.92C46.69,136.11 44,133.57 44,130.38V17.55C44,14.36 46.69,11.82 49.89,12.01L154.76,18.13C157.7,18.3 160,20.73 160,23.67V124.26C160,127.2 157.7,129.63 154.76,129.8Z"
android:strokeColor="#8E8E93"
android:strokeWidth="2" />
<path
android:fillColor="#1C1C1E"
android:pathData="M164.85,40.87C164.85,38.55 162.98,36.68 160.66,36.68C158.34,36.68 156.46,38.55 156.46,40.87V57.63C156.46,59.94 158.34,61.82 160.66,61.82C162.98,61.82 164.85,59.94 164.85,57.63V40.87Z"
android:strokeColor="#8E8E93"
android:strokeWidth="1" />
<path
android:fillColor="#1C1C1E"
android:pathData="M164.85,82.77C164.85,80.45 162.98,78.58 160.66,78.58C158.34,78.58 156.46,80.45 156.46,82.77V99.53C156.46,101.84 158.34,103.71 160.66,103.71C162.98,103.71 164.85,101.84 164.85,99.53V82.77Z"
android:strokeColor="#8E8E93"
android:strokeWidth="1" />
<path
android:fillColor="#00000000"
android:pathData="M62,45C63.66,45 65,46.26 65,47.81V86.44C65,87.99 63.66,89.25 62,89.25"
android:strokeColor="#8E8E93"
android:strokeLineCap="round"
android:strokeWidth="2" />
<path
android:fillColor="#8E8E93"
android:pathData="M109,86.29C103.24,86.29 98.56,80.74 98.56,73.92C98.56,67.09 103.24,61.55 109,61.55C114.76,61.55 119.42,67.1 119.42,73.92C119.42,80.73 114.75,86.29 109,86.29ZM109,59.83C102.45,59.83 97.12,66.15 97.12,73.92C97.12,81.69 102.45,88.01 109,88.01C115.55,88.01 120.87,81.7 120.87,73.92C120.87,66.14 115.54,59.83 109,59.83Z" />
<path
android:fillColor="#8E8E93"
android:pathData="M107.55,53.53C103.88,53.9 100.54,55.64 97.88,58.31L98.85,59.46C99.13,59.79 99.27,60.23 99.27,60.67C99.27,61.1 99.13,61.54 98.85,61.87C98.58,62.22 98.2,62.37 97.84,62.37C97.47,62.37 97.11,62.22 96.82,61.87L95.86,60.72C93.6,63.87 92.14,67.84 91.84,72.21H93.21C94,72.21 94.65,72.97 94.65,73.91C94.65,74.84 94,75.62 93.21,75.62H91.84C92.14,79.98 93.61,83.96 95.86,87.1L96.82,85.95C97.11,85.61 97.47,85.45 97.84,85.45C98.2,85.45 98.58,85.61 98.85,85.95C99.13,86.28 99.27,86.73 99.27,87.16C99.27,87.59 99.13,88.04 98.85,88.37L97.88,89.52C100.54,92.2 103.89,93.94 107.57,94.29V92.65C107.57,91.71 108.22,90.94 109.01,90.94C101.11,90.94 94.66,83.3 94.66,73.91C94.66,64.52 101.11,56.88 109.01,56.88C108.22,56.88 107.57,56.11 107.57,55.17V53.53M110.45,53.53V55.17C110.45,56.12 109.8,56.88 109.01,56.88C116.92,56.88 123.35,64.52 123.35,73.91C123.35,83.3 116.91,90.94 109.01,90.94C109.8,90.94 110.45,91.72 110.45,92.65V94.29C114.12,93.93 117.47,92.2 120.13,89.52L119.17,88.36C118.88,88.03 118.74,87.58 118.74,87.15C118.74,86.72 118.88,86.27 119.17,85.94C119.43,85.6 119.81,85.44 120.18,85.44C120.54,85.44 120.92,85.6 121.2,85.94L122.17,87.09C124.41,83.93 125.88,79.97 126.19,75.6H124.81C124.01,75.6 123.36,74.84 123.36,73.9C123.36,72.95 124.01,72.2 124.81,72.2H126.19C125.88,67.83 124.41,63.87 122.17,60.71L121.2,61.86C120.92,62.2 120.54,62.36 120.18,62.36C119.81,62.36 119.43,62.2 119.17,61.86C118.88,61.53 118.74,61.09 118.74,60.65C118.74,60.22 118.88,59.78 119.17,59.45L120.13,58.3C117.46,55.62 114.12,53.89 110.45,53.52" />
<path
android:fillColor="#8E8E93"
android:pathData="M109,46C108.21,46 107.55,46.76 107.55,47.71V55.17C107.55,56.12 108.21,56.88 109,56.88C109.79,56.88 110.43,56.11 110.43,55.17V47.71C110.43,46.76 109.8,46 109,46Z" />
<path
android:fillColor="#8E8E93"
android:pathData="M93.38,53.67C93.01,53.67 92.65,53.84 92.36,54.18C91.8,54.84 91.8,55.93 92.36,56.59L95.85,60.72L96.81,61.87C97.09,62.22 97.46,62.37 97.82,62.37C98.19,62.37 98.56,62.22 98.84,61.87C99.12,61.54 99.26,61.1 99.26,60.67C99.26,60.23 99.12,59.79 98.84,59.46L97.87,58.31L94.39,54.18C94.11,53.84 93.73,53.67 93.36,53.67" />
<path
android:fillColor="#8E8E93"
android:pathData="M93.21,72.21H86.92C86.13,72.21 85.47,72.97 85.47,73.91C85.47,74.84 86.13,75.62 86.92,75.62H93.21C94,75.62 94.65,74.85 94.65,73.91C94.65,72.96 94,72.21 93.21,72.21Z" />
<path
android:fillColor="#8E8E93"
android:pathData="M97.84,85.46C97.47,85.46 97.11,85.62 96.82,85.96L95.86,87.11L92.38,91.25C91.81,91.91 91.81,92.99 92.38,93.65C92.66,93.99 93.02,94.16 93.39,94.16C93.75,94.16 94.13,93.99 94.41,93.65L97.88,89.52L98.85,88.37C99.13,88.04 99.27,87.59 99.27,87.16C99.27,86.73 99.13,86.28 98.85,85.95C98.58,85.61 98.2,85.45 97.84,85.45" />
<path
android:fillColor="#8E8E93"
android:pathData="M109,90.95C108.21,90.95 107.55,91.73 107.55,92.66V100.13C107.55,101.07 108.21,101.84 109,101.84C109.79,101.84 110.43,101.07 110.43,100.13V92.66C110.43,91.72 109.79,90.95 109,90.95Z" />
<path
android:fillColor="#8E8E93"
android:pathData="M120.17,85.46C119.8,85.46 119.42,85.62 119.15,85.96C118.87,86.29 118.73,86.74 118.73,87.17C118.73,87.6 118.87,88.05 119.15,88.38L120.12,89.54L123.59,93.67C123.87,94 124.25,94.17 124.61,94.17C124.98,94.17 125.35,94 125.64,93.67C126.2,93.01 126.2,91.92 125.64,91.26L122.15,87.13L121.19,85.97C120.91,85.63 120.53,85.47 120.17,85.47" />
<path
android:fillColor="#8E8E93"
android:pathData="M131.08,72.21H124.8C124,72.21 123.35,72.97 123.35,73.91C123.35,74.84 124,75.62 124.8,75.62H131.08C131.87,75.62 132.53,74.85 132.53,73.91C132.53,72.96 131.87,72.21 131.08,72.21Z" />
<path
android:fillColor="#8E8E93"
android:pathData="M124.61,53.67C124.25,53.67 123.87,53.84 123.59,54.18L120.12,58.31L119.15,59.46C118.87,59.79 118.73,60.23 118.73,60.67C118.73,61.1 118.87,61.54 119.15,61.87C119.42,62.22 119.8,62.37 120.17,62.37C120.53,62.37 120.91,62.22 121.19,61.87L122.15,60.72L125.64,56.59C126.2,55.93 126.2,54.84 125.64,54.18C125.35,53.84 124.98,53.67 124.61,53.67Z" />
</vector>
Loading

0 comments on commit f39669e

Please sign in to comment.