Removed FAB animation when scrolling due to recomposition inefficiency

Refactored viewmodel injection code
Changed column to lazy column on WallpaperScreen.kt
This commit is contained in:
Anthonyy232 committed 2024-07-17 22:42:10 -07:00
1 parent 829d982d23
commit 4c3d5af7f7
8 files changed
+257 -302

No files matched your search

+2 -2
View File
@@ -19,8 +19,8 @@ android {
applicationId = "com.anthonyla.paperize" applicationId = "com.anthonyla.paperize"
minSdk = 26 minSdk = 26
targetSdk = 34 targetSdk = 34
versionCode = 26 versionCode = 27
versionName = "1.6.1" versionName = "1.6.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {
useSupportLibrary = true useSupportLibrary = true
@@ -559,7 +559,8 @@ fun PaperizeApp(
}, },
onShowFolderView = { folderName, wallpapers -> onShowFolderView = { folderName, wallpapers ->
navController.navigate(FolderView(folderName, wallpapers)) navController.navigate(FolderView(folderName, wallpapers))
} },
animate = settingsState.value.animate
) )
} }
// Navigate to wallpaper view screen to view individual wallpapers in full screen // Navigate to wallpaper view screen to view individual wallpapers in full screen
@@ -655,6 +656,7 @@ fun PaperizeApp(
if (albumWithWallpaper != null) { if (albumWithWallpaper != null) {
AlbumViewScreen( AlbumViewScreen(
album = albumWithWallpaper, album = albumWithWallpaper,
animate = settingsState.value.animate,
onBackClick = { navController.navigateUp() }, onBackClick = { navController.navigateUp() },
onShowWallpaperView = { onShowWallpaperView = {
navController.navigate(WallpaperView(it)) navController.navigate(WallpaperView(it))
@@ -5,11 +5,8 @@ import android.net.Uri
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -33,26 +30,21 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.co
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumSmallTopBar import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumSmallTopBar
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
@Composable @Composable
fun AddAlbumScreen( fun AddAlbumScreen(
addAlbumViewModel: AddAlbumViewModel = hiltViewModel(), addAlbumViewModel: AddAlbumViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
initialAlbumName: String, initialAlbumName: String,
onBackClick: () -> Unit, onBackClick: () -> Unit,
onConfirmation: () -> Unit, onConfirmation: () -> Unit,
onShowWallpaperView: (String) -> Unit, onShowWallpaperView: (String) -> Unit,
onShowFolderView: (String?, List<String>) -> Unit onShowFolderView: (String?, List<String>) -> Unit,
animate: Boolean
) { ) {
val context = LocalContext.current val context = LocalContext.current
val lazyGridState = rememberLazyStaggeredGridState() val lazyGridState = rememberLazyStaggeredGridState()
val addAlbumState = addAlbumViewModel.state.collectAsStateWithLifecycle() val addAlbumState = addAlbumViewModel.state.collectAsStateWithLifecycle()
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
var selectionMode by rememberSaveable { mutableStateOf(false) } var selectionMode by rememberSaveable { mutableStateOf(false) }
if (addAlbumState.value.initialAlbumName.isEmpty()) {
addAlbumViewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
}
var showSpotlight by rememberSaveable { mutableStateOf(false) } var showSpotlight by rememberSaveable { mutableStateOf(false) }
BackHandler( BackHandler(
@@ -126,40 +118,17 @@ fun AddAlbumScreen(
) )
}, },
floatingActionButton = { floatingActionButton = {
if (settingsState.value.animate) { AddAlbumAnimatedFab(
AnimatedVisibility( onImageClick = {
visible = !lazyGridState.isScrollInProgress || lazyGridState.firstVisibleItemScrollOffset < 0, selectionMode = false
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)), imagePickerLauncher.launch(arrayOf("image/*"))
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)), },
) { onFolderClick = {
AddAlbumAnimatedFab( selectionMode = false
onImageClick = { folderPickerLauncher.launch(null)
selectionMode = false },
imagePickerLauncher.launch(arrayOf("image/*")) animate = animate
}, )
onFolderClick = {
selectionMode = false
folderPickerLauncher.launch(null)
},
animate = true
)
}
}
else {
AddAlbumAnimatedFab(
onImageClick = {
selectionMode = false
imagePickerLauncher.launch(arrayOf("image/*"))
showSpotlight = true
},
onFolderClick = {
selectionMode = false
folderPickerLauncher.launch(null)
showSpotlight = true
},
animate = false
)
}
}, },
content = { content = {
LazyVerticalStaggeredGrid( LazyVerticalStaggeredGrid(
@@ -225,7 +194,7 @@ fun AddAlbumScreen(
easing = FastOutSlowInEasing easing = FastOutSlowInEasing
), ),
), ),
animate = settingsState.value.animate animate = animate
) )
} }
} }
@@ -15,6 +15,9 @@ import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -38,6 +41,7 @@ fun AlbumItem(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
animate: Boolean = true animate: Boolean = true
) { ) {
val context = LocalContext.current
fun isValidUri(context: Context, uriString: String?): Boolean { fun isValidUri(context: Context, uriString: String?): Boolean {
val uri = uriString?.toUri() val uri = uriString?.toUri()
return try { return try {
@@ -48,8 +52,7 @@ fun AlbumItem(
true true
} catch (e: Exception) { false } } catch (e: Exception) { false }
} }
val showCoverUri by remember { mutableStateOf(album.coverUri != null && isValidUri(context, album.coverUri)) }
val showCoverUri = album.coverUri != null && isValidUri(LocalContext.current, album.coverUri)
Card( Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
@@ -70,7 +73,7 @@ fun AlbumItem(
imageOptions = ImageOptions( imageOptions = ImageOptions(
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
alignment = Alignment.Center, alignment = Alignment.Center,
requestSize = IntSize(300, 300), requestSize = IntSize(250, 250),
), ),
loading = { loading = {
if (animate) { if (animate) {
@@ -28,13 +28,14 @@ import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@@ -62,7 +63,7 @@ fun FolderItem(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
animate: Boolean = true animate: Boolean = true
) { ) {
val configuration = LocalConfiguration.current val context = LocalContext.current
val haptics = LocalHapticFeedback.current val haptics = LocalHapticFeedback.current
val transition = updateTransition(itemSelected, label = "") val transition = updateTransition(itemSelected, label = "")
@@ -84,8 +85,7 @@ fun FolderItem(
true true
} catch (e: Exception) { false } } catch (e: Exception) { false }
} }
val showCoverUri by remember { mutableStateOf(folder.coverUri != null && isValidUri(context, folder.coverUri)) }
val showCoverUri = folder.coverUri != null && isValidUri(LocalContext.current, folder.coverUri)
Card( Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
@@ -122,7 +122,7 @@ fun FolderItem(
imageOptions = ImageOptions( imageOptions = ImageOptions(
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
alignment = Alignment.Center, alignment = Alignment.Center,
requestSize = IntSize(300, 300), requestSize = IntSize(250, 250),
), ),
loading = { loading = {
if (animate) { if (animate) {
@@ -21,6 +21,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur import androidx.compose.ui.draw.blur
@@ -40,8 +42,6 @@ import androidx.core.net.toUri
import com.anthonyla.paperize.R import com.anthonyla.paperize.R
import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.core.getImageDimensions import com.anthonyla.paperize.core.getImageDimensions
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.skydoves.landscapist.ImageOptions import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.glide.GlideImage import com.skydoves.landscapist.glide.GlideImage
@@ -88,8 +88,8 @@ fun WallpaperItem(
true true
} catch (e: Exception) { false } } catch (e: Exception) { false }
} }
val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) }
val showUri = isValidUri(LocalContext.current, wallpaperUri)
val boxModifier = if (clickable) { val boxModifier = if (clickable) {
modifier modifier
.padding(paddingTransition) .padding(paddingTransition)
@@ -115,6 +115,7 @@ fun WallpaperItem(
.padding(paddingTransition) .padding(paddingTransition)
.clip(RoundedCornerShape(roundedCornerShapeTransition)) .clip(RoundedCornerShape(roundedCornerShapeTransition))
} }
Box(modifier = boxModifier) { Box(modifier = boxModifier) {
if (showUri) { if (showUri) {
val dimension = wallpaperUri.toUri().getImageDimensions(context) val dimension = wallpaperUri.toUri().getImageDimensions(context)
@@ -129,7 +130,7 @@ fun WallpaperItem(
ScalingConstants.STRETCH -> ContentScale.FillBounds ScalingConstants.STRETCH -> ContentScale.FillBounds
} }
} else { ContentScale.Crop }, } else { ContentScale.Crop },
requestSize = IntSize(300, 300), requestSize = IntSize(250, 250),
alignment = Alignment.Center, alignment = Alignment.Center,
colorFilter = if (darken && darkenPercentage != null && darkenPercentage < 100) { colorFilter = if (darken && darkenPercentage != null && darkenPercentage < 100) {
ColorFilter.tint( ColorFilter.tint(
@@ -145,12 +146,6 @@ fun WallpaperItem(
} }
} }
}, },
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.format(DecodeFormat.PREFER_RGB_565)
},
modifier = Modifier modifier = Modifier
.aspectRatio(imageAspectRatio) .aspectRatio(imageAspectRatio)
.background(if (scaling != null) Color.Black else Color.Transparent) .background(if (scaling != null) Color.Black else Color.Transparent)
@@ -5,11 +5,8 @@ import android.net.Uri
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -34,13 +31,12 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.co
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
@Composable @Composable
fun AlbumViewScreen( fun AlbumViewScreen(
albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(), albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
album: AlbumWithWallpaperAndFolder, album: AlbumWithWallpaperAndFolder,
animate: Boolean,
onBackClick: () -> Unit, onBackClick: () -> Unit,
onShowWallpaperView: (String) -> Unit, onShowWallpaperView: (String) -> Unit,
onShowFolderView: (String?, List<String>) -> Unit, onShowFolderView: (String?, List<String>) -> Unit,
@@ -51,7 +47,6 @@ fun AlbumViewScreen(
albumViewScreenViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size)) // For selectedAll state albumViewScreenViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size)) // For selectedAll state
val lazyListState = rememberLazyStaggeredGridState() val lazyListState = rememberLazyStaggeredGridState()
val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle() val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle()
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
var selectionMode by rememberSaveable { mutableStateOf(false) } var selectionMode by rememberSaveable { mutableStateOf(false) }
val context = LocalContext.current val context = LocalContext.current
@@ -119,38 +114,17 @@ fun AlbumViewScreen(
) )
}, },
floatingActionButton = { floatingActionButton = {
if (settingsState.value.animate) { AddAlbumAnimatedFab(
AnimatedVisibility( onImageClick = {
visible = !lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0, selectionMode = false
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)), imagePickerLauncher.launch(arrayOf("image/*"))
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)), },
) { onFolderClick = {
AddAlbumAnimatedFab( selectionMode = false
onImageClick = { folderPickerLauncher.launch(null)
selectionMode = false },
imagePickerLauncher.launch(arrayOf("image/*")) animate = animate
}, )
onFolderClick = {
selectionMode = false
folderPickerLauncher.launch(null)
},
animate = true
)
}
}
else {
AddAlbumAnimatedFab(
onImageClick = {
selectionMode = false
imagePickerLauncher.launch(arrayOf("image/*"))
},
onFolderClick = {
selectionMode = false
folderPickerLauncher.launch(null)
},
animate = false
)
}
}, },
content = { it -> content = { it ->
LazyVerticalStaggeredGrid( LazyVerticalStaggeredGrid(
@@ -164,7 +138,7 @@ fun AlbumViewScreen(
content = { content = {
items (items = album.folders, key = { folder -> folder.folderUri } items (items = album.folders, key = { folder -> folder.folderUri }
) { folder -> ) { folder ->
if (settingsState.value.animate) { if (animate) {
FolderItem( FolderItem(
folder = folder, folder = folder,
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri), itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
@@ -182,8 +156,10 @@ fun AlbumViewScreen(
onFolderViewClick = { onFolderViewClick = {
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers) if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
}, },
modifier = Modifier.padding(4.dp).animateItem( modifier = Modifier
placementSpec = tween( .padding(4.dp)
.animateItem(
placementSpec = tween(
durationMillis = 800, durationMillis = 800,
delayMillis = 0, delayMillis = 0,
easing = FastOutSlowInEasing easing = FastOutSlowInEasing
@@ -217,7 +193,7 @@ fun AlbumViewScreen(
} }
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri } items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
) { wallpaper -> ) { wallpaper ->
if (settingsState.value.animate) { if (animate) {
WallpaperItem( WallpaperItem(
wallpaperUri = wallpaper.wallpaperUri, wallpaperUri = wallpaper.wallpaperUri,
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri), itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
@@ -9,13 +9,11 @@ import android.provider.Settings
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideInVertically
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarDuration
@@ -88,7 +86,6 @@ fun WallpaperScreen(
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }
val openLiveDialog = rememberSaveable { mutableStateOf(false) } val openLiveDialog = rememberSaveable { mutableStateOf(false) }
val showInterval = rememberSaveable { mutableStateOf(false) } val showInterval = rememberSaveable { mutableStateOf(false) }
val scrollState = rememberScrollState()
if (openLiveDialog.value) { if (openLiveDialog.value) {
ShowLiveWallpaperEnabledDialog( ShowLiveWallpaperEnabledDialog(
@@ -110,100 +107,124 @@ fun WallpaperScreen(
) }, ) },
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
content = { padding -> content = { padding ->
Column( LazyColumn(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(8.dp) .padding(8.dp),
.verticalScroll(scrollState),
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
ChangerSelectionRow( item {
homeEnabled = homeEnabled, ChangerSelectionRow(
lockEnabled = lockEnabled, homeEnabled = homeEnabled,
onHomeCheckedChange = onHomeCheckedChange, lockEnabled = lockEnabled,
onLockCheckedChange = onLockCheckedChange onHomeCheckedChange = onHomeCheckedChange,
) onLockCheckedChange = onLockCheckedChange
if (homeEnabled || lockEnabled) {
CurrentSelectedAlbum(
selectedAlbum = selectedAlbum,
onOpenBottomSheet = {
if (albums.firstOrNull() != null) {
if (isLiveWallpaperSet(context)) {
openLiveDialog.value = true
} else {
openBottomSheet = true
}
} else {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(
message = context.getString(R.string.no_albums_found),
actionLabel = context.getString(R.string.dismiss),
duration = SnackbarDuration.Short
)
}
}
},
onStop = {
if (selectedAlbum != null) {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(
message = context.getString(
R.string.has_been_unselected,
selectedAlbum.album.displayedAlbumName
),
actionLabel = context.getString(R.string.dismiss),
duration = SnackbarDuration.Short
)
}
onStop()
}
},
animate = animate,
enableChanger = enableChanger,
onToggleChanger = {
if (!it) {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(
message = context.getString(R.string.wallpaper_changer_has_been_disabled),
actionLabel = context.getString(R.string.dismiss),
duration = SnackbarDuration.Short
)
}
}
onToggleChanger(it)
}
) )
} }
if (animate) { item {
AnimatedVisibility( if (homeEnabled || lockEnabled) {
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null, CurrentSelectedAlbum(
enter = slideInVertically(initialOffsetY = { -it }), selectedAlbum = selectedAlbum,
exit = fadeOut() onOpenBottomSheet = {
) { if (albums.firstOrNull() != null) {
if (isLiveWallpaperSet(context)) {
openLiveDialog.value = true
} else {
openBottomSheet = true
}
} else {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(
message = context.getString(R.string.no_albums_found),
actionLabel = context.getString(R.string.dismiss),
duration = SnackbarDuration.Short
)
}
}
},
onStop = {
if (selectedAlbum != null) {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(
message = context.getString(
R.string.has_been_unselected,
selectedAlbum.album.displayedAlbumName
),
actionLabel = context.getString(R.string.dismiss),
duration = SnackbarDuration.Short
)
}
onStop()
}
},
animate = animate,
enableChanger = enableChanger,
onToggleChanger = {
if (!it) {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(
message = context.getString(R.string.wallpaper_changer_has_been_disabled),
actionLabel = context.getString(R.string.dismiss),
duration = SnackbarDuration.Short
)
}
}
onToggleChanger(it)
}
)
}
}
item {
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
CurrentAndNextChange(lastSetTime, nextSetTime)
}
}
}
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) { if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
CurrentAndNextChange(lastSetTime, nextSetTime) CurrentAndNextChange(lastSetTime, nextSetTime)
} }
} }
} }
else { item {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) { if (animate) {
CurrentAndNextChange(lastSetTime, nextSetTime) AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
WallpaperPreviewAndScale(
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
animate = true,
darken = darken,
darkenPercentage = darkenPercentage,
scaling = scaling,
onScalingChange = onScalingChange,
homeEnabled = homeEnabled,
lockEnabled = lockEnabled,
blur = blur,
blurPercentage = blurPercentage
)
}
}
} }
} else {
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) { if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
WallpaperPreviewAndScale( WallpaperPreviewAndScale(
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper, currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper, currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
animate = true, animate = false,
darken = darken, darken = darken,
darkenPercentage = darkenPercentage, darkenPercentage = darkenPercentage,
scaling = scaling, scaling = scaling,
@@ -216,123 +237,112 @@ fun WallpaperScreen(
} }
} }
} }
else { item {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) { if (animate) {
WallpaperPreviewAndScale( AnimatedVisibility(
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper, visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper, enter = slideInVertically(initialOffsetY = { -it }),
animate = false, exit = fadeOut()
darken = darken, ) {
darkenPercentage = darkenPercentage, TimeSliders(
scaling = scaling, timeInMinutes1 = interval1,
onScalingChange = onScalingChange, timeInMinutes2 = interval2,
homeEnabled = homeEnabled, onTimeChange1 = { days, hours, minutes ->
lockEnabled = lockEnabled, val totalMinutes = 24 * days * 60 + hours * 60 + minutes
blur = blur, onTimeChange1(totalMinutes)
blurPercentage = blurPercentage },
) onTimeChange2 = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onTimeChange2(totalMinutes)
},
showInterval = showInterval.value,
animate = true,
onShowIntervalChange = { showInterval.value = it },
scheduleSeparately = scheduleSeparately,
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
lockEnabled = lockEnabled,
homeEnabled = homeEnabled
)
}
}
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
TimeSliders(
timeInMinutes1 = interval1,
timeInMinutes2 = interval2,
onTimeChange1 = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onScheduleWallpaperChanger1(totalMinutes)
},
onTimeChange2 = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onScheduleWallpaperChanger2(totalMinutes)
},
showInterval = showInterval.value,
animate = false,
onShowIntervalChange = { showInterval.value = it },
scheduleSeparately = scheduleSeparately,
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
lockEnabled = lockEnabled,
homeEnabled = homeEnabled,
)
}
} }
} }
if (animate) { item {
AnimatedVisibility( if (animate) {
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null, AnimatedVisibility(
enter = slideInVertically(initialOffsetY = { -it }), visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
exit = fadeOut() enter = slideInVertically(initialOffsetY = { -it }),
) { exit = fadeOut()
TimeSliders( ) {
timeInMinutes1 = interval1, DarkenSwitchAndSlider(
timeInMinutes2 = interval2, onDarkCheck = onDarkCheck,
onTimeChange1 = { days, hours, minutes -> darken = darken,
val totalMinutes = 24 * days * 60 + hours * 60 + minutes onDarkenChange = onDarkenPercentage,
onTimeChange1(totalMinutes) darkenPercentage = darkenPercentage,
}, animate = true
onTimeChange2 = { days, hours, minutes -> )
val totalMinutes = 24 * days * 60 + hours * 60 + minutes }
onTimeChange2(totalMinutes) }
}, else {
showInterval = showInterval.value, if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
animate = true, DarkenSwitchAndSlider(
onShowIntervalChange = { showInterval.value = it }, onDarkCheck = onDarkCheck,
scheduleSeparately = scheduleSeparately, darken = darken,
onScheduleSeparatelyChange = onScheduleSeparatelyChange, onDarkenChange = onDarkenPercentage,
lockEnabled = lockEnabled, darkenPercentage = darkenPercentage,
homeEnabled = homeEnabled animate = false
) )
}
} }
} }
else { item {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) { if (animate) {
TimeSliders( AnimatedVisibility(
timeInMinutes1 = interval1, visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
timeInMinutes2 = interval2, enter = slideInVertically(initialOffsetY = { -it }),
onTimeChange1 = { days, hours, minutes -> exit = fadeOut()
val totalMinutes = 24 * days * 60 + hours * 60 + minutes ) {
onScheduleWallpaperChanger1(totalMinutes) BlurSwitchAndSlider(
}, onBlurPercentageChange = onBlurPercentageChange,
onTimeChange2 = { days, hours, minutes -> onBlurChange = onBlurChange,
val totalMinutes = 24 * days * 60 + hours * 60 + minutes blur = blur,
onScheduleWallpaperChanger2(totalMinutes) blurPercentage = blurPercentage,
}, animate = true
showInterval = showInterval.value, )
animate = false, }
onShowIntervalChange = { showInterval.value = it },
scheduleSeparately = scheduleSeparately,
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
lockEnabled = lockEnabled,
homeEnabled = homeEnabled,
)
} }
} else {
if (animate) { if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
AnimatedVisibility( BlurSwitchAndSlider(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null, onBlurPercentageChange = onBlurPercentageChange,
enter = slideInVertically(initialOffsetY = { -it }), onBlurChange = onBlurChange,
exit = fadeOut() blur = blur,
) { blurPercentage = blurPercentage,
DarkenSwitchAndSlider( animate = false
onDarkCheck = onDarkCheck, )
darken = darken, }
onDarkenChange = onDarkenPercentage,
darkenPercentage = darkenPercentage,
animate = true
)
}
}
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
DarkenSwitchAndSlider(
onDarkCheck = onDarkCheck,
darken = darken,
onDarkenChange = onDarkenPercentage,
darkenPercentage = darkenPercentage,
animate = false
)
}
}
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
BlurSwitchAndSlider(
onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange,
blur = blur,
blurPercentage = blurPercentage,
animate = true
)
}
}
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
BlurSwitchAndSlider(
onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange,
blur = blur,
blurPercentage = blurPercentage,
animate = false
)
} }
} }
} }