1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.wallpapers
7 import android.graphics.Bitmap
8 import androidx.compose.foundation.clickable
9 import androidx.compose.foundation.layout.Column
10 import androidx.compose.foundation.layout.Spacer
11 import androidx.compose.foundation.layout.fillMaxWidth
12 import androidx.compose.foundation.layout.height
13 import androidx.compose.foundation.layout.padding
14 import androidx.compose.foundation.layout.size
15 import androidx.compose.foundation.shape.RoundedCornerShape
16 import androidx.compose.material.ExperimentalMaterialApi
17 import androidx.compose.material.Icon
18 import androidx.compose.material.Surface
19 import androidx.compose.material.Text
20 import androidx.compose.material.TextButton
21 import androidx.compose.runtime.Composable
22 import androidx.compose.ui.Alignment
23 import androidx.compose.ui.Modifier
24 import androidx.compose.ui.res.painterResource
25 import androidx.compose.ui.res.stringResource
26 import androidx.compose.ui.text.style.TextOverflow
27 import androidx.compose.ui.tooling.preview.Preview
28 import androidx.compose.ui.unit.dp
29 import org.mozilla.fenix.R
30 import org.mozilla.fenix.settings.wallpaper.WallpaperThumbnails
31 import org.mozilla.fenix.theme.FirefoxTheme
34 * A view that shows content of a WallpaperOnboarding dialog.
36 * @param wallpapers Wallpapers to add to grid.
37 * @param currentWallpaper The currently selected wallpaper.
38 * @param loadWallpaperResource Callback to handle loading a wallpaper bitmap. Only optional in the default case.
39 * @param onCloseClicked Callback for when the close button is clicked.
40 * @param onExploreMoreButtonClicked Callback for when the bottom text button is clicked.
41 * @param onSelectWallpaper Callback for when a new wallpaper is selected.
44 @Suppress("LongParameterList")
45 @ExperimentalMaterialApi
47 fun WallpaperOnboarding(
48 wallpapers: List<Wallpaper>,
49 currentWallpaper: Wallpaper,
50 loadWallpaperResource: suspend (Wallpaper) -> Bitmap?,
51 onCloseClicked: () -> Unit,
52 onExploreMoreButtonClicked: () -> Unit,
53 onSelectWallpaper: (Wallpaper) -> Unit,
56 color = FirefoxTheme.colors.layer2,
57 shape = RoundedCornerShape(topStart = 8.dp, topEnd = 8.dp),
60 modifier = Modifier.padding(horizontal = 32.dp, vertical = 16.dp),
61 horizontalAlignment = Alignment.CenterHorizontally,
64 painter = painterResource(id = R.drawable.mozac_ic_cross_24),
65 contentDescription = stringResource(id = R.string.close_tab),
66 tint = FirefoxTheme.colors.iconPrimary,
68 .clickable { onCloseClicked() }
70 .align(Alignment.End),
73 Spacer(modifier = Modifier.height(8.dp))
76 text = stringResource(R.string.wallpapers_onboarding_dialog_title_text),
77 color = FirefoxTheme.colors.textPrimary,
78 overflow = TextOverflow.Ellipsis,
80 style = FirefoxTheme.typography.headline7,
83 Spacer(modifier = Modifier.height(4.dp))
86 text = stringResource(R.string.wallpapers_onboarding_dialog_body_text),
87 color = FirefoxTheme.colors.textSecondary,
88 overflow = TextOverflow.Ellipsis,
90 style = FirefoxTheme.typography.caption,
93 Spacer(modifier = Modifier.height(16.dp))
96 wallpapers = wallpapers,
97 defaultWallpaper = Wallpaper.Default,
98 selectedWallpaper = currentWallpaper,
99 loadWallpaperResource = { loadWallpaperResource(it) },
100 onSelectWallpaper = { onSelectWallpaper(it) },
103 Spacer(modifier = Modifier.height(16.dp))
107 .align(Alignment.CenterHorizontally)
109 onClick = { onExploreMoreButtonClicked() },
112 text = stringResource(R.string.wallpapers_onboarding_dialog_explore_more_button_text),
113 color = FirefoxTheme.colors.textAccent,
114 overflow = TextOverflow.Ellipsis,
116 style = FirefoxTheme.typography.button,
124 @ExperimentalMaterialApi
126 private fun WallpaperSnackbarPreview() {
129 wallpapers = listOf(Wallpaper.Default),
130 currentWallpaper = Wallpaper.Default,
132 onExploreMoreButtonClicked = {},
133 loadWallpaperResource = { null },
134 onSelectWallpaper = {},