Skip to content

Commit

Permalink
Merge pull request #11 from google-developer-training/main-e2e
Browse files Browse the repository at this point in the history
Main branch Edge to Edge implementation
  • Loading branch information
the-scrambler authored Aug 29, 2023
2 parents aaf2cc5 + d555366 commit 4791a0a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
11 changes: 5 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ plugins {

android {
namespace = "com.example.lunchtray"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "com.example.lunchtray"
minSdk = 24
targetSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand All @@ -50,13 +50,12 @@ android {
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.7"
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
Expand All @@ -67,15 +66,15 @@ android {

dependencies {

implementation(platform("androidx.compose:compose-bom:2023.05.01"))
implementation(platform("androidx.compose:compose-bom:2023.08.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.navigation:navigation-compose:2.5.3")
implementation("androidx.navigation:navigation-compose:2.7.0")

debugImplementation("androidx.compose.ui:ui-test-manifest")
debugImplementation("androidx.compose.ui:ui-tooling")
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/com/example/lunchtray/LunchTrayScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
Expand Down Expand Up @@ -57,6 +58,7 @@ enum class LunchTrayScreen(@StringRes val title: Int) {
/**
* Composable that displays the topBar and displays back button if back navigation is possible.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LunchTrayAppBar(
@StringRes currentScreenTitle: Int,
Expand Down Expand Up @@ -107,16 +109,15 @@ fun LunchTrayApp() {
NavHost(
navController = navController,
startDestination = LunchTrayScreen.Start.name,
modifier = Modifier.padding(innerPadding),
) {
composable(route = LunchTrayScreen.Start.name) {
StartOrderScreen(
onStartOrderButtonClicked = {
navController.navigate(LunchTrayScreen.Entree.name)
},
modifier = Modifier
.padding(dimensionResource(R.dimen.padding_medium))
.fillMaxSize()
.padding(innerPadding)
)
}

Expand All @@ -134,8 +135,8 @@ fun LunchTrayApp() {
viewModel.updateEntree(item)
},
modifier = Modifier
.padding(dimensionResource(R.dimen.padding_medium))
.verticalScroll(rememberScrollState())
.padding(innerPadding)
)
}

Expand All @@ -153,8 +154,8 @@ fun LunchTrayApp() {
viewModel.updateSideDish(item)
},
modifier = Modifier
.padding(dimensionResource(R.dimen.padding_medium))
.verticalScroll(rememberScrollState())
.padding(innerPadding)
)
}

Expand All @@ -172,8 +173,8 @@ fun LunchTrayApp() {
viewModel.updateAccompaniment(item)
},
modifier = Modifier
.padding(dimensionResource(R.dimen.padding_medium))
.verticalScroll(rememberScrollState())
.padding(innerPadding)
)
}

Expand All @@ -189,8 +190,13 @@ fun LunchTrayApp() {
navController.popBackStack(LunchTrayScreen.Start.name, inclusive = false)
},
modifier = Modifier
.padding(dimensionResource(R.dimen.padding_medium))
.verticalScroll(rememberScrollState())
.padding(
top = innerPadding.calculateTopPadding(),
bottom = innerPadding.calculateBottomPadding(),
start = dimensionResource(R.dimen.padding_medium),
end = dimensionResource(R.dimen.padding_medium),
)
)
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/example/lunchtray/ui/BaseMenuScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ fun BaseMenuScreen(
selected = selectedItemName == item.name,
onClick = onClick
)
.padding(
start = dimensionResource(R.dimen.padding_medium),
end = dimensionResource(R.dimen.padding_medium),
)
)
}

Expand Down
26 changes: 23 additions & 3 deletions app/src/main/java/com/example/lunchtray/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.example.lunchtray.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
Expand All @@ -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
Expand Down Expand Up @@ -113,9 +115,7 @@ fun LunchTrayTheme(
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
setUpEdgeToEdge(view, darkTheme)
}
}

Expand All @@ -125,3 +125,23 @@ fun LunchTrayTheme(
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
}
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.0" apply false
id("com.android.library") version "8.1.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 27 22:40:22 PDT 2023
#Mon Aug 14 19:44:23 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

0 comments on commit 4791a0a

Please sign in to comment.