Skip to content

Commit ac83068

Browse files
authored
Simplified edge to edge (#14)
1 parent 63fcef2 commit ac83068

7 files changed

Lines changed: 36 additions & 19 deletions

File tree

app/build.gradle.kts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
@file:Suppress("UnstableApiUsage")
1615

1716
plugins {
1817
id("com.android.application")
@@ -21,12 +20,12 @@ plugins {
2120

2221
android {
2322
namespace = "com.example.superheroes"
24-
compileSdk = 33
23+
compileSdk = 34
2524

2625
defaultConfig {
2726
applicationId = "com.example.superheroes"
2827
minSdk = 24
29-
targetSdk = 33
28+
targetSdk = 34
3029
versionCode = 1
3130
versionName = "1.0"
3231

@@ -56,7 +55,7 @@ android {
5655
compose = true
5756
}
5857
composeOptions {
59-
kotlinCompilerExtensionVersion = "1.4.7"
58+
kotlinCompilerExtensionVersion = "1.5.3"
6059
}
6160
packaging {
6261
resources {
@@ -66,7 +65,7 @@ android {
6665
}
6766

6867
dependencies {
69-
implementation(platform("androidx.compose:compose-bom:2023.06.00"))
68+
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
7069
implementation("androidx.activity:activity-compose:1.7.2")
7170
implementation("androidx.compose.material3:material3")
7271
implementation("androidx.compose.ui:ui")

app/src/main/java/com/example/superheroes/HeroesScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.animation.slideInVertically
2929
import androidx.compose.foundation.Image
3030
import androidx.compose.foundation.layout.Box
3131
import androidx.compose.foundation.layout.Column
32+
import androidx.compose.foundation.layout.PaddingValues
3233
import androidx.compose.foundation.layout.Row
3334
import androidx.compose.foundation.layout.Spacer
3435
import androidx.compose.foundation.layout.fillMaxWidth
@@ -63,6 +64,7 @@ import com.example.superheroes.ui.theme.SuperheroesTheme
6364
fun HeroesList(
6465
heroes: List<Hero>,
6566
modifier: Modifier = Modifier,
67+
contentPadding: PaddingValues = PaddingValues(0.dp),
6668
) {
6769
val visibleState = remember {
6870
MutableTransitionState(false).apply {
@@ -80,7 +82,7 @@ fun HeroesList(
8082
exit = fadeOut(),
8183
modifier = modifier
8284
) {
83-
LazyColumn {
85+
LazyColumn(contentPadding = contentPadding) {
8486
itemsIndexed(heroes) { index, hero ->
8587
HeroListItem(
8688
hero = hero,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
2222
import androidx.compose.foundation.layout.fillMaxSize
23-
import androidx.compose.foundation.layout.padding
2423
import androidx.compose.material3.CenterAlignedTopAppBar
2524
import androidx.compose.material3.ExperimentalMaterial3Api
2625
import androidx.compose.material3.MaterialTheme
@@ -66,8 +65,7 @@ class MainActivity : ComponentActivity() {
6665
data source as a dependency and exposes heroes.
6766
*/
6867
val heroes = HeroesRepository.heroes
69-
HeroesList(heroes = heroes, Modifier.padding(it))
70-
68+
HeroesList(heroes = heroes, contentPadding = it)
7169
}
7270
}
7371

@@ -98,4 +96,3 @@ class MainActivity : ComponentActivity() {
9896
}
9997
}
10098
}
101-

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

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

1919
import android.app.Activity
2020
import android.os.Build
21+
import android.view.View
2122
import androidx.compose.foundation.isSystemInDarkTheme
2223
import androidx.compose.material3.MaterialTheme
2324
import androidx.compose.material3.darkColorScheme
@@ -26,6 +27,7 @@ import androidx.compose.material3.dynamicLightColorScheme
2627
import androidx.compose.material3.lightColorScheme
2728
import androidx.compose.runtime.Composable
2829
import androidx.compose.runtime.SideEffect
30+
import androidx.compose.ui.graphics.Color
2931
import androidx.compose.ui.graphics.toArgb
3032
import androidx.compose.ui.platform.LocalContext
3133
import androidx.compose.ui.platform.LocalView
@@ -115,9 +117,7 @@ fun SuperheroesTheme(
115117
val view = LocalView.current
116118
if (!view.isInEditMode) {
117119
SideEffect {
118-
val window = (view.context as Activity).window
119-
window.statusBarColor = colorScheme.background.toArgb()
120-
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
120+
setUpEdgeToEdge(view, darkTheme)
121121
}
122122
}
123123

@@ -128,3 +128,23 @@ fun SuperheroesTheme(
128128
content = content
129129
)
130130
}
131+
132+
/**
133+
* Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either
134+
* light or dark depending on whether the [darkTheme] is enabled or not.
135+
*/
136+
private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) {
137+
val window = (view.context as Activity).window
138+
WindowCompat.setDecorFitsSystemWindows(window, false)
139+
window.statusBarColor = Color.Transparent.toArgb()
140+
val navigationBarColor = when {
141+
Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb()
142+
Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb()
143+
// Min sdk version for this app is 24, this block is for SDK versions 24 and 25
144+
else -> Color(0x00, 0x00, 0x00, 0x50).toArgb()
145+
}
146+
window.navigationBarColor = navigationBarColor
147+
val controller = WindowCompat.getInsetsController(window, view)
148+
controller.isAppearanceLightStatusBars = !darkTheme
149+
controller.isAppearanceLightNavigationBars = !darkTheme
150+
}

app/src/main/java/com/example/superheroes/ui/theme/Type.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ val Cabin = FontFamily(
2828
Font(R.font.cabin_regular, FontWeight.Normal),
2929
Font(R.font.cabin_bold, FontWeight.Bold)
3030
)
31+
3132
// Set of Material typography styles to start with
3233
val Typography = Typography(
33-
3434
bodyLarge = TextStyle(
3535
fontFamily = Cabin,
3636
fontWeight = FontWeight.Normal,
3737
fontSize = 16.sp,
3838
lineHeight = 24.sp,
3939
letterSpacing = 0.5.sp
4040
),
41-
4241
displayLarge = TextStyle(
4342
fontFamily = Cabin,
4443
fontWeight = FontWeight.Normal,

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1818
plugins {
19-
id("com.android.application") version "8.0.2" apply false
20-
id("com.android.library") version "8.0.2" apply false
21-
id("org.jetbrains.kotlin.android") version "1.8.21" apply false
19+
id("com.android.application") version "8.1.1" apply false
20+
id("com.android.library") version "8.1.1" apply false
21+
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
2222
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Mar 09 16:31:19 PST 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)