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

Commit

Permalink
Closes #26212: Download wallpapers when a thumbnail is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
mike a committed Aug 29, 2022
1 parent f89203b commit 50f2007
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ internal object AppStoreReducer {
)
is AppAction.WallpaperAction.UpdateWallpaperDownloadState -> {
val wallpapers = state.wallpaperState.availableWallpapers.map {
if (it == action.wallpaper) {
if (it.name == action.wallpaper.name) {
it.copy(assetsFileState = action.imageState)
} else {
it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Scaffold
import androidx.compose.material.Snackbar
import androidx.compose.material.SnackbarDuration
Expand All @@ -36,6 +38,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
Expand Down Expand Up @@ -165,14 +168,16 @@ private fun WallpaperThumbnails(
for (columnIndex in 0 until numColumns) {
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 = wallpapers[itemIndex],
wallpaper = wallpaper,
defaultWallpaper = defaultWallpaper,
loadWallpaperResource = loadWallpaperResource,
isSelected = selectedWallpaper == wallpapers[itemIndex],
isSelected = selectedWallpaper.name == wallpaper.name,
isLoading = wallpaper.assetsFileState == Wallpaper.ImageFileState.Downloading,
onSelect = onSelectWallpaper
)
}
Expand Down Expand Up @@ -201,7 +206,9 @@ private fun WallpaperThumbnailItem(
defaultWallpaper: Wallpaper,
loadWallpaperResource: suspend (Wallpaper) -> Bitmap?,
isSelected: Boolean,
isLoading: Boolean,
aspectRatio: Float = 1.1f,
loadingOpacity: Float = 0.5f,
onSelect: (Wallpaper) -> Unit
) {
var bitmap: Bitmap? by remember { mutableStateOf(null) }
Expand All @@ -211,7 +218,12 @@ private fun WallpaperThumbnailItem(
val thumbnailShape = RoundedCornerShape(8.dp)
val border = if (isSelected) {
Modifier.border(
BorderStroke(width = 2.dp, color = FirefoxTheme.colors.borderAccent),
BorderStroke(width = 3.dp, color = FirefoxTheme.colors.borderAccent),
thumbnailShape
)
} else if (wallpaper.name == Wallpaper.defaultName) {
Modifier.border(
BorderStroke(width = 1.dp, color = FirefoxTheme.colors.borderPrimary),
thumbnailShape
)
} else {
Expand Down Expand Up @@ -239,8 +251,20 @@ private fun WallpaperThumbnailItem(
R.string.wallpapers_item_name_content_description, wallpaper.name
),
modifier = Modifier.fillMaxSize(),
alpha = if (isLoading) loadingOpacity else 1.0f
)
}
if (isLoading) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(24.dp)
) {
CircularProgressIndicator(
color = FirefoxTheme.colors.borderAccent
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WallpaperSettingsFragment : Fragment() {
state.wallpaperState.currentWallpaper
}.value ?: Wallpaper.Default

var coroutineScope = rememberCoroutineScope()
val coroutineScope = rememberCoroutineScope()

WallpaperSettings(
wallpapers = wallpapers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ class WallpapersUseCases(
* @param wallpaper The selected wallpaper.
*/
override suspend fun invoke(wallpaper: Wallpaper) {
if (fileManager.wallpaperImagesExist(wallpaper)) {
if (wallpaper.name == Wallpaper.defaultName ||
fileManager.wallpaperImagesExist(wallpaper)
) {
selectWallpaper(wallpaper)
dispatchDownloadState(wallpaper, Wallpaper.ImageFileState.Downloaded)
} else {
Expand Down

0 comments on commit 50f2007

Please sign in to comment.