Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feature_pull_to_refresh_gallery_screen_issue…
Browse files Browse the repository at this point in the history
…_866
  • Loading branch information
arriolac authored Dec 26, 2023
2 parents f387658 + 937fc80 commit a0dde22
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import androidx.paging.LoadState
import androidx.paging.PagingData
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemKey
import com.google.samples.apps.sunflower.R
import com.google.samples.apps.sunflower.compose.plantlist.PhotoListItem
import com.google.samples.apps.sunflower.data.UnsplashPhoto
Expand Down Expand Up @@ -90,7 +91,7 @@ private fun GalleryScreen(
val pullToRefreshState = rememberPullToRefreshState()

if (pullToRefreshState.isRefreshing) {
onPullToRefresh()
onPullToRefresh()
}

val pagingItems: LazyPagingItems<UnsplashPhoto> =
Expand Down Expand Up @@ -119,10 +120,7 @@ private fun GalleryScreen(
// See: https://issuetracker.google.com/issues/178087310
items(
count = pagingItems.itemCount,
key = { index ->
val photo = pagingItems[index]
"${photo?.id ?: ""}${index}"
}
key = pagingItems.itemKey { it }
) { index ->
val photo = pagingItems[index] ?: return@items
PhotoListItem(photo = photo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ enum class SunflowerPage(
fun HomeScreen(
modifier: Modifier = Modifier,
onPlantClick: (Plant) -> Unit = {},
viewModel: PlantListViewModel = hiltViewModel()
viewModel: PlantListViewModel = hiltViewModel(),
pages: Array<SunflowerPage> = SunflowerPage.values()
) {
val pages : Array<SunflowerPage> = SunflowerPage.values()
val pagerState = rememberPagerState(pageCount = {pages.count()})
val pagerState = rememberPagerState(pageCount = { pages.size })
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()

Scaffold(
Expand All @@ -89,8 +89,8 @@ fun HomeScreen(
HomePagerScreen(
onPlantClick = onPlantClick,
pagerState = pagerState,
Modifier.padding(top = contentPadding.calculateTopPadding()),
pages = pages
pages = pages,
Modifier.padding(top = contentPadding.calculateTopPadding())
)
}
}
Expand All @@ -100,6 +100,7 @@ fun HomeScreen(
fun HomePagerScreen(
onPlantClick: (Plant) -> Unit,
pagerState: PagerState,
pages: Array<SunflowerPage>,
modifier: Modifier = Modifier,
pages: Array<SunflowerPage>
) {
Expand Down Expand Up @@ -200,10 +201,11 @@ private fun HomeTopAppBar(
@Composable
private fun HomeScreenPreview() {
SunflowerTheme {
val pages = SunflowerPage.values()
HomePagerScreen(
onPlantClick = {},
pagerState = rememberPagerState(pageCount = {2}),
pages = SunflowerPage.values()
pagerState = rememberPagerState(pageCount = { pages.size }),
pages = pages
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fun PlantDetails(
hasValidUnsplashKey = hasValidUnsplashKey,
imageHeight = with(LocalDensity.current) {
val candidateHeight =
Dimens.PlantDetailAppBarHeight + toolbarOffsetHeightPx.value.toDp()
Dimens.PlantDetailAppBarHeight
// FIXME: Remove this workaround when https://github.com/bumptech/glide/issues/4952
// is released
maxOf(candidateHeight, 1.dp)
Expand Down
50 changes: 50 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2020 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Translated by Anselmo Alexandre -->
<string name="menu_filter_by_grow_zone">Filtrar por zona de cultivo</string>
<string name="my_garden_title">Meu jardim</string>
<string name="plant_list_title">Lista de plantas</string>
<string name="available">Plantas disponíveis</string>
<string name="plant_details_title">Detalhes da planta</string>
<string name="add_plant">Adicionar planta</string>
<string name="added_plant_to_garden">Adicionou planta ao jardim</string>
<string name="garden_empty">Seu jardim está vazio</string>
<string name="plant_date_header">Plantada</string>
<string name="watered_date_header">Regado pela última vez</string>
<string name="menu_item_share_plant">Partilhar</string>
<string name="share_text_plant">Confira o %s da planta na aplicação Sunflower</string>
<string name="gallery_title">Imagens tiradas do Unsplash</string>

<!-- String plurals and their related prefix / suffix strings -->
<string name="watering_needs_prefix">Necessidades de rega</string>
<plurals name="watering_needs_suffix">
<item quantity="one" tools:ignore="ImpliedQuantity">todos dias</item>
<item quantity="other">a cada %d dias</item>
</plurals>

<plurals name="watering_next">
<item quantity="one" tools:ignore="ImpliedQuantity">regar amanhã.</item>
<item quantity="other">regar dentro de %d dias.</item>
</plurals>

<!-- Accessibility -->
<string name="a11y_plant_item_image">Foto da planta</string>
<string name="gallery_content_description">Navegue para a tela da galeria</string>
<string name="plant_detail_image_content_description">Imagem da planta</string>
</resources>
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ androidGradlePlugin = "8.1.2"
benchmark = "1.1.0"
# @keep
compileSdk = "34"
composeLatest = "1.4.0-alpha03"
composeBom = "2023.06.01"
composeLatest = "1.6.0-beta03"
composeBom = "2023.10.01"
compose-compiler = "1.5.3"
constraintLayoutCompose = "1.0.1"
coreTesting = "2.2.0"
Expand All @@ -45,7 +45,7 @@ minSdk = "23"
monitor = "1.6.0"
navigation = "2.5.3"
okhttpLogging = "4.10.0"
pagingCompose = "1.0.0-alpha18"
pagingCompose = "1.0.0-alpha19"
profileInstaller = "1.2.0"
recyclerView = "1.3.0-alpha02"
retrofit = "2.9.0"
Expand Down

0 comments on commit a0dde22

Please sign in to comment.