19 * You should have received a copy of the GNU General Public License |
19 * You should have received a copy of the GNU General Public License |
20 * along with AboutOss. If not, see <http://www.gnu.org/licenses/>. |
20 * along with AboutOss. If not, see <http://www.gnu.org/licenses/>. |
21 */ |
21 */ |
22 package com.geekorum.aboutoss.ui.material3 |
22 package com.geekorum.aboutoss.ui.material3 |
23 |
23 |
24 import android.app.Activity |
|
25 import android.os.Bundle |
24 import android.os.Bundle |
26 import androidx.activity.compose.setContent |
25 import androidx.activity.compose.setContent |
|
26 import androidx.activity.enableEdgeToEdge |
27 import androidx.activity.viewModels |
27 import androidx.activity.viewModels |
28 import androidx.compose.foundation.isSystemInDarkTheme |
28 import androidx.compose.foundation.isSystemInDarkTheme |
29 import androidx.compose.material3.MaterialTheme |
29 import androidx.compose.material3.MaterialTheme |
|
30 import androidx.compose.material3.darkColorScheme |
|
31 import androidx.compose.material3.lightColorScheme |
30 import androidx.compose.runtime.Composable |
32 import androidx.compose.runtime.Composable |
31 import androidx.compose.runtime.SideEffect |
|
32 import androidx.compose.ui.graphics.toArgb |
|
33 import androidx.compose.ui.platform.LocalView |
|
34 import androidx.core.view.WindowCompat |
|
35 import com.geekorum.aboutoss.core.gms.GmsLicenseInfoRepository |
33 import com.geekorum.aboutoss.core.gms.GmsLicenseInfoRepository |
36 import com.geekorum.aboutoss.ui.common.BaseOpensourceLicenseActivity |
34 import com.geekorum.aboutoss.ui.common.BaseOpensourceLicenseActivity |
37 import com.geekorum.aboutoss.ui.common.Factory |
35 import com.geekorum.aboutoss.ui.common.Factory |
38 import com.geekorum.aboutoss.ui.common.OpenSourceLicensesViewModel |
36 import com.geekorum.aboutoss.ui.common.OpenSourceLicensesViewModel |
39 import com.geekorum.aboutoss.ui.material3.OpenSourceLicensesActivity.Companion.themeProvider |
37 import com.geekorum.aboutoss.ui.material3.OpenSourceLicensesActivity.Companion.themeProvider |
58 } |
56 } |
59 ) |
57 ) |
60 |
58 |
61 override fun onCreate(savedInstanceState: Bundle?) { |
59 override fun onCreate(savedInstanceState: Bundle?) { |
62 super.onCreate(savedInstanceState) |
60 super.onCreate(savedInstanceState) |
63 WindowCompat.setDecorFitsSystemWindows(window, false) |
61 enableEdgeToEdge() |
64 setContent { |
62 setContent { |
65 themeProvider { |
63 themeProvider { |
66 OpenSourceDependenciesNavHost( |
64 OpenSourceDependenciesNavHost( |
67 openSourceLicensesViewModel = viewModel, |
65 openSourceLicensesViewModel = viewModel, |
68 navigateUp = { |
66 navigateUp = { |
80 * The composable Theme function to set the theme of the UI in [OpenSourceLicensesActivity] |
78 * The composable Theme function to set the theme of the UI in [OpenSourceLicensesActivity] |
81 * Default to base material theme [MaterialTheme] |
79 * Default to base material theme [MaterialTheme] |
82 */ |
80 */ |
83 var themeProvider: @Composable (@Composable () -> Unit) -> Unit = { content -> |
81 var themeProvider: @Composable (@Composable () -> Unit) -> Unit = { content -> |
84 val darkTheme: Boolean = isSystemInDarkTheme() |
82 val darkTheme: Boolean = isSystemInDarkTheme() |
85 val colorScheme = MaterialTheme.colorScheme |
83 val colorScheme = if (darkTheme) darkColorScheme() else lightColorScheme() |
86 val view = LocalView.current |
84 MaterialTheme(colorScheme, content = content) |
87 if (!view.isInEditMode) { |
|
88 SideEffect { |
|
89 val window = (view.context as Activity).window |
|
90 window.statusBarColor = colorScheme.primary.toArgb() |
|
91 WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme |
|
92 } |
|
93 } |
|
94 MaterialTheme(content = content) |
|
95 } |
85 } |
96 } |
86 } |
97 } |
87 } |
98 |
88 |