Compare commits

..
3 Commits
Author SHA1 Message Date
Anthonyy232 48a730e4a9 Fixed WallpaperBootAndChangeReceiver not changing wallpaper immediately
Refactored WallpaperAlarmSchedulerImpl.kt name
2024-07-19 20:28:29 -07:00
Anthonyy232 4c3d5af7f7 Removed FAB animation when scrolling due to recomposition inefficiency
Refactored viewmodel injection code
Changed column to lazy column on WallpaperScreen.kt
2024-07-17 22:42:10 -07:00
Anthonyy232 829d982d23 Refactored albums viewmodel injecting 2024-07-16 23:34:34 -07:00
15 changed files with 276 additions and 325 deletions

No files matched your search

+2 -2
View File
@@ -19,8 +19,8 @@ android {
applicationId = "com.anthonyla.paperize"
minSdk = 26
targetSdk = 34
versionCode = 26
versionName = "1.6.1"
versionCode = 27
versionName = "1.6.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
@@ -42,7 +42,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.Wa
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@@ -81,7 +81,7 @@ class MainActivity : ComponentActivity() {
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
setContent {
val scheduler = WallpaperScheduler(context)
val scheduler = WallpaperAlarmSchedulerImpl(context)
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
if (isFirstLaunch) {
@@ -55,7 +55,7 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.WallpaperView
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionIn
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@@ -65,7 +65,7 @@ import kotlinx.coroutines.withContext
@Composable
fun PaperizeApp(
firstLaunch: Boolean,
scheduler : WallpaperScheduler,
scheduler : WallpaperAlarmSchedulerImpl,
topInsets: Dp,
albumsViewModel: AlbumsViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
@@ -232,6 +232,7 @@ fun PaperizeApp(
}
) {
HomeScreen(
albums = albumState.value.albumsWithWallpapers,
onSettingsClick = { navController.navigate(Settings) },
navigateToAddWallpaperScreen = {
navController.navigate(AddEdit(it))
@@ -558,7 +559,8 @@ fun PaperizeApp(
},
onShowFolderView = { folderName, wallpapers ->
navController.navigate(FolderView(folderName, wallpapers))
}
},
animate = settingsState.value.animate
)
}
// Navigate to wallpaper view screen to view individual wallpapers in full screen
@@ -654,6 +656,7 @@ fun PaperizeApp(
if (albumWithWallpaper != null) {
AlbumViewScreen(
album = albumWithWallpaper,
animate = settingsState.value.animate,
onBackClick = { navController.navigateUp() },
onShowWallpaperView = {
navController.navigate(WallpaperView(it))
@@ -5,11 +5,8 @@ import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing
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.PaddingValues
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.album.components.FolderItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
@Composable
fun AddAlbumScreen(
addAlbumViewModel: AddAlbumViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
initialAlbumName: String,
onBackClick: () -> Unit,
onConfirmation: () -> Unit,
onShowWallpaperView: (String) -> Unit,
onShowFolderView: (String?, List<String>) -> Unit
onShowFolderView: (String?, List<String>) -> Unit,
animate: Boolean
) {
val context = LocalContext.current
val lazyGridState = rememberLazyStaggeredGridState()
val addAlbumState = addAlbumViewModel.state.collectAsStateWithLifecycle()
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
var selectionMode by rememberSaveable { mutableStateOf(false) }
if (addAlbumState.value.initialAlbumName.isEmpty()) {
addAlbumViewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
}
var showSpotlight by rememberSaveable { mutableStateOf(false) }
BackHandler(
@@ -126,40 +118,17 @@ fun AddAlbumScreen(
)
},
floatingActionButton = {
if (settingsState.value.animate) {
AnimatedVisibility(
visible = !lazyGridState.isScrollInProgress || lazyGridState.firstVisibleItemScrollOffset < 0,
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
) {
AddAlbumAnimatedFab(
onImageClick = {
selectionMode = false
imagePickerLauncher.launch(arrayOf("image/*"))
},
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
)
}
AddAlbumAnimatedFab(
onImageClick = {
selectionMode = false
imagePickerLauncher.launch(arrayOf("image/*"))
},
onFolderClick = {
selectionMode = false
folderPickerLauncher.launch(null)
},
animate = animate
)
},
content = {
LazyVerticalStaggeredGrid(
@@ -225,7 +194,7 @@ fun AddAlbumScreen(
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.Text
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.Modifier
import androidx.compose.ui.draw.clip
@@ -38,6 +41,7 @@ fun AlbumItem(
modifier: Modifier = Modifier,
animate: Boolean = true
) {
val context = LocalContext.current
fun isValidUri(context: Context, uriString: String?): Boolean {
val uri = uriString?.toUri()
return try {
@@ -48,8 +52,7 @@ fun AlbumItem(
true
} catch (e: Exception) { false }
}
val showCoverUri = album.coverUri != null && isValidUri(LocalContext.current, album.coverUri)
val showCoverUri by remember { mutableStateOf(album.coverUri != null && isValidUri(context, album.coverUri)) }
Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
@@ -70,7 +73,7 @@ fun AlbumItem(
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center,
requestSize = IntSize(300, 300),
requestSize = IntSize(250, 250),
),
loading = {
if (animate) {
@@ -28,13 +28,14 @@ import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
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.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
@@ -62,7 +63,7 @@ fun FolderItem(
modifier: Modifier = Modifier,
animate: Boolean = true
) {
val configuration = LocalConfiguration.current
val context = LocalContext.current
val haptics = LocalHapticFeedback.current
val transition = updateTransition(itemSelected, label = "")
@@ -84,8 +85,7 @@ fun FolderItem(
true
} catch (e: Exception) { false }
}
val showCoverUri = folder.coverUri != null && isValidUri(LocalContext.current, folder.coverUri)
val showCoverUri by remember { mutableStateOf(folder.coverUri != null && isValidUri(context, folder.coverUri)) }
Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
@@ -122,7 +122,7 @@ fun FolderItem(
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center,
requestSize = IntSize(300, 300),
requestSize = IntSize(250, 250),
),
loading = {
if (animate) {
@@ -21,6 +21,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.surfaceColorAtElevation
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.Modifier
import androidx.compose.ui.draw.blur
@@ -40,8 +42,6 @@ import androidx.core.net.toUri
import com.anthonyla.paperize.R
import com.anthonyla.paperize.core.ScalingConstants
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.glide.GlideImage
@@ -88,8 +88,8 @@ fun WallpaperItem(
true
} catch (e: Exception) { false }
}
val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) }
val showUri = isValidUri(LocalContext.current, wallpaperUri)
val boxModifier = if (clickable) {
modifier
.padding(paddingTransition)
@@ -115,6 +115,7 @@ fun WallpaperItem(
.padding(paddingTransition)
.clip(RoundedCornerShape(roundedCornerShapeTransition))
}
Box(modifier = boxModifier) {
if (showUri) {
val dimension = wallpaperUri.toUri().getImageDimensions(context)
@@ -129,7 +130,7 @@ fun WallpaperItem(
ScalingConstants.STRETCH -> ContentScale.FillBounds
}
} else { ContentScale.Crop },
requestSize = IntSize(300, 300),
requestSize = IntSize(250, 250),
alignment = Alignment.Center,
colorFilter = if (darken && darkenPercentage != null && darkenPercentage < 100) {
ColorFilter.tint(
@@ -145,12 +146,6 @@ fun WallpaperItem(
}
}
},
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.format(DecodeFormat.PREFER_RGB_565)
},
modifier = Modifier
.aspectRatio(imageAspectRatio)
.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.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing
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.PaddingValues
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.WallpaperItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
@Composable
fun AlbumViewScreen(
albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
album: AlbumWithWallpaperAndFolder,
animate: Boolean,
onBackClick: () -> Unit,
onShowWallpaperView: (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
val lazyListState = rememberLazyStaggeredGridState()
val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle()
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
var selectionMode by rememberSaveable { mutableStateOf(false) }
val context = LocalContext.current
@@ -119,38 +114,17 @@ fun AlbumViewScreen(
)
},
floatingActionButton = {
if (settingsState.value.animate) {
AnimatedVisibility(
visible = !lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
) {
AddAlbumAnimatedFab(
onImageClick = {
selectionMode = false
imagePickerLauncher.launch(arrayOf("image/*"))
},
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
)
}
AddAlbumAnimatedFab(
onImageClick = {
selectionMode = false
imagePickerLauncher.launch(arrayOf("image/*"))
},
onFolderClick = {
selectionMode = false
folderPickerLauncher.launch(null)
},
animate = animate
)
},
content = { it ->
LazyVerticalStaggeredGrid(
@@ -164,7 +138,7 @@ fun AlbumViewScreen(
content = {
items (items = album.folders, key = { folder -> folder.folderUri }
) { folder ->
if (settingsState.value.animate) {
if (animate) {
FolderItem(
folder = folder,
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
@@ -182,8 +156,10 @@ fun AlbumViewScreen(
onFolderViewClick = {
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
},
modifier = Modifier.padding(4.dp).animateItem(
placementSpec = tween(
modifier = Modifier
.padding(4.dp)
.animateItem(
placementSpec = tween(
durationMillis = 800,
delayMillis = 0,
easing = FastOutSlowInEasing
@@ -217,7 +193,7 @@ fun AlbumViewScreen(
}
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
) { wallpaper ->
if (settingsState.value.animate) {
if (animate) {
WallpaperItem(
wallpaperUri = wallpaper.wallpaperUri,
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
@@ -32,6 +32,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.Wa
@Composable
fun HomeScreen(
albums: List<AlbumWithWallpaperAndFolder>,
animate : Boolean,
darken: Boolean,
darkenPercentage: Int,
@@ -131,6 +132,7 @@ fun HomeScreen(
) { index ->
when(index.coerceIn(tabItems.indices)) {
0 -> WallpaperScreen(
albums = albums,
animate = animate,
darken = darken,
darkenPercentage = darkenPercentage,
@@ -163,6 +165,7 @@ fun HomeScreen(
blurPercentage = blurPercentage
)
else -> LibraryScreen(
albums = albums,
onAddNewAlbumClick = { addAlbumDialog = true },
onViewAlbum = onAlbumViewClick,
animate = animate
@@ -18,21 +18,18 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.AlbumItem
@Composable
fun LibraryScreen(
albumsViewModel: AlbumsViewModel = hiltViewModel(),
albums: List<AlbumWithWallpaperAndFolder>,
onAddNewAlbumClick: () -> Unit,
onViewAlbum: (String) -> Unit,
animate: Boolean
) {
val lazyListState = rememberLazyGridState()
val state = albumsViewModel.state.collectAsStateWithLifecycle()
Scaffold(
modifier = Modifier.fillMaxSize(),
floatingActionButton = {
@@ -56,7 +53,7 @@ fun LibraryScreen(
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
content = {
items (state.value.albumsWithWallpapers, key = { album -> album.album.initialAlbumName}
items (albums, key = { album -> album.album.initialAlbumName}
) { album ->
AlbumItem(
album = album.album,
@@ -9,13 +9,11 @@ import android.provider.Settings
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
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.verticalScroll
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarDuration
@@ -33,13 +31,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.R
import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
@@ -53,7 +48,7 @@ import kotlinx.coroutines.launch
@Composable
fun WallpaperScreen(
albumsViewModel: AlbumsViewModel = hiltViewModel(),
albums: List<AlbumWithWallpaperAndFolder>,
animate: Boolean,
darken: Boolean,
darkenPercentage: Int,
@@ -86,13 +81,11 @@ fun WallpaperScreen(
blurPercentage: Int
) {
val context = LocalContext.current
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val openLiveDialog = rememberSaveable { mutableStateOf(false) }
val showInterval = rememberSaveable { mutableStateOf(false) }
val scrollState = rememberScrollState()
if (openLiveDialog.value) {
ShowLiveWallpaperEnabledDialog(
@@ -114,100 +107,124 @@ fun WallpaperScreen(
) },
modifier = Modifier.fillMaxSize(),
content = { padding ->
Column(
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(8.dp)
.verticalScroll(scrollState),
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
ChangerSelectionRow(
homeEnabled = homeEnabled,
lockEnabled = lockEnabled,
onHomeCheckedChange = onHomeCheckedChange,
onLockCheckedChange = onLockCheckedChange
)
if (homeEnabled || lockEnabled) {
CurrentSelectedAlbum(
selectedAlbum = selectedAlbum,
onOpenBottomSheet = {
if (albumState.value.albumsWithWallpapers.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 {
ChangerSelectionRow(
homeEnabled = homeEnabled,
lockEnabled = lockEnabled,
onHomeCheckedChange = onHomeCheckedChange,
onLockCheckedChange = onLockCheckedChange
)
}
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
item {
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)
}
)
}
}
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) {
CurrentAndNextChange(lastSetTime, nextSetTime)
}
}
}
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
CurrentAndNextChange(lastSetTime, nextSetTime)
item {
if (animate) {
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
)
}
}
}
}
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
WallpaperPreviewAndScale(
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
animate = true,
animate = false,
darken = darken,
darkenPercentage = darkenPercentage,
scaling = scaling,
@@ -220,129 +237,118 @@ fun WallpaperScreen(
}
}
}
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
WallpaperPreviewAndScale(
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
animate = false,
darken = darken,
darkenPercentage = darkenPercentage,
scaling = scaling,
onScalingChange = onScalingChange,
homeEnabled = homeEnabled,
lockEnabled = lockEnabled,
blur = blur,
blurPercentage = blurPercentage
)
item {
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
TimeSliders(
timeInMinutes1 = interval1,
timeInMinutes2 = interval2,
onTimeChange1 = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onTimeChange1(totalMinutes)
},
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) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
TimeSliders(
timeInMinutes1 = interval1,
timeInMinutes2 = interval2,
onTimeChange1 = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onTimeChange1(totalMinutes)
},
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
)
item {
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
DarkenSwitchAndSlider(
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
)
}
}
}
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,
)
item {
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
)
}
}
}
if (animate) {
AnimatedVisibility(
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
DarkenSwitchAndSlider(
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
)
else {
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
BlurSwitchAndSlider(
onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange,
blur = blur,
blurPercentage = blurPercentage,
animate = false
)
}
}
}
}
if (((homeEnabled || lockEnabled)) && openBottomSheet) {
AlbumBottomSheet(
albums = albumState.value.albumsWithWallpapers,
albums = albums,
currentSelectedAlbum = selectedAlbum,
onDismiss = { openBottomSheet = false },
onSelect = { album ->
@@ -16,7 +16,7 @@ import java.time.ZoneId
* It uses the AlarmManager to schedule alarms for the WallpaperReceiver.
* It also uses the WallpaperService to change the wallpaper due to receiver limitations.
*/
class WallpaperScheduler (
class WallpaperAlarmSchedulerImpl (
private val context: Context,
): WallpaperAlarmScheduler {
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
@@ -23,7 +23,7 @@ class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
@SuppressLint("UnsafeProtectedBroadcastReceiver")
override fun onReceive(context: Context, intent: Intent) = goAsync {
try {
val scheduler = WallpaperScheduler(context)
val scheduler = WallpaperAlarmSchedulerImpl(context)
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
if (toggleChanger) {
val timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
@@ -34,8 +34,7 @@ class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
timeInMinutes2 = timeInMinutes2,
scheduleSeparately = scheduleSeparately
)
val changeImmediate = intent.getBooleanExtra("changeImmediate", false)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, changeImmediate, true)}
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
}
} catch (e: Exception) {
e.printStackTrace()
@@ -22,7 +22,7 @@ class WallpaperReceiver: BroadcastReceiver() {
action = WallpaperService1.Actions.REFRESH.toString()
}
context.startService(serviceIntent)
WallpaperScheduler(context).scheduleRefresh()
WallpaperAlarmSchedulerImpl(context).scheduleRefresh()
}
else {
val timeInMinutes1 = intent?.getIntExtra("timeInMinutes1", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
@@ -48,7 +48,7 @@ class WallpaperReceiver: BroadcastReceiver() {
// Schedule next alarm for next wallpaper change
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
WallpaperScheduler(context).scheduleWallpaperAlarm(
WallpaperAlarmSchedulerImpl(context).scheduleWallpaperAlarm(
WallpaperAlarmItem(
timeInMinutes1 = timeInMinutes1,
timeInMinutes2 = timeInMinutes2,
@@ -28,7 +28,7 @@ class ChangeWallpaperTileService: TileService() {
override fun onClick() {
super.onClick()
val intent = Intent(this, WallpaperBootAndChangeReceiver::class.java).putExtra("changeImmediate", true)
val intent = Intent(this, WallpaperBootAndChangeReceiver::class.java)
sendBroadcast(intent)
}