|
|
|
@ -4,6 +4,7 @@
|
|
|
|
|
|
|
|
|
|
package org.mozilla.fenix.home.pocket
|
|
|
|
|
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
import android.view.View
|
|
|
|
|
import androidx.compose.foundation.isSystemInDarkTheme
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
@ -12,7 +13,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.platform.ComposeView
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
@ -25,7 +25,6 @@ import org.mozilla.fenix.components.components
|
|
|
|
|
import org.mozilla.fenix.compose.ComposeViewHolder
|
|
|
|
|
import org.mozilla.fenix.compose.home.HomeSectionHeader
|
|
|
|
|
import org.mozilla.fenix.theme.FirefoxTheme
|
|
|
|
|
import org.mozilla.fenix.theme.Theme
|
|
|
|
|
import org.mozilla.fenix.wallpapers.WallpaperState
|
|
|
|
|
|
|
|
|
|
internal const val POCKET_CATEGORIES_SELECTED_AT_A_TIME_COUNT = 8
|
|
|
|
@ -61,10 +60,8 @@ class PocketCategoriesViewHolder(
|
|
|
|
|
val wallpaperState = components.appStore
|
|
|
|
|
.observeAsComposableState { state -> state.wallpaperState }.value ?: WallpaperState.default
|
|
|
|
|
|
|
|
|
|
var selectedBackgroundColor: Color? = null
|
|
|
|
|
var unselectedBackgroundColor: Color? = null
|
|
|
|
|
var selectedTextColor: Color? = null
|
|
|
|
|
var unselectedTextColor: Color? = null
|
|
|
|
|
var (selectedBackgroundColor, unselectedBackgroundColor, selectedTextColor, unselectedTextColor) =
|
|
|
|
|
PocketStoriesCategoryColors.buildColors()
|
|
|
|
|
wallpaperState.composeRunIfWallpaperCardColorsAreAvailable { cardColorLight, cardColorDark ->
|
|
|
|
|
if (isSystemInDarkTheme()) {
|
|
|
|
|
selectedBackgroundColor = cardColorDark
|
|
|
|
@ -79,16 +76,20 @@ class PocketCategoriesViewHolder(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val categoryColors = PocketStoriesCategoryColors(
|
|
|
|
|
selectedTextColor = selectedTextColor,
|
|
|
|
|
unselectedTextColor = unselectedTextColor,
|
|
|
|
|
selectedBackgroundColor = selectedBackgroundColor,
|
|
|
|
|
unselectedBackgroundColor = unselectedBackgroundColor,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// See the detailed comment in PocketStoriesViewHolder for reasoning behind this change.
|
|
|
|
|
if (!homeScreenReady) return
|
|
|
|
|
Column {
|
|
|
|
|
Spacer(Modifier.height(24.dp))
|
|
|
|
|
|
|
|
|
|
PocketTopics(
|
|
|
|
|
selectedBackgroundColor = selectedBackgroundColor,
|
|
|
|
|
unselectedBackgroundColor = unselectedBackgroundColor,
|
|
|
|
|
selectedTextColor = selectedTextColor,
|
|
|
|
|
unselectedTextColor = unselectedTextColor,
|
|
|
|
|
categoryColors = categoryColors,
|
|
|
|
|
categories = categories ?: emptyList(),
|
|
|
|
|
categoriesSelections = categoriesSelections ?: emptyList(),
|
|
|
|
|
onCategoryClick = interactor::onCategoryClicked,
|
|
|
|
@ -103,12 +104,9 @@ class PocketCategoriesViewHolder(
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
private fun PocketTopics(
|
|
|
|
|
selectedTextColor: Color? = null,
|
|
|
|
|
unselectedTextColor: Color? = null,
|
|
|
|
|
selectedBackgroundColor: Color? = null,
|
|
|
|
|
unselectedBackgroundColor: Color? = null,
|
|
|
|
|
categories: List<PocketRecommendedStoriesCategory> = emptyList(),
|
|
|
|
|
categoriesSelections: List<PocketRecommendedStoriesSelectedCategory> = emptyList(),
|
|
|
|
|
categoryColors: PocketStoriesCategoryColors = PocketStoriesCategoryColors.buildColors(),
|
|
|
|
|
onCategoryClick: (PocketRecommendedStoriesCategory) -> Unit,
|
|
|
|
|
) {
|
|
|
|
|
Column {
|
|
|
|
@ -121,21 +119,18 @@ private fun PocketTopics(
|
|
|
|
|
PocketStoriesCategories(
|
|
|
|
|
categories = categories,
|
|
|
|
|
selections = categoriesSelections,
|
|
|
|
|
selectedTextColor = selectedTextColor,
|
|
|
|
|
unselectedTextColor = unselectedTextColor,
|
|
|
|
|
selectedBackgroundColor = selectedBackgroundColor,
|
|
|
|
|
unselectedBackgroundColor = unselectedBackgroundColor,
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
categoryColors = categoryColors,
|
|
|
|
|
onCategoryClick = onCategoryClick,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
@Preview
|
|
|
|
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
|
|
|
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
|
|
|
|
private fun PocketCategoriesViewHolderPreview() {
|
|
|
|
|
FirefoxTheme(theme = Theme.getTheme()) {
|
|
|
|
|
FirefoxTheme {
|
|
|
|
|
PocketTopics(
|
|
|
|
|
categories = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
|
|
|
|
|
.split(" ")
|
|
|
|
|