Hoisted settings state up to PaperizeApp.kt for WallpaperScreen.kt
Fixed disabling animation for WallpaperScreen.kt Updated color for AlbumBottomSheet Rounded corners for snackbars
This commit is contained in:
1 parent
41b32f3154
commit
379d6b21be
12 files changed
+417
-239
No files matched your search
+10
-1
@@ -204,12 +204,21 @@ fun PaperizeApp(
|
||||
context.startForegroundService(intent)
|
||||
},
|
||||
onStop = {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
animate = settingsState.value.animate,
|
||||
interval = settingsState.value.interval,
|
||||
setLockWithHome = settingsState.value.setLockWithHome,
|
||||
lastSetTime = settingsState.value.lastSetTime,
|
||||
nextSetTime = settingsState.value.nextSetTime,
|
||||
onSetLockWithHome = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(it))
|
||||
},
|
||||
selectedAlbum = selectedState.value.selectedAlbum
|
||||
)
|
||||
}
|
||||
// Navigate to the add album screen to create a new album and add wallpapers to it
|
||||
|
||||
+39
-22
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -21,6 +22,7 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
@@ -37,6 +39,19 @@ fun AlbumItem(
|
||||
modifier: Modifier = Modifier,
|
||||
animate: Boolean = true
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showCoverUri = album.coverUri != null && isValidUri(LocalContext.current, album.coverUri)
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
modifier = modifier
|
||||
@@ -50,29 +65,31 @@ fun AlbumItem(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
GlideImage(
|
||||
imageModel = { album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.padding(6.dp))
|
||||
|
||||
+16
-2
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -74,6 +75,19 @@ fun FolderItem(
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showCoverUri = folder.coverUri != null && isValidUri(LocalContext.current, folder.coverUri)
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
modifier = modifier
|
||||
@@ -100,9 +114,9 @@ fun FolderItem(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
if (folder.coverUri != null) {
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { folder.coverUri.toUri() },
|
||||
imageModel = { folder.coverUri?.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
|
||||
+37
-27
@@ -37,7 +37,7 @@ import androidx.core.net.toUri
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.R
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions.withCrossFade
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -70,9 +70,18 @@ fun WallpaperItem(
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
val dimension = wallpaperDrawable?.let { Pair(it.width, it.height) } ?: wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: (dimension.first.toFloat() / dimension.second.toFloat())
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showUri = isValidUri(LocalContext.current, wallpaperUri)
|
||||
val boxModifier = if (clickable) {
|
||||
modifier
|
||||
.padding(paddingTransition)
|
||||
@@ -95,31 +104,32 @@ fun WallpaperItem(
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = boxModifier
|
||||
) {
|
||||
GlideImage(
|
||||
imageModel = { wallpaperDrawable ?: wallpaperUri.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
Box(modifier = boxModifier) {
|
||||
if (showUri) {
|
||||
val dimension = wallpaperDrawable?.let { Pair(it.width, it.height) } ?: wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: (dimension.first.toFloat() / dimension.second.toFloat())
|
||||
GlideImage(
|
||||
imageModel = { wallpaperDrawable ?: wallpaperUri.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.aspectRatio(imageAspectRatio)
|
||||
)
|
||||
},
|
||||
modifier = Modifier.aspectRatio(imageAspectRatio)
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (itemSelected) {
|
||||
|
||||
+16
-2
@@ -22,6 +22,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
@@ -34,8 +35,14 @@ fun HomeScreen(
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onSetLockWithHome: (Boolean) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate : Boolean
|
||||
animate : Boolean,
|
||||
interval: Int,
|
||||
setLockWithHome: Boolean,
|
||||
lastSetTime: String?,
|
||||
nextSetTime: String?,
|
||||
selectedAlbum: SelectedAlbum?
|
||||
) {
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val pagerState = rememberPagerState { tabItems.size }
|
||||
@@ -103,7 +110,14 @@ fun HomeScreen(
|
||||
when(index) {
|
||||
0 -> WallpaperScreen(
|
||||
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
|
||||
onStop = onStop
|
||||
onStop = onStop,
|
||||
animate = animate,
|
||||
interval = interval,
|
||||
setLockWithHome = setLockWithHome,
|
||||
lastSetTime = lastSetTime,
|
||||
nextSetTime = nextSetTime,
|
||||
onSetLockWithHome = { onSetLockWithHome(it) },
|
||||
selectedAlbum = selectedAlbum
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
|
||||
+3
-1
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
@@ -68,7 +69,8 @@ fun SettingsScrollableSettings(
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp))
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
|
||||
+3
-1
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material.icons.sharp.CheckCircleOutline
|
||||
@@ -65,7 +66,8 @@ fun StartupScreen(
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp))
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
|
||||
+70
-65
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
@@ -42,11 +43,16 @@ fun WallpaperScreen(
|
||||
wallpaperScreenViewModel: WallpaperScreenViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onStop: () -> Unit
|
||||
onSetLockWithHome: (Boolean) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate: Boolean,
|
||||
interval: Int,
|
||||
setLockWithHome: Boolean,
|
||||
lastSetTime: String?,
|
||||
nextSetTime: String?,
|
||||
selectedAlbum: SelectedAlbum?
|
||||
) {
|
||||
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
@@ -58,12 +64,13 @@ fun WallpaperScreen(
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp))
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { it
|
||||
content = { padding ->
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@@ -72,17 +79,16 @@ fun WallpaperScreen(
|
||||
) {
|
||||
item {
|
||||
CurrentSelectedAlbum(
|
||||
selectedAlbum = selectedState.value.selectedAlbum,
|
||||
selectedAlbum = selectedAlbum,
|
||||
onOpenBottomSheet = {
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) openBottomSheet = true
|
||||
},
|
||||
onStop = {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
if (selectedAlbum != null) {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "${selectedState.value.selectedAlbum?.album?.displayedAlbumName} has been unselected.",
|
||||
message = "${selectedAlbum.album.displayedAlbumName} has been unselected.",
|
||||
actionLabel = "Dismiss",
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
@@ -90,46 +96,64 @@ fun WallpaperScreen(
|
||||
onStop()
|
||||
}
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
if (settingsState.value.animate) {
|
||||
item {
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedState.value.selectedAlbum != null,
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
CurrentAndNextChange(
|
||||
settingsState.value.lastSetTime,
|
||||
settingsState.value.nextSetTime
|
||||
)
|
||||
if (selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedState.value.selectedAlbum != null,
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
if (selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedState.value.selectedAlbum!!.album.coverUri,
|
||||
checked = settingsState.value.setLockWithHome,
|
||||
onCheckedChange = { isChecked ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(isChecked))
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
albumUri = selectedAlbum.album.coverUri,
|
||||
checked = setLockWithHome,
|
||||
onCheckedChange = { onSetLockWithHome(it) },
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedAlbum.album.coverUri,
|
||||
checked = setLockWithHome,
|
||||
onCheckedChange = { onSetLockWithHome(it) },
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedState.value.selectedAlbum != null,
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
TimeSliders(
|
||||
timeInMinutes = settingsState.value.interval,
|
||||
timeInMinutes = interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
@@ -140,62 +164,44 @@ fun WallpaperScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
CurrentAndNextChange(
|
||||
settingsState.value.lastSetTime,
|
||||
settingsState.value.nextSetTime
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
TimeSliders(
|
||||
timeInMinutes = interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetWallpaperInterval(totalMinutes)
|
||||
)
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedState.value.selectedAlbum!!.album.coverUri,
|
||||
checked = settingsState.value.setLockWithHome,
|
||||
onCheckedChange = { isChecked ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(isChecked))
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
}
|
||||
}
|
||||
item {
|
||||
TimeSliders(
|
||||
timeInMinutes = settingsState.value.interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetWallpaperInterval(totalMinutes)
|
||||
)
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (openBottomSheet) {
|
||||
AlbumBottomSheet(
|
||||
albums = albumState.value.albumsWithWallpapers,
|
||||
currentSelectedAlbum = selectedState.value.selectedAlbum,
|
||||
currentSelectedAlbum = selectedAlbum,
|
||||
onDismiss = { openBottomSheet = false },
|
||||
onSelect = { album ->
|
||||
val wallpapers: List<Wallpaper> = album.wallpapers + album.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
val wallpapers: List<Wallpaper> = album.wallpapers + album.folders.asSequence().flatMap { folder ->
|
||||
folder.wallpapers.asSequence().map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = album.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}.toList()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = album.album.copy(
|
||||
wallpapersInQueue = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
|
||||
openBottomSheet = false
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
@@ -205,10 +211,9 @@ fun WallpaperScreen(
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
|
||||
onScheduleWallpaperChanger(settingsState.value.interval)
|
||||
onScheduleWallpaperChanger(interval)
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
+43
-25
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
@@ -28,6 +29,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
@@ -49,12 +51,25 @@ fun AlbumBottomSheet(
|
||||
onSelect: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val modalBottomSheetState = rememberModalBottomSheetState()
|
||||
val scope = rememberCoroutineScope()
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = { onDismiss() },
|
||||
sheetState = modalBottomSheetState,
|
||||
dragHandle = { BottomSheetDefaults.DragHandle() },
|
||||
containerColor = MaterialTheme.colorScheme.background,
|
||||
tonalElevation = 5.dp
|
||||
) {
|
||||
albums.forEach {
|
||||
ListItem(
|
||||
@@ -83,33 +98,36 @@ fun AlbumBottomSheet(
|
||||
Box (
|
||||
modifier = Modifier.size(60.dp)
|
||||
) {
|
||||
GlideImage(
|
||||
imageModel = { it.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
alignment = Alignment.Center,
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(
|
||||
Alignment.Center
|
||||
val showCoverUri = isValidUri(LocalContext.current, it.album.coverUri)
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { it.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
alignment = Alignment.Center,
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(
|
||||
Alignment.Center
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
trailingContent = {
|
||||
|
||||
+41
-25
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -28,6 +29,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.bumptech.glide.Glide
|
||||
@@ -45,6 +47,19 @@ fun CurrentSelectedAlbum(
|
||||
onStop: () -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showCoverUri = isValidUri(LocalContext.current, selectedAlbum?.album?.coverUri)
|
||||
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
@@ -66,33 +81,34 @@ fun CurrentSelectedAlbum(
|
||||
)
|
||||
} },
|
||||
leadingContent = {
|
||||
Box (
|
||||
modifier = Modifier.size(60.dp)
|
||||
) {
|
||||
Box (modifier = Modifier.size(60.dp)) {
|
||||
if (selectedAlbum != null) {
|
||||
GlideImage(
|
||||
imageModel = { selectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
alignment = Alignment.Center,
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { selectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
alignment = Alignment.Center,
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(
|
||||
Alignment.Center))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Image(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
|
||||
+106
-50
@@ -55,58 +55,114 @@ fun SetLockScreenSwitch(
|
||||
onCheckedChange = onCheckedChange
|
||||
)
|
||||
}
|
||||
AnimatedVisibility(
|
||||
visible = checked,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = shrinkVertically(animationSpec = tween(durationMillis = 500, easing = LinearOutSlowInEasing))
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = animate
|
||||
)
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = checked,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = shrinkVertically(animationSpec = tween(durationMillis = 700, easing = LinearOutSlowInEasing))
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
if (checked) {
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-18
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen
|
||||
|
||||
import android.content.Context
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -45,6 +46,18 @@ fun WallpaperViewScreen(
|
||||
onBackClick: () -> Unit,
|
||||
animate : Boolean
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showUri = isValidUri(LocalContext.current, wallpaperUri)
|
||||
val zoomState = rememberZoomState()
|
||||
BackHandler { onBackClick() }
|
||||
Scaffold(
|
||||
@@ -86,26 +99,28 @@ fun WallpaperViewScreen(
|
||||
.padding(padding)
|
||||
.zoomable(zoomState)
|
||||
) {
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
if (showUri) {
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user