From 40155f35579ef13bceeffb131b64ea103599a875 Mon Sep 17 00:00:00 2001 From: Alexandru2909 Date: Tue, 2 Aug 2022 15:01:39 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/26115 - Change homescreen Show all button color according to wallpaper --- .../fenix/compose/home/HomeSectionHeader.kt | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 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 bc18351f96..a500006bf1 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 @@ -4,14 +4,15 @@ package org.mozilla.fenix.compose.home -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.text.ClickableText import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics @@ -20,10 +21,14 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import mozilla.components.lib.state.ext.observeAsComposableState import org.mozilla.fenix.R +import org.mozilla.fenix.components.components import org.mozilla.fenix.compose.SectionHeader +import org.mozilla.fenix.compose.inComposePreview import org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.Theme +import org.mozilla.fenix.wallpapers.Wallpaper /** * Homepage header. @@ -37,6 +42,47 @@ fun HomeSectionHeader( headerText: String, description: String, onShowAllClick: () -> Unit +) { + if (inComposePreview) { + HomeSectionHeaderContent( + headerText = headerText, + description = description, + onShowAllClick = onShowAllClick + ) + } else { + val wallpaperState = components.appStore + .observeAsComposableState { state -> state.wallpaperState }.value + + val isWallpaperDefault = + (wallpaperState?.currentWallpaper ?: Wallpaper.Default) == Wallpaper.Default + + HomeSectionHeaderContent( + headerText = headerText, + description = description, + showAllTextColor = if (isWallpaperDefault) { + FirefoxTheme.colors.textAccent + } else { + FirefoxTheme.colors.textPrimary + }, + onShowAllClick = onShowAllClick, + ) + } +} + +/** + * Homepage header content. + * + * @param headerText The header string. + * @param description The description for click action + * @param showAllTextColor [Color] for the "Show all" button. + * @param onShowAllClick Invoked when "Show all" button is clicked. + */ +@Composable +private fun HomeSectionHeaderContent( + headerText: String, + description: String, + showAllTextColor: Color = FirefoxTheme.colors.textAccent, + onShowAllClick: () -> Unit, ) { Row( modifier = Modifier.fillMaxWidth(), @@ -55,7 +101,7 @@ fun HomeSectionHeader( contentDescription = description }, style = TextStyle( - color = FirefoxTheme.colors.textAccent, + color = showAllTextColor, fontSize = 14.sp ), onClick = { onShowAllClick() }