Skip to content

Commit

Permalink
Observe system theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Mar 15, 2024
1 parent fad8804 commit 8ba719a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package exchange.dydx.platformui.designSystem.theme

import android.content.Context
import android.content.res.Configuration
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.util.Log
import exchange.dydx.utilities.utils.JsonUtils
import exchange.dydx.utilities.utils.SharedPreferencesStore
Expand Down Expand Up @@ -47,6 +49,7 @@ data class ThemeConfig(
"dark" -> dark(context)
"light" -> light(context)
"classic_dark" -> classicDark(context)
"system" -> if (context.isDarkThemeOn()) dark(context) else light(context)
else -> null
}

Expand All @@ -57,6 +60,11 @@ data class ThemeConfig(
config
}
}

private fun Context.isDarkThemeOn(): Boolean {
return resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
}
}
}

Expand Down

0 comments on commit 8ba719a

Please sign in to comment.