From 0ee71113ed0ebea3ca12a4424a7d84fc37bf1cb2 Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Tue, 21 Nov 2023 10:16:56 -0800 Subject: [PATCH 1/2] Enable e2e. Change-Id: I777b0977dcdeda3101d412354cb14e1d8f41b634 --- app/src/main/AndroidManifest.xml | 1 + .../google/samples/apps/sunflower/GardenActivity.kt | 6 +++--- .../apps/sunflower/compose/gallery/GalleryScreen.kt | 3 +-- .../samples/apps/sunflower/compose/home/HomeScreen.kt | 11 ++++------- gradle/libs.versions.toml | 6 +++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c1b7d22a..5f36ddadf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,6 +31,7 @@ android:theme="@style/Theme.Sunflower"> diff --git a/app/src/main/java/com/google/samples/apps/sunflower/GardenActivity.kt b/app/src/main/java/com/google/samples/apps/sunflower/GardenActivity.kt index ef3acc269..92a2ed328 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/GardenActivity.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/GardenActivity.kt @@ -19,7 +19,7 @@ package com.google.samples.apps.sunflower import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.core.view.WindowCompat +import androidx.activity.enableEdgeToEdge import com.google.samples.apps.sunflower.compose.SunflowerApp import com.google.samples.apps.sunflower.ui.SunflowerTheme import dagger.hilt.android.AndroidEntryPoint @@ -31,7 +31,7 @@ class GardenActivity : ComponentActivity() { super.onCreate(savedInstanceState) // Displaying edge-to-edge - WindowCompat.setDecorFitsSystemWindows(window, false) + enableEdgeToEdge() setContent { SunflowerTheme { SunflowerApp() @@ -39,4 +39,4 @@ class GardenActivity : ComponentActivity() { } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt index e78bade63..eaf0c8c7c 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/gallery/GalleryScreen.kt @@ -62,7 +62,6 @@ fun GalleryScreen( ) } -@OptIn(ExperimentalMaterial3Api::class) @Composable private fun GalleryScreen( plantPictures: Flow>, @@ -150,4 +149,4 @@ private class GalleryScreenPreviewParamProvider : ) ), ) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/home/HomeScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/home/HomeScreen.kt index 5b274d74a..299c21467 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/home/HomeScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/home/HomeScreen.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.sunflower.compose.home +import android.util.Log import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.compose.foundation.ExperimentalFoundationApi @@ -26,7 +27,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.rememberPagerState @@ -85,11 +85,11 @@ fun HomeScreen( scrollBehavior = scrollBehavior ) } - ) { + ) { contentPadding -> HomePagerScreen( onPlantClick = onPlantClick, pagerState = pagerState, - modifier = Modifier.padding(it) + Modifier.padding(top = contentPadding.calculateTopPadding()) ) } } @@ -102,9 +102,6 @@ fun HomePagerScreen( modifier: Modifier = Modifier, pages: Array = SunflowerPage.values() ) { - // Use Modifier.nestedScroll + rememberNestedScrollInteropConnection() here so that this - // composable participates in the nested scroll hierarchy so that HomeScreen can be used in - // use cases like a collapsing toolbar Column(modifier) { val coroutineScope = rememberCoroutineScope() @@ -181,7 +178,7 @@ private fun HomeTopAppBar( ) } }, - modifier = modifier.statusBarsPadding(), + modifier = modifier, actions = { if (pagerState.currentPage == SunflowerPage.PLANT_LIST.ordinal) { IconButton(onClick = onFilterClick) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d22e1646c..05832e41d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,11 +15,11 @@ ## [versions] accessibilityTestFramework = "4.0.0" -activityCompose = "1.7.2" +activityCompose = "1.8.1" androidGradlePlugin = "8.1.2" benchmark = "1.1.0" # @keep -compileSdk = "33" +compileSdk = "34" composeLatest = "1.4.0-alpha03" composeBom = "2023.06.01" compose-compiler = "1.5.3" @@ -52,7 +52,7 @@ retrofit = "2.9.0" room = "2.5.2" runner = "1.0.1" # @keep -targetSdk = "33" +targetSdk = "34" testExtJunit = "1.1.5" uiAutomator = "2.2.0" viewModelCompose = "2.5.1" From fedc53908eeebdf7b2cbc1e6114762d151dd4c4f Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Tue, 21 Nov 2023 12:41:35 -0800 Subject: [PATCH 2/2] Add imePadding. Change-Id: I5180f86eb5aea9cee8ba19264488ca9e638b3d66 --- .../apps/sunflower/compose/garden/GardenScreen.kt | 6 ++++-- .../apps/sunflower/compose/plantlist/PlantListScreen.kt | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt index 4821712c6..376081fe3 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/garden/GardenScreen.kt @@ -23,6 +23,8 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid @@ -98,7 +100,7 @@ private fun GardenList( ReportDrawnWhen { gridState.layoutInfo.totalItemsCount > 0 } LazyVerticalGrid( columns = GridCells.Fixed(2), - modifier, + modifier.imePadding(), state = gridState, contentPadding = PaddingValues( horizontal = dimensionResource(id = R.dimen.card_side_margin), @@ -257,4 +259,4 @@ private class GardenScreenPreviewParamProvider : ) ) ) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListScreen.kt b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListScreen.kt index 586f24033..a364d8f56 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListScreen.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/compose/plantlist/PlantListScreen.kt @@ -17,6 +17,9 @@ package com.google.samples.apps.sunflower.compose.plantlist import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.consumeWindowInsets +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items @@ -37,6 +40,7 @@ import com.google.samples.apps.sunflower.data.Plant @Composable fun PlantListScreen( onPlantClick: (Plant) -> Unit, + modifier: Modifier = Modifier, viewModel: PlantListViewModel = hiltViewModel(), ) { @@ -52,7 +56,8 @@ fun PlantListScreen( ) { LazyVerticalGrid( columns = GridCells.Fixed(2), - modifier = modifier.testTag("plant_list"), + modifier = modifier.testTag("plant_list") + .imePadding(), contentPadding = PaddingValues( horizontal = dimensionResource(id = R.dimen.card_side_margin), vertical = dimensionResource(id = R.dimen.header_margin) @@ -88,4 +93,4 @@ private class PlantListPreviewParamProvider : PreviewParameterProvider