From 8e99bc1852f8bd5fcacf73b082532c23bd28cb86 Mon Sep 17 00:00:00 2001 From: mcarare Date: Tue, 30 Aug 2022 20:59:53 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/26444: Replace SectionHeader with HomeSectionHeader for home sections. --- .../fenix/compose/home/HomeSectionHeader.kt | 4 +-- .../home/pocket/PocketCategoriesViewHolder.kt | 11 ++----- .../home/pocket/PocketStoriesComposables.kt | 5 --- .../home/pocket/PocketStoriesViewHolder.kt | 32 +++++++------------ .../viewholders/CollectionHeaderViewHolder.kt | 12 ++----- 5 files changed, 19 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/compose/home/HomeSectionHeader.kt b/app/src/main/java/org/mozilla/fenix/compose/home/HomeSectionHeader.kt index 980103b034..db2361669d 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/home/HomeSectionHeader.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/home/HomeSectionHeader.kt @@ -40,7 +40,7 @@ import org.mozilla.fenix.wallpapers.Wallpaper @Composable fun HomeSectionHeader( headerText: String, - description: String, + description: String = "", onShowAllClick: (() -> Unit)? = null ) { if (inComposePreview) { @@ -80,7 +80,7 @@ fun HomeSectionHeader( @Composable private fun HomeSectionHeaderContent( headerText: String, - description: String, + description: String = "", showAllTextColor: Color = FirefoxTheme.colors.textAccent, onShowAllClick: (() -> Unit)? = null, ) { diff --git a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketCategoriesViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketCategoriesViewHolder.kt index af2a298b57..4a30f87800 100644 --- a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketCategoriesViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketCategoriesViewHolder.kt @@ -9,9 +9,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.res.stringResource @@ -23,7 +21,7 @@ import mozilla.components.lib.state.ext.observeAsComposableState import org.mozilla.fenix.R import org.mozilla.fenix.components.components import org.mozilla.fenix.compose.ComposeViewHolder -import org.mozilla.fenix.compose.SectionHeader +import org.mozilla.fenix.compose.home.HomeSectionHeader import org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.Theme @@ -82,11 +80,8 @@ private fun PocketTopics( onCategoryClick: (PocketRecommendedStoriesCategory) -> Unit ) { Column { - SectionHeader( - text = stringResource(R.string.pocket_stories_categories_header), - modifier = Modifier - .fillMaxWidth() - .wrapContentHeight(align = Alignment.Top) + HomeSectionHeader( + headerText = stringResource(R.string.pocket_stories_categories_header), ) Spacer(Modifier.height(16.dp)) diff --git a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt index db6480f2b5..96e06d2e8a 100644 --- a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt +++ b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesComposables.kt @@ -13,7 +13,6 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -48,7 +47,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -211,7 +209,6 @@ fun PocketSponsoredStory( @Composable fun PocketStories( @PreviewParameter(PocketStoryProvider::class) stories: List, - contentPadding: Dp, onStoryShown: (PocketStory, Pair) -> Unit, onStoryClicked: (PocketStory, Pair) -> Unit, onDiscoverMoreClicked: (String) -> Unit @@ -224,7 +221,6 @@ fun PocketStories( val flingBehavior = EagerFlingBehavior(lazyRowState = listState) LazyRow( - contentPadding = PaddingValues(horizontal = contentPadding), state = listState, flingBehavior = flingBehavior, horizontalArrangement = Arrangement.spacedBy(8.dp) @@ -441,7 +437,6 @@ private fun PocketStoriesComposablesPreview() { Column { PocketStories( stories = getFakePocketStories(8), - contentPadding = 0.dp, onStoryShown = { _, _ -> }, onStoryClicked = { _, _ -> }, onDiscoverMoreClicked = {} diff --git a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesViewHolder.kt index e57b81f95e..8fbb928a03 100644 --- a/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/pocket/PocketStoriesViewHolder.kt @@ -7,16 +7,12 @@ package org.mozilla.fenix.home.pocket import android.view.View import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -27,7 +23,7 @@ import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory import org.mozilla.fenix.R import org.mozilla.fenix.components.components import org.mozilla.fenix.compose.ComposeViewHolder -import org.mozilla.fenix.compose.SectionHeader +import org.mozilla.fenix.compose.home.HomeSectionHeader import org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.Theme @@ -44,14 +40,18 @@ class PocketStoriesViewHolder( private val interactor: PocketStoriesInteractor ) : ComposeViewHolder(composeView, viewLifecycleOwner) { + init { + val horizontalPadding = + composeView.resources.getDimensionPixelSize(R.dimen.home_item_horizontal_margin) + composeView.setPadding(horizontalPadding, 0, horizontalPadding, 0) + } + companion object { val LAYOUT_ID = View.generateViewId() } @Composable override fun Content() { - val horizontalPadding = dimensionResource(R.dimen.home_item_horizontal_margin) - val homeScreenReady = components.appStore .observeAsComposableState { state -> state.firstFrameDrawn }.value ?: false @@ -79,19 +79,14 @@ class PocketStoriesViewHolder( } Column(modifier = Modifier.padding(top = 72.dp)) { - SectionHeader( - text = stringResource(R.string.pocket_stories_header_1), - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = horizontalPadding) - .wrapContentHeight(align = Alignment.Top) + HomeSectionHeader( + headerText = stringResource(R.string.pocket_stories_header_1), ) Spacer(Modifier.height(16.dp)) PocketStories( stories ?: emptyList(), - horizontalPadding, interactor::onStoryShown, interactor::onStoryClicked, interactor::onDiscoverMoreClicked @@ -105,12 +100,8 @@ class PocketStoriesViewHolder( fun PocketStoriesViewHolderPreview() { FirefoxTheme(theme = Theme.getTheme()) { Column { - SectionHeader( - text = stringResource(R.string.pocket_stories_header_1), - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .wrapContentHeight(align = Alignment.Top) + HomeSectionHeader( + headerText = stringResource(R.string.pocket_stories_header_1), ) Spacer(Modifier.height(16.dp)) @@ -118,7 +109,6 @@ fun PocketStoriesViewHolderPreview() { @Suppress("MagicNumber") PocketStories( stories = getFakePocketStories(8), - contentPadding = 0.dp, onStoryShown = { _, _ -> }, onStoryClicked = { _, _ -> }, onDiscoverMoreClicked = {} diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/CollectionHeaderViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/CollectionHeaderViewHolder.kt index cdfef158c7..401d0a080d 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/CollectionHeaderViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/CollectionHeaderViewHolder.kt @@ -6,12 +6,9 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders import android.view.View import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.res.stringResource @@ -19,7 +16,7 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.LifecycleOwner import org.mozilla.fenix.R import org.mozilla.fenix.compose.ComposeViewHolder -import org.mozilla.fenix.compose.SectionHeader +import org.mozilla.fenix.compose.home.HomeSectionHeader /** * View holder for the "Collections" section header with the "Show all" button. @@ -43,11 +40,8 @@ class CollectionHeaderViewHolder( Column { Spacer(Modifier.height(56.dp)) - SectionHeader( - text = stringResource(R.string.collections_header), - modifier = Modifier - .fillMaxWidth() - .wrapContentHeight(align = Alignment.Top), + HomeSectionHeader( + headerText = stringResource(R.string.collections_header), ) Spacer(Modifier.height(10.dp))