Skip to content

Commit d1ae44d

Browse files
author
schordas
committed
Update main branch with e2e
1 parent 607d016 commit d1ae44d

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

app/build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ plugins {
2020

2121
android {
2222
namespace = "com.example.affirmations"
23-
compileSdk = 33
23+
compileSdk = 34
2424

2525
defaultConfig {
2626
applicationId = "com.example.affirmations"
2727
minSdk = 24
28-
targetSdk = 33
28+
targetSdk = 34
2929
versionCode = 1
3030
versionName = "1.0"
3131

@@ -55,7 +55,7 @@ android {
5555
compose = true
5656
}
5757
composeOptions {
58-
kotlinCompilerExtensionVersion = "1.4.7"
58+
kotlinCompilerExtensionVersion = "1.5.3"
5959
}
6060
packaging {
6161
resources {
@@ -65,14 +65,14 @@ android {
6565
}
6666

6767
dependencies {
68-
implementation(platform("androidx.compose:compose-bom:2023.05.01"))
68+
implementation(platform("androidx.compose:compose-bom:2023.09.00"))
6969
implementation("androidx.activity:activity-compose:1.7.2")
7070
implementation("androidx.compose.material3:material3")
7171
implementation("androidx.compose.ui:ui")
7272
implementation("androidx.compose.ui:ui-graphics")
7373
implementation("androidx.compose.ui:ui-tooling-preview")
74-
implementation("androidx.core:core-ktx:1.10.1")
75-
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
74+
implementation("androidx.core:core-ktx:1.12.0")
75+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
7676

7777
debugImplementation("androidx.compose.ui:ui-test-manifest")
7878
debugImplementation("androidx.compose.ui:ui-tooling")

app/src/main/java/com/example/affirmations/MainActivity.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ import androidx.activity.ComponentActivity
2020
import androidx.activity.compose.setContent
2121
import androidx.compose.foundation.Image
2222
import androidx.compose.foundation.layout.Column
23+
import androidx.compose.foundation.layout.WindowInsets
24+
import androidx.compose.foundation.layout.asPaddingValues
25+
import androidx.compose.foundation.layout.calculateEndPadding
26+
import androidx.compose.foundation.layout.calculateStartPadding
2327
import androidx.compose.foundation.layout.fillMaxSize
2428
import androidx.compose.foundation.layout.fillMaxWidth
2529
import androidx.compose.foundation.layout.height
2630
import androidx.compose.foundation.layout.padding
31+
import androidx.compose.foundation.layout.safeDrawing
32+
import androidx.compose.foundation.layout.statusBarsPadding
2733
import androidx.compose.foundation.lazy.LazyColumn
2834
import androidx.compose.foundation.lazy.items
2935
import androidx.compose.material3.Card
@@ -34,6 +40,7 @@ import androidx.compose.runtime.Composable
3440
import androidx.compose.ui.Modifier
3541
import androidx.compose.ui.layout.ContentScale
3642
import androidx.compose.ui.platform.LocalContext
43+
import androidx.compose.ui.platform.LocalLayoutDirection
3744
import androidx.compose.ui.res.painterResource
3845
import androidx.compose.ui.res.stringResource
3946
import androidx.compose.ui.tooling.preview.Preview
@@ -48,10 +55,18 @@ class MainActivity : ComponentActivity() {
4855
super.onCreate(savedInstanceState)
4956
setContent {
5057
AffirmationsTheme {
58+
val layoutDirection = LocalLayoutDirection.current
5159
// A surface container using the 'background' color from the theme
5260
Surface(
53-
modifier = Modifier.fillMaxSize(),
54-
color = MaterialTheme.colorScheme.background
61+
modifier = Modifier
62+
.fillMaxSize()
63+
.statusBarsPadding()
64+
.padding(
65+
start = WindowInsets.safeDrawing.asPaddingValues()
66+
.calculateStartPadding(layoutDirection),
67+
end = WindowInsets.safeDrawing.asPaddingValues()
68+
.calculateEndPadding(layoutDirection)
69+
),
5570
) {
5671
AffirmationsApp()
5772
}

app/src/main/java/com/example/affirmations/ui/theme/Theme.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.example.affirmations.ui.theme
1717

1818
import android.app.Activity
1919
import android.os.Build
20+
import android.view.View
2021
import androidx.compose.foundation.isSystemInDarkTheme
2122
import androidx.compose.material3.MaterialTheme
2223
import androidx.compose.material3.darkColorScheme
@@ -25,6 +26,7 @@ import androidx.compose.material3.dynamicLightColorScheme
2526
import androidx.compose.material3.lightColorScheme
2627
import androidx.compose.runtime.Composable
2728
import androidx.compose.runtime.SideEffect
29+
import androidx.compose.ui.graphics.Color
2830
import androidx.compose.ui.graphics.toArgb
2931
import androidx.compose.ui.platform.LocalContext
3032
import androidx.compose.ui.platform.LocalView
@@ -61,9 +63,7 @@ fun AffirmationsTheme(
6163
val view = LocalView.current
6264
if (!view.isInEditMode) {
6365
SideEffect {
64-
val window = (view.context as Activity).window
65-
window.statusBarColor = colorScheme.background.toArgb()
66-
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
66+
setUpEdgeToEdge(view, darkTheme)
6767
}
6868
}
6969

@@ -72,3 +72,23 @@ fun AffirmationsTheme(
7272
content = content
7373
)
7474
}
75+
76+
/**
77+
* Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either
78+
* light or dark depending on whether the [darkTheme] is enabled or not.
79+
*/
80+
private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) {
81+
val window = (view.context as Activity).window
82+
WindowCompat.setDecorFitsSystemWindows(window, false)
83+
window.statusBarColor = Color.Transparent.toArgb()
84+
val navigationBarColor = when {
85+
Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb()
86+
Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb()
87+
// Min sdk version for this app is 24, this block is for SDK versions 24 and 25
88+
else -> Color(0x00, 0x00, 0x00, 0x50).toArgb()
89+
}
90+
window.navigationBarColor = navigationBarColor
91+
val controller = WindowCompat.getInsetsController(window, view)
92+
controller.isAppearanceLightStatusBars = !darkTheme
93+
controller.isAppearanceLightNavigationBars = !darkTheme
94+
}

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1717
plugins {
18-
id("com.android.application") version "8.0.2" apply false
19-
id("com.android.library") version "8.0.2" apply false
20-
id("org.jetbrains.kotlin.android") version "1.8.21" apply false
18+
id("com.android.application") version "8.1.1" apply false
19+
id("com.android.library") version "8.1.1" apply false
20+
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
2121
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Wed Mar 15 18:26:52 PDT 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)