@@ -18,17 +18,19 @@ package com.prof18.secureqrreader
1818
1919import android.content.res.Configuration
2020import android.os.Bundle
21+ import android.util.Log
2122import androidx.activity.ComponentActivity
2223import androidx.activity.SystemBarStyle
2324import androidx.activity.compose.setContent
2425import androidx.activity.enableEdgeToEdge
2526import androidx.compose.animation.AnimatedContentTransitionScope
2627import androidx.compose.animation.fadeIn
2728import androidx.compose.animation.fadeOut
28- import androidx.compose.material.MaterialTheme
29+ import androidx.compose.foundation.isSystemInDarkTheme
2930import androidx.compose.runtime.LaunchedEffect
3031import androidx.compose.runtime.getValue
3132import androidx.compose.runtime.mutableStateOf
33+ import androidx.compose.runtime.remember
3234import androidx.compose.runtime.rememberCoroutineScope
3335import androidx.compose.runtime.saveable.rememberSaveable
3436import androidx.compose.runtime.setValue
@@ -47,7 +49,6 @@ import com.prof18.secureqrreader.screens.ScanScreen
4749import com.prof18.secureqrreader.screens.SplashScreen
4850import com.prof18.secureqrreader.screens.WelcomeScreen
4951import com.prof18.secureqrreader.style.SecureQrReaderTheme
50- import com.prof18.secureqrreader.style.toolbarColor
5152import kotlinx.coroutines.launch
5253
5354class MainActivity : ComponentActivity () {
@@ -59,42 +60,51 @@ class MainActivity : ComponentActivity() {
5960 val splashScreen = installSplashScreen()
6061 splashScreen.setKeepOnScreenCondition { ! dismissSplashScreen }
6162
62- enableEdgeToEdge()
63-
6463 super .onCreate(savedInstanceState)
6564
6665 setContent {
6766 val navController = rememberNavController()
6867 val scope = rememberCoroutineScope()
6968 val navBackStackEntry by navController.currentBackStackEntryAsState()
69+ val isDarkTheme = isSystemInDarkTheme()
70+
71+ val defaultSystemBarStyle = SystemBarStyle .auto(
72+ android.graphics.Color .TRANSPARENT ,
73+ darkScrim = android.graphics.Color .TRANSPARENT ,
74+ detectDarkMode = { isDarkTheme },
75+ )
76+ var systemBarStyle by remember {
77+ mutableStateOf(
78+ defaultSystemBarStyle
79+ )
80+ }
7081
7182 var scanResult by rememberSaveable {
7283 mutableStateOf<String ?>(null )
7384 }
85+ val configuration = LocalConfiguration .current
7486
7587 LaunchedEffect (Unit ) {
76- navController.addOnDestinationChangedListener { _, destination, _ ->
77- dismissSplashScreen = destination.route != Screen .Splash .name
78- }
79- }
80-
81- SecureQrReaderTheme {
82- val toolbarColor = toolbarColor()
83- val splashScreenColor = MaterialTheme .colors.background
84- val configuration = LocalConfiguration .current
85-
86- val statusBarColor = when (navBackStackEntry?.destination?.route) {
87- Screen .WelcomeScreen .name -> splashScreenColor
88- Screen .ScanScreen .name -> {
89- when (configuration.orientation) {
90- Configuration .ORIENTATION_LANDSCAPE -> toolbarColor
91- else -> Color .Transparent
88+ navController.currentBackStackEntryFlow.collect { destination ->
89+ Log .d(" Tag" , " Got destination change: $destination " )
90+ dismissSplashScreen = destination.destination.route != Screen .Splash .name
91+
92+ systemBarStyle = when (destination.destination.route) {
93+ Screen .ScanScreen .name -> {
94+ when (configuration.orientation) {
95+ Configuration .ORIENTATION_LANDSCAPE -> defaultSystemBarStyle
96+ else -> SystemBarStyle .dark(
97+ android.graphics.Color .TRANSPARENT ,
98+ )
99+ }
92100 }
93- }
94101
95- else -> toolbarColor
102+ else -> defaultSystemBarStyle
103+ }
96104 }
105+ }
97106
107+ SecureQrReaderTheme {
98108 val navigationBarStyle =
99109 if (navBackStackEntry?.destination?.route == Screen .ScanScreen .name && configuration.orientation == Configuration .ORIENTATION_PORTRAIT ) {
100110 SystemBarStyle .dark(
@@ -108,9 +118,7 @@ class MainActivity : ComponentActivity() {
108118 }
109119
110120 enableEdgeToEdge(
111- statusBarStyle = SystemBarStyle .dark(
112- statusBarColor.toArgb(),
113- ),
121+ statusBarStyle = systemBarStyle,
114122 navigationBarStyle = navigationBarStyle,
115123 )
116124
0 commit comments