From da1062c99cc75f1789de1ce69669df4c2af7b16a Mon Sep 17 00:00:00 2001 From: schordas Date: Mon, 2 Oct 2023 12:48:34 -0700 Subject: [PATCH 1/2] Migrate to e2e for starter branch --- app/build.gradle.kts | 12 ++++----- .../com/example/affirmations/MainActivity.kt | 4 +-- .../example/affirmations/ui/theme/Theme.kt | 26 ++++++++++++++++--- build.gradle.kts | 6 ++--- gradle/wrapper/gradle-wrapper.properties | 2 +- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 87be2e5..f4280b5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,12 +20,12 @@ plugins { android { namespace = "com.example.affirmations" - compileSdk = 33 + compileSdk = 34 defaultConfig { applicationId = "com.example.affirmations" minSdk = 24 - targetSdk = 33 + targetSdk = 34 versionCode = 1 versionName = "1.0" @@ -55,7 +55,7 @@ android { compose = true } composeOptions { - kotlinCompilerExtensionVersion = "1.4.7" + kotlinCompilerExtensionVersion = "1.5.3" } packaging { resources { @@ -65,14 +65,14 @@ android { } dependencies { - implementation(platform("androidx.compose:compose-bom:2023.05.01")) + implementation(platform("androidx.compose:compose-bom:2023.09.00")) implementation("androidx.activity:activity-compose:1.7.2") implementation("androidx.compose.material3:material3") implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-tooling-preview") - implementation("androidx.core:core-ktx:1.10.1") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") + implementation("androidx.core:core-ktx:1.12.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") debugImplementation("androidx.compose.ui:ui-test-manifest") debugImplementation("androidx.compose.ui:ui-tooling") diff --git a/app/src/main/java/com/example/affirmations/MainActivity.kt b/app/src/main/java/com/example/affirmations/MainActivity.kt index 511f188..6d07c2b 100644 --- a/app/src/main/java/com/example/affirmations/MainActivity.kt +++ b/app/src/main/java/com/example/affirmations/MainActivity.kt @@ -31,10 +31,8 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) setContent { AffirmationsTheme { - // A surface container using the 'background' color from the theme Surface( - modifier = Modifier.fillMaxSize(), - color = MaterialTheme.colorScheme.background + modifier = Modifier.fillMaxSize() ) { AffirmationsApp() } diff --git a/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt b/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt index e7de411..cf85e26 100644 --- a/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt @@ -17,6 +17,7 @@ package com.example.affirmations.ui.theme import android.app.Activity import android.os.Build +import android.view.View import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme @@ -25,6 +26,7 @@ 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.Color import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView @@ -61,9 +63,7 @@ fun AffirmationsTheme( val view = LocalView.current if (!view.isInEditMode) { SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.background.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme + setUpEdgeToEdge(view, darkTheme) } } @@ -72,3 +72,23 @@ fun AffirmationsTheme( content = content ) } + +/** + * Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either + * light or dark depending on whether the [darkTheme] is enabled or not. + */ +private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) { + val window = (view.context as Activity).window + WindowCompat.setDecorFitsSystemWindows(window, false) + window.statusBarColor = Color.Transparent.toArgb() + val navigationBarColor = when { + Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb() + Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb() + // Min sdk version for this app is 24, this block is for SDK versions 24 and 25 + else -> Color(0x00, 0x00, 0x00, 0x50).toArgb() + } + window.navigationBarColor = navigationBarColor + val controller = WindowCompat.getInsetsController(window, view) + controller.isAppearanceLightStatusBars = !darkTheme + controller.isAppearanceLightNavigationBars = !darkTheme +} diff --git a/build.gradle.kts b/build.gradle.kts index 76adc6b..23d077a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ */ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.0.2" apply false - id("com.android.library") version "8.0.2" apply false - id("org.jetbrains.kotlin.android") version "1.8.21" apply false + id("com.android.application") version "8.1.1" apply false + id("com.android.library") version "8.1.1" apply false + id("org.jetbrains.kotlin.android") version "1.9.10" apply false } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 58b9abb..6012ae1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Mar 15 18:26:52 PDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From e26ddf0e90bf2dd99fccd8338af8faac8e4e755e Mon Sep 17 00:00:00 2001 From: schordas Date: Mon, 2 Oct 2023 12:48:34 -0700 Subject: [PATCH 2/2] Migrate to e2e for starter branch --- app/build.gradle.kts | 2 +- .../com/example/affirmations/MainActivity.kt | 3 ++- .../example/affirmations/ui/theme/Theme.kt | 27 +++---------------- build.gradle.kts | 4 +-- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f4280b5..f4e2ec9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -66,7 +66,7 @@ android { dependencies { implementation(platform("androidx.compose:compose-bom:2023.09.00")) - implementation("androidx.activity:activity-compose:1.7.2") + implementation("androidx.activity:activity-compose:1.8.0") implementation("androidx.compose.material3:material3") implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui-graphics") diff --git a/app/src/main/java/com/example/affirmations/MainActivity.kt b/app/src/main/java/com/example/affirmations/MainActivity.kt index 6d07c2b..704fefe 100644 --- a/app/src/main/java/com/example/affirmations/MainActivity.kt +++ b/app/src/main/java/com/example/affirmations/MainActivity.kt @@ -18,8 +18,8 @@ package com.example.affirmations import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -28,6 +28,7 @@ import com.example.affirmations.ui.theme.AffirmationsTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge() super.onCreate(savedInstanceState) setContent { AffirmationsTheme { diff --git a/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt b/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt index cf85e26..2011969 100644 --- a/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/affirmations/ui/theme/Theme.kt @@ -17,7 +17,6 @@ package com.example.affirmations.ui.theme import android.app.Activity import android.os.Build -import android.view.View import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme @@ -26,7 +25,6 @@ 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.Color import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView @@ -60,10 +58,13 @@ fun AffirmationsTheme( darkTheme -> DarkColorScheme else -> LightColorScheme } + val view = LocalView.current if (!view.isInEditMode) { SideEffect { - setUpEdgeToEdge(view, darkTheme) + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.background.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme } } @@ -72,23 +73,3 @@ fun AffirmationsTheme( content = content ) } - -/** - * Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either - * light or dark depending on whether the [darkTheme] is enabled or not. - */ -private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) { - val window = (view.context as Activity).window - WindowCompat.setDecorFitsSystemWindows(window, false) - window.statusBarColor = Color.Transparent.toArgb() - val navigationBarColor = when { - Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb() - Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb() - // Min sdk version for this app is 24, this block is for SDK versions 24 and 25 - else -> Color(0x00, 0x00, 0x00, 0x50).toArgb() - } - window.navigationBarColor = navigationBarColor - val controller = WindowCompat.getInsetsController(window, view) - controller.isAppearanceLightStatusBars = !darkTheme - controller.isAppearanceLightNavigationBars = !darkTheme -} diff --git a/build.gradle.kts b/build.gradle.kts index 23d077a..1c20334 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ */ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.1.1" apply false - id("com.android.library") version "8.1.1" apply false + id("com.android.application") version "8.1.2" apply false + id("com.android.library") version "8.1.2" apply false id("org.jetbrains.kotlin.android") version "1.9.10" apply false }