|
| 1 | +package com.example.cfseeker.ui.theme |
| 2 | + |
| 3 | +import android.app.Activity |
| 4 | +import androidx.compose.foundation.isSystemInDarkTheme |
| 5 | +import androidx.compose.material3.MaterialTheme |
| 6 | +import androidx.compose.material3.darkColorScheme |
| 7 | +import androidx.compose.material3.lightColorScheme |
| 8 | +import androidx.compose.runtime.Composable |
| 9 | +import androidx.compose.runtime.SideEffect |
| 10 | +import androidx.compose.ui.graphics.toArgb |
| 11 | +import androidx.compose.ui.platform.LocalView |
| 12 | +import androidx.core.view.WindowCompat |
| 13 | + |
| 14 | +private val LightColorScheme = lightColorScheme( |
| 15 | + primary = md_theme_light_primary, |
| 16 | + onPrimary = md_theme_light_onPrimary, |
| 17 | + primaryContainer = md_theme_light_primaryContainer, |
| 18 | + onPrimaryContainer = md_theme_light_onPrimaryContainer, |
| 19 | + secondary = md_theme_light_secondary, |
| 20 | + onSecondary = md_theme_light_onSecondary, |
| 21 | + secondaryContainer = md_theme_light_secondaryContainer, |
| 22 | + onSecondaryContainer = md_theme_light_onSecondaryContainer, |
| 23 | + error = md_theme_light_error, |
| 24 | + onError = md_theme_light_onError, |
| 25 | + errorContainer = md_theme_light_errorContainer, |
| 26 | + onErrorContainer = md_theme_light_onErrorContainer, |
| 27 | + background = md_theme_light_background, |
| 28 | + onBackground = md_theme_light_onBackground, |
| 29 | + surface = md_theme_light_surface, |
| 30 | + onSurface = md_theme_light_onSurface, |
| 31 | + surfaceVariant = md_theme_light_surfaceVariant, |
| 32 | + onSurfaceVariant = md_theme_light_onSurfaceVariant, |
| 33 | +) |
| 34 | + |
| 35 | +private val DarkColorScheme = darkColorScheme( |
| 36 | + primary = md_theme_dark_primary, |
| 37 | + onPrimary = md_theme_dark_onPrimary, |
| 38 | + primaryContainer = md_theme_dark_primaryContainer, |
| 39 | + onPrimaryContainer = md_theme_dark_onPrimaryContainer, |
| 40 | + secondary = md_theme_dark_secondary, |
| 41 | + onSecondary = md_theme_dark_onSecondary, |
| 42 | + secondaryContainer = md_theme_dark_secondaryContainer, |
| 43 | + onSecondaryContainer = md_theme_dark_onSecondaryContainer, |
| 44 | + error = md_theme_dark_error, |
| 45 | + onError = md_theme_dark_onError, |
| 46 | + errorContainer = md_theme_dark_errorContainer, |
| 47 | + onErrorContainer = md_theme_dark_onErrorContainer, |
| 48 | + background = md_theme_dark_background, |
| 49 | + onBackground = md_theme_dark_onBackground, |
| 50 | + surface = md_theme_dark_surface, |
| 51 | + onSurface = md_theme_dark_onSurface, |
| 52 | + surfaceVariant = md_theme_dark_surfaceVariant, |
| 53 | + onSurfaceVariant = md_theme_dark_onSurfaceVariant, |
| 54 | +) |
| 55 | + |
| 56 | +@Composable |
| 57 | +fun CFSeekerTheme( |
| 58 | + darkTheme: Boolean = isSystemInDarkTheme(), |
| 59 | + content: @Composable () -> Unit |
| 60 | +) { |
| 61 | + val colorScheme = when { |
| 62 | + darkTheme -> DarkColorScheme |
| 63 | + else -> LightColorScheme |
| 64 | + } |
| 65 | + |
| 66 | + val view = LocalView.current |
| 67 | + if (!view.isInEditMode) { |
| 68 | + SideEffect { |
| 69 | + val window = (view.context as Activity).window |
| 70 | + window.statusBarColor = colorScheme.primary.toArgb() |
| 71 | + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + MaterialTheme( |
| 76 | + colorScheme = colorScheme, |
| 77 | + typography = Typography, |
| 78 | + content = content |
| 79 | + ) |
| 80 | +} |
0 commit comments