Skip to content

Commit

Permalink
Fixed Issue #602:Add auto dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohit Mandalia authored and Mohit Mandalia committed Mar 26, 2022
1 parent 5b89814 commit 83d50db
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeMoreMenu.kt
Expand Up @@ -404,18 +404,22 @@ private fun QuickAccess(
icon = when (theme) {
Theme.LIGHT -> R.drawable.home_more_menu_light_mode
Theme.DARK -> R.drawable.home_more_menu_dark_mode
Theme.AUTO -> R.drawable.home_more_menu_auto_mode
},
label = when (theme) {
Theme.LIGHT -> "Light mode"
Theme.DARK -> "Dark mode"
Theme.AUTO -> "Auto mode"
},
backgroundColor = when (theme) {
Theme.LIGHT -> UI.colors.pure
Theme.DARK -> UI.colors.pureInverse
Theme.AUTO -> UI.colors.pure
},
tint = when (theme) {
Theme.LIGHT -> UI.colors.pureInverse
Theme.DARK -> UI.colors.pure
Theme.AUTO -> UI.colors.pureInverse
}
) {
onSwitchTheme()
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt
Expand Up @@ -241,7 +241,8 @@ class HomeViewModel @Inject constructor(
val newSettings = currentSettings.copy(
theme = when (currentSettings.theme) {
Theme.LIGHT -> Theme.DARK
Theme.DARK -> Theme.LIGHT
Theme.DARK -> Theme.AUTO
Theme.AUTO -> Theme.LIGHT
}
)
settingsDao.save(newSettings)
Expand Down
2 changes: 1 addition & 1 deletion ivy-design/src/main/java/com/ivy/design/api/IvyDesign.kt
Expand Up @@ -11,7 +11,7 @@ interface IvyDesign {

fun typography(): IvyTypography

fun colors(theme: Theme): IvyColors
fun colors(theme: Theme,isDarkModeEnabled: Boolean): IvyColors

fun shapes(): IvyShapes
}
Expand Up @@ -110,7 +110,7 @@ abstract class IvyWalletDesign : IvyDesign {
}
}

override fun colors(theme: Theme): IvyColors {
override fun colors(theme: Theme, isDarkModeEnabled: Boolean): IvyColors {
return when (theme) {
Theme.LIGHT -> object : IvyColors {
override val pure = White
Expand Down Expand Up @@ -154,6 +154,7 @@ abstract class IvyWalletDesign : IvyDesign {

override val isLight = false
}
Theme.AUTO -> if(isDarkModeEnabled) colors(Theme.DARK,true) else colors(Theme.LIGHT,false)
}
}

Expand Down
@@ -1,5 +1,6 @@
package com.ivy.design.l0_system

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Colors
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Shapes
Expand Down Expand Up @@ -38,7 +39,7 @@ fun IvyTheme(
design: IvyDesign,
content: @Composable () -> Unit
) {
val colors = design.colors(theme)
val colors = design.colors(theme, isSystemInDarkTheme())
val typography = design.typography()
val shapes = design.shapes()

Expand Down
3 changes: 2 additions & 1 deletion ivy-design/src/main/java/com/ivy/design/l0_system/Theme.kt
@@ -1,12 +1,13 @@
package com.ivy.design.l0_system

enum class Theme {
LIGHT, DARK;
LIGHT, DARK, AUTO;

fun inverted(): Theme {
return when (this) {
LIGHT -> DARK
DARK -> LIGHT
AUTO -> AUTO
}
}
}

0 comments on commit 83d50db

Please sign in to comment.