Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed May 1, 2024
1 parent 264a6db commit c1f32ed
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ private fun ThemeBottomSheet(
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
) {
Column(
modifier = Modifier.selectableGroup(),
modifier = Modifier
.selectableGroup()
.padding(top = 6.dp),
verticalArrangement = Arrangement.Center,
) {
themeRadioOptions.forEach { text ->
Expand Down
78 changes: 45 additions & 33 deletions app/src/main/java/com/starry/greenstash/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

package com.starry.greenstash.ui.theme

import android.content.Context
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
Expand Down Expand Up @@ -99,6 +101,42 @@ private val DarkColors = darkColorScheme(
primary = md_theme_dark_primary,
)

fun getColorScheme(
themeState: ThemeMode,
materialYouState: Boolean,
amoledTheme: Boolean,
darkTheme: Boolean,
context: Context
): ColorScheme {
val initialColorScheme = when (themeState) {
ThemeMode.Light -> if (materialYouState && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
dynamicLightColorScheme(context)
} else {
LightColors
}

ThemeMode.Dark -> if (materialYouState && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
dynamicDarkColorScheme(context)
} else {
DarkColors
}

ThemeMode.Auto -> if (materialYouState && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
} else {
if (darkTheme) DarkColors else LightColors
}
}

return if (amoledTheme && // Check if AMOLED theme is enabled
(themeState == ThemeMode.Dark || themeState == ThemeMode.Auto && darkTheme)
) {
initialColorScheme.copy(surface = Color.Black, background = Color.Black)
} else {
initialColorScheme
}
}

@Composable
fun GreenStashTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
Expand All @@ -112,39 +150,13 @@ fun GreenStashTheme(
initial = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
)


var colorScheme = when (themeState.value) {
ThemeMode.Light -> if (materialYouState.value && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) dynamicLightColorScheme(
context
) else LightColors

ThemeMode.Dark -> if (materialYouState.value && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) dynamicDarkColorScheme(
context
) else DarkColors

ThemeMode.Auto -> if (materialYouState.value && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
} else {
if (darkTheme) DarkColors else LightColors
}
}

if (amoledTheme.value && // Amoled theme enabled
(themeState.value == ThemeMode.Dark || themeState.value == ThemeMode.Auto && darkTheme)
) {
colorScheme = colorScheme.copy(surface = Color.Black, background = Color.Black)
}

/*
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
}
}
*/

val colorScheme = getColorScheme(
themeState = themeState.value,
materialYouState = materialYouState.value,
amoledTheme = amoledTheme.value,
darkTheme = darkTheme,
context = context
)
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
Expand Down

0 comments on commit c1f32ed

Please sign in to comment.