From d55ecf72d5599deb8bb8fb89c2725e95c2eef872 Mon Sep 17 00:00:00 2001 From: "jaguhdeveloper@gmail.com" Date: Thu, 11 Jan 2024 18:08:21 +0300 Subject: [PATCH 1/2] updated from material to material3 --- app/build.gradle | 2 +- .../getstream/androiddeveloperroadmap/MainActivity.kt | 10 +++++----- .../androiddeveloperroadmap/ui/theme/Shape.kt | 2 +- .../getstream/androiddeveloperroadmap/ui/theme/Type.kt | 4 ++-- build.gradle | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dc19891..ccde84c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { dependencies { implementation "androidx.compose.ui:ui:$compose_version" - implementation "androidx.compose.material:material:$compose_version" + implementation "androidx.compose.material3:material3" implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" implementation "androidx.compose.ui:ui-tooling:$compose_version" implementation "androidx.compose.runtime:runtime:$compose_version" diff --git a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/MainActivity.kt b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/MainActivity.kt index e62da87..c21e885 100644 --- a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/MainActivity.kt +++ b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/MainActivity.kt @@ -20,8 +20,8 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Surface +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.layout.ContentScale @@ -42,7 +42,7 @@ class MainActivity : ComponentActivity() { setContent { AndroidDeveloperRoadmapTheme { Surface( - color = MaterialTheme.colors.background + color = MaterialTheme.colorScheme.background ) { AndroidRoadmap() } @@ -53,7 +53,7 @@ class MainActivity : ComponentActivity() { @Composable private fun AndroidRoadmap() { - val background = MaterialTheme.colors.background + val background = MaterialTheme.colorScheme.background CoilImage( modifier = Modifier .fillMaxSize() @@ -70,7 +70,7 @@ private fun AndroidRoadmap() { ) } -@Preview(showBackground = true) +@Preview(showBackground = true, showSystemUi = true) @Composable private fun DefaultPreview() { AndroidDeveloperRoadmapTheme { diff --git a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Shape.kt b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Shape.kt index b3db7ec..d69d4cd 100644 --- a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Shape.kt +++ b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Shape.kt @@ -17,7 +17,7 @@ package io.getstream.androiddeveloperroadmap.ui.theme import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Shapes +import androidx.compose.material3.Shapes import androidx.compose.ui.unit.dp val Shapes = Shapes( diff --git a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Type.kt b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Type.kt index a133229..6df8a35 100644 --- a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Type.kt +++ b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Type.kt @@ -16,7 +16,7 @@ package io.getstream.androiddeveloperroadmap.ui.theme -import androidx.compose.material.Typography +import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight @@ -24,7 +24,7 @@ import androidx.compose.ui.unit.sp // Set of Material typography styles to start with val Typography = Typography( - body1 = TextStyle( + bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp diff --git a/build.gradle b/build.gradle index b9e5408..efd9a0e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { compose_version = '1.5.2' compose_compiler_version = '1.5.3' - compose_activity_version = '1.7.2' + compose_activity_version = '1.8.2' landscapist_version = '2.2.10' zoomable_version = '1.5.1' } From d6dbeb82edc9ba3b63b78f7ecaa05fee0a304cd1 Mon Sep 17 00:00:00 2001 From: "jaguhdeveloper@gmail.com" Date: Thu, 11 Jan 2024 18:09:07 +0300 Subject: [PATCH 2/2] added dynamic colors --- .../androiddeveloperroadmap/ui/theme/Theme.kt | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Theme.kt b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Theme.kt index bcfac78..70d7088 100644 --- a/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Theme.kt +++ b/app/src/main/kotlin/io/getstream/androiddeveloperroadmap/ui/theme/Theme.kt @@ -16,37 +16,59 @@ package io.getstream.androiddeveloperroadmap.ui.theme +import android.app.Activity +import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material.MaterialTheme -import androidx.compose.material.darkColors -import androidx.compose.material.lightColors +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat -private val DarkColorPalette = darkColors( +private val DarkColorScheme = darkColorScheme( primary = Purple200, - primaryVariant = Purple700, - secondary = Teal200 + secondary = Purple700, + tertiary = Teal200 ) -private val LightColorPalette = lightColors( +private val LightColorScheme = lightColorScheme( primary = Purple500, - primaryVariant = Purple700, - secondary = Teal200 + secondary = Purple700, + tertiary = Teal200 ) @Composable fun AndroidDeveloperRoadmapTheme( darkTheme: Boolean = isSystemInDarkTheme(), + dynamicColor: Boolean = true, content: @Composable () -> Unit ) { - val colors = if (darkTheme) { - DarkColorPalette - } else { - LightColorPalette + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } } MaterialTheme( - colors = colors, + colorScheme = colorScheme, typography = Typography, shapes = Shapes, content = content