This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #26750: add Wallpapers Onboarding dialog
- Loading branch information
mike a
committed
Sep 1, 2022
1 parent
ca0cfd7
commit fbc7e3c
Showing
12 changed files
with
289 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperOnboarding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.wallpapers | ||
|
||
import android.graphics.Bitmap | ||
import androidx.compose.foundation.clickable | ||
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.size | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Surface | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.settings.wallpaper.WallpaperThumbnails | ||
import org.mozilla.fenix.theme.FirefoxTheme | ||
import org.mozilla.fenix.theme.Theme | ||
|
||
/** | ||
* A view that shows content of a WallpaperOnboarding dialog. | ||
* | ||
* @param wallpapers Wallpapers to add to grid. | ||
* @param currentWallpaper The currently selected wallpaper. | ||
* @param onCloseClicked Callback for when the close button is clicked. | ||
* @param onButtonClicked Callback for when the bottom text button is clicked. | ||
* @param loadWallpaperResource Callback to handle loading a wallpaper bitmap. Only optional in the default case. | ||
* @param onSelectWallpaper Callback for when a new wallpaper is selected. | ||
*/ | ||
|
||
@Suppress("LongParameterList") | ||
@ExperimentalMaterialApi | ||
@Composable | ||
fun WallpaperOnboarding( | ||
wallpapers: List<Wallpaper>, | ||
currentWallpaper: Wallpaper, | ||
onCloseClicked: () -> Unit, | ||
onButtonClicked: () -> Unit, | ||
loadWallpaperResource: suspend (Wallpaper) -> Bitmap?, | ||
onSelectWallpaper: (Wallpaper) -> Unit, | ||
) { | ||
Surface( | ||
color = FirefoxTheme.colors.layer2, | ||
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp) | ||
) { | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.mozac_ic_close), | ||
contentDescription = stringResource(id = R.string.close_tab), | ||
tint = FirefoxTheme.colors.iconPrimary, | ||
modifier = Modifier | ||
.clickable { onCloseClicked() } | ||
.size(24.dp) | ||
.align(Alignment.End) | ||
) | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
Text( | ||
text = stringResource(R.string.wallpapers_onboarding_dialog_title_text), | ||
color = FirefoxTheme.colors.textPrimary, | ||
fontWeight = FontWeight.Bold, | ||
fontSize = 16.sp, | ||
overflow = TextOverflow.Ellipsis, | ||
maxLines = 1, | ||
) | ||
Spacer(modifier = Modifier.height(4.dp)) | ||
Text( | ||
text = stringResource(R.string.wallpapers_onboarding_dialog_body_text), | ||
color = FirefoxTheme.colors.textSecondary, | ||
fontSize = 12.sp, | ||
overflow = TextOverflow.Ellipsis, | ||
maxLines = 1, | ||
) | ||
WallpaperThumbnails( | ||
wallpapers = wallpapers, | ||
defaultWallpaper = Wallpaper.Default, | ||
loadWallpaperResource = { loadWallpaperResource(it) }, | ||
selectedWallpaper = currentWallpaper, | ||
onSelectWallpaper = { onSelectWallpaper(it) }, | ||
verticalPadding = 16, | ||
horizontalPadding = 0 | ||
) | ||
TextButton( | ||
modifier = Modifier | ||
.align(Alignment.CenterHorizontally) | ||
.fillMaxWidth(), | ||
onClick = { onButtonClicked() } | ||
) { | ||
Text( | ||
text = stringResource(R.string.wallpapers_onboarding_dialog_explore_more_button_text), | ||
fontWeight = FontWeight.Bold, | ||
color = FirefoxTheme.colors.textAccent, | ||
fontSize = 14.sp, | ||
overflow = TextOverflow.Ellipsis, | ||
maxLines = 1, | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(12.dp)) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@ExperimentalMaterialApi | ||
@Composable | ||
private fun WallpaperSnackbarPreview() { | ||
FirefoxTheme(theme = Theme.getTheme()) { | ||
WallpaperOnboarding( | ||
wallpapers = listOf(Wallpaper.Default), | ||
currentWallpaper = Wallpaper.Default, | ||
onCloseClicked = {}, | ||
onButtonClicked = {}, | ||
loadWallpaperResource = { null }, | ||
onSelectWallpaper = {} | ||
) | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperOnboardingDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.wallpapers | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.pm.ActivityInfo | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.platform.ViewCompositionStrategy | ||
import androidx.navigation.fragment.findNavController | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import kotlinx.coroutines.launch | ||
import mozilla.components.lib.state.ext.observeAsComposableState | ||
import org.mozilla.fenix.NavGraphDirections | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.ext.requireComponents | ||
import org.mozilla.fenix.ext.settings | ||
import org.mozilla.fenix.theme.FirefoxTheme | ||
|
||
/** | ||
* Dialog displaying the wallpapers onboarding. | ||
*/ | ||
@OptIn(ExperimentalMaterialApi::class) | ||
class WallpaperOnboardingDialogFragment : BottomSheetDialogFragment() { | ||
private val appStore by lazy { | ||
requireComponents.appStore | ||
} | ||
|
||
private val wallpaperUseCases by lazy { | ||
requireComponents.useCases.wallpaperUseCases | ||
} | ||
|
||
@SuppressLint("SourceLockedOrientationActivity") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NO_TITLE, R.style.WallpaperOnboardingDialogStyle) | ||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
requireContext().settings().showWallpaperOnboarding = false | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View = ComposeView(requireContext()).apply { | ||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) | ||
|
||
setContent { | ||
FirefoxTheme { | ||
val wallpapers = appStore.observeAsComposableState { state -> | ||
state.wallpaperState.availableWallpapers | ||
}.value ?: listOf() | ||
val currentWallpaper = appStore.observeAsComposableState { state -> | ||
state.wallpaperState.currentWallpaper | ||
}.value ?: Wallpaper.Default | ||
|
||
val coroutineScope = rememberCoroutineScope() | ||
|
||
WallpaperOnboarding( | ||
wallpapers = wallpapers, | ||
currentWallpaper = currentWallpaper, | ||
onCloseClicked = { dismiss() }, | ||
onButtonClicked = { | ||
val directions = NavGraphDirections.actionGlobalWallpaperSettingsFragment() | ||
findNavController().navigate(directions) | ||
}, | ||
loadWallpaperResource = { wallpaperUseCases.loadThumbnail(it) }, | ||
onSelectWallpaper = { | ||
coroutineScope.launch { wallpaperUseCases.selectWallpaper(it) } | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.