From 5ed97265a01424fea8e1fc6873f28cdbc1e61208 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sun, 5 Dec 2021 22:08:22 +0100 Subject: [PATCH] Adjust legacy compose theme --- .../de/mm20/launcher2/ui/LegacyAppTheme.kt | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/ui/src/main/java/de/mm20/launcher2/ui/LegacyAppTheme.kt b/ui/src/main/java/de/mm20/launcher2/ui/LegacyAppTheme.kt index be083743..bd82a7f0 100644 --- a/ui/src/main/java/de/mm20/launcher2/ui/LegacyAppTheme.kt +++ b/ui/src/main/java/de/mm20/launcher2/ui/LegacyAppTheme.kt @@ -1,11 +1,20 @@ package de.mm20.launcher2.ui +import android.util.TypedValue import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material3.* +import androidx.compose.material.darkColors +import androidx.compose.material.lightColors +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Typography +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp +import androidx.compose.material.MaterialTheme as Material2Theme val legacyTypography = Typography( displayLarge = TextStyle( @@ -70,11 +79,39 @@ val legacyTypography = Typography( ), ) + @Composable fun LegacyLauncherTheme(content: @Composable () -> Unit) { + val theme = LocalContext.current.theme + + val colorSurface = TypedValue() + theme.resolveAttribute(R.attr.colorSurface, colorSurface, true) + val colorSurfaceVariant = TypedValue() + theme.resolveAttribute(R.attr.colorSurfaceVariant, colorSurfaceVariant, true) + + val colorPrimary = TypedValue() + theme.resolveAttribute(R.attr.colorPrimary, colorSurfaceVariant, true) + + MaterialTheme( typography = legacyTypography, - content = content, - colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme() - ) + colorScheme = if (isSystemInDarkTheme()) darkColorScheme( + surface = Color(colorSurface.data), + primary = Color(colorSurface.data), + ) else lightColorScheme( + surface = Color(colorSurface.data), + primary = Color(colorSurface.data), + ) + ) { + Material2Theme( + colors = if (isSystemInDarkTheme()) darkColors( + surface = Color(colorSurface.data), + primary = Color(colorSurface.data), + ) else lightColors( + surface = Color(colorSurface.data), + primary = Color(colorSurface.data), + ), + content = content + ) + } } \ No newline at end of file