Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Closes #26212: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mike a committed Sep 9, 2022
1 parent 0a86eb6 commit d5e593e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
22 changes: 20 additions & 2 deletions app/src/main/java/org/mozilla/fenix/home/WallpapersObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.lib.state.Store
import org.mozilla.fenix.R
import org.mozilla.fenix.addons.showSnackBar
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.appstate.AppState
Expand Down Expand Up @@ -67,6 +69,12 @@ class WallpapersObserver(
@VisibleForTesting
internal var currentWallpaperImage: Bitmap? = null

/**
* A parameter that helps on the stage of applying to tell if the loading of the file from the
* storage was successful or error snackbar should be displayed.
*/
var lastObservedValue: Wallpaper? = null

/**
* Listener for when the first observed wallpaper is loaded and available to be set.
*/
Expand All @@ -88,7 +96,18 @@ class WallpapersObserver(
withContext(Dispatchers.Main.immediate) {
with(currentWallpaperImage) {
when (this) {
null -> wallpaperImageView.isVisible = false
null -> {
wallpaperImageView.isVisible = false

if (lastObservedValue != Wallpaper.Default) {
with(wallpaperImageView) {
showSnackBar(
view = this,
text = resources.getString(R.string.wallpaper_select_error_snackbar_message),
)
}
}
}
else -> {
scaleToBottomOfView(wallpaperImageView)
wallpaperImageView.isVisible = true
Expand All @@ -105,7 +124,6 @@ class WallpapersObserver(

@VisibleForTesting
internal fun observeWallpaperUpdates() {
var lastObservedValue: Wallpaper? = null
observeWallpapersStoreSubscription = appStore.observeManually { state ->
val currentValue = state.wallpaperState.currentWallpaper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun WallpaperSettings(
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.background(color = FirefoxTheme.colors.layer1)
.background(color = FirefoxTheme.colors.layer1),
) {
WallpaperThumbnails(
wallpapers = wallpapers,
Expand Down Expand Up @@ -107,16 +107,16 @@ private fun WallpaperThumbnails(
val itemIndex = rowIndex * numColumns + columnIndex
if (itemIndex < wallpapers.size) {
val wallpaper = wallpapers[itemIndex]
Box(
modifier = Modifier.weight(1f, fill = true).padding(4.dp),
) {
WallpaperThumbnailItem(
wallpaper = wallpaper,
defaultWallpaper = defaultWallpaper,
loadWallpaperResource = loadWallpaperResource,
isSelected = selectedWallpaper.name == wallpaper.name,
isLoading = wallpaper.assetsFileState == Wallpaper.ImageFileState.Downloading,
onSelect = onSelectWallpaper,
Box(
modifier = Modifier.weight(1f, fill = true).padding(4.dp),
) {
WallpaperThumbnailItem(
wallpaper = wallpaper,
defaultWallpaper = defaultWallpaper,
loadWallpaperResource = loadWallpaperResource,
isSelected = selectedWallpaper.name == wallpaper.name,
isLoading = wallpaper.assetsFileState == Wallpaper.ImageFileState.Downloading,
onSelect = onSelectWallpaper,
)
}
} else {
Expand Down Expand Up @@ -189,17 +189,17 @@ private fun WallpaperThumbnailItem(
wallpaper.name,
),
modifier = Modifier.fillMaxSize(),
alpha = if (isLoading) loadingOpacity else 1.0f
alpha = if (isLoading) loadingOpacity else 1.0f,
)
}
if (isLoading) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(24.dp)
.size(24.dp),
) {
CircularProgressIndicator(
color = FirefoxTheme.colors.borderAccent
color = FirefoxTheme.colors.borderAccent,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class WallpaperSettingsFragment : Fragment() {
private fun onWallpaperSelected(
wallpaper: Wallpaper,
result: Wallpaper.ImageFileState,
view: View
view: View,
) {
when (result) {
Wallpaper.ImageFileState.Downloaded -> {
FenixSnackbar.make(
view = view,
isDisplayedWithBrowserToolbar = false
isDisplayedWithBrowserToolbar = false,
)
.setText(view.context.getString(R.string.wallpaper_updated_snackbar_message))
.setAction(requireContext().getString(R.string.wallpaper_updated_snackbar_action)) {
Expand All @@ -92,7 +92,7 @@ class WallpaperSettingsFragment : Fragment() {
Wallpaper.ImageFileState.Error -> {
FenixSnackbar.make(
view = view,
isDisplayedWithBrowserToolbar = false
isDisplayedWithBrowserToolbar = false,
)
.setText(view.context.getString(R.string.wallpaper_download_error_snackbar_message))
.setAction(view.context.getString(R.string.wallpaper_download_error_snackbar_action)) {
Expand Down

0 comments on commit d5e593e

Please sign in to comment.