Skip to content

Commit

Permalink
fix: fallback status bar color to black when light theme enabled on miui
Browse files Browse the repository at this point in the history
  • Loading branch information
uragiristereo committed Sep 19, 2021
1 parent 224aaff commit bf6ae4e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.uragiristereo.mejiboard.ui.screens.settings.SettingsScreen
import com.uragiristereo.mejiboard.ui.screens.splash.SplashScreen
import com.uragiristereo.mejiboard.ui.theme.MejiboardTheme
import com.uragiristereo.mejiboard.ui.viewmodel.MainViewModel
import com.uragiristereo.mejiboard.util.MiuiHelper
import com.uragiristereo.mejiboard.util.MiuiHelper.isDeviceMiui
import soup.compose.material.motion.materialSharedAxisXIn
import soup.compose.material.motion.materialSharedAxisXOut
import soup.compose.material.motion.navigation.MaterialMotionNavHost
Expand All @@ -36,6 +38,7 @@ fun MainNavigation(
) {
val mainNavigation = rememberMaterialMotionNavController()
val systemUiController = rememberSystemUiController()
val isDeviceMiui = isDeviceMiui()

mainViewModel.isDesiredThemeDark =
when (mainViewModel.theme) {
Expand All @@ -52,9 +55,6 @@ fun MainNavigation(
theme = mainViewModel.theme,
blackTheme = mainViewModel.blackTheme
) {
systemUiController.setStatusBarColor(MaterialTheme.colors.surface)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface.copy(0.4f))

Surface(color = MaterialTheme.colors.background) {
MaterialMotionNavHost(navController = mainNavigation, startDestination = "main") {
composable("splash") {
Expand All @@ -63,7 +63,11 @@ fun MainNavigation(
SplashScreen(mainNavigation, mainViewModel.isDesiredThemeDark)
}
composable("main") {
systemUiController.setSystemBarsColor(MaterialTheme.colors.surface)
if (isDeviceMiui && !mainViewModel.isDesiredThemeDark) {
systemUiController.setStatusBarColor(Color.Black)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface)
} else
systemUiController.setSystemBarsColor(MaterialTheme.colors.surface)

MainScreen(mainNavigation, mainViewModel)
}
Expand All @@ -72,13 +76,24 @@ fun MainNavigation(
enterMotionSpec = { _, _ -> materialSharedAxisXIn() },
exitMotionSpec = { _, _ -> materialSharedAxisXOut() },
) {
if (isDeviceMiui && !mainViewModel.isDesiredThemeDark) {
systemUiController.setStatusBarColor(Color.Black)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface)
} else
systemUiController.setSystemBarsColor(MaterialTheme.colors.surface)

SearchScreen(mainNavigation, mainViewModel)
}
composable(
"settings",
) {
systemUiController.setStatusBarColor(MaterialTheme.colors.surface)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface.copy(0.4f))
if (isDeviceMiui && !mainViewModel.isDesiredThemeDark) {
systemUiController.setStatusBarColor(Color.Black)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface)
} else {
systemUiController.setStatusBarColor(MaterialTheme.colors.surface)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface.copy(0.4f))
}

SettingsScreen(mainNavigation, mainViewModel)
}
Expand All @@ -91,8 +106,13 @@ fun MainNavigation(
composable(
"about",
) {
systemUiController.setStatusBarColor(MaterialTheme.colors.surface)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface.copy(0.4f))
if (isDeviceMiui && !mainViewModel.isDesiredThemeDark) {
systemUiController.setStatusBarColor(Color.Black)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface)
} else {
systemUiController.setStatusBarColor(MaterialTheme.colors.surface)
systemUiController.setNavigationBarColor(MaterialTheme.colors.surface.copy(0.4f))
}

AboutScreen(mainNavigation, mainViewModel)
}
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/uragiristereo/mejiboard/util/MiuiHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.uragiristereo.mejiboard.util

import android.annotation.SuppressLint

@SuppressLint("PrivateApi")
object MiuiHelper {
fun isDeviceMiui(): Boolean {
val c = Class.forName("android.os.SystemProperties")
val get = c.getMethod("get", String::class.java)
val miui = get.invoke(c, "ro.miui.ui.version.code") as String

return miui.isNotEmpty()
}
}

0 comments on commit bf6ae4e

Please sign in to comment.