Added separate scheduling for lock screen
Added option to allow only changing lock screen Updated wallpaper screen UI to match options selected Updated wallpaper retrieval method to support lock and home screen separation in scheduling Fixed issue where pressing back would sometimes freeze up
This commit is contained in:
1 parent
0cc477b7e8
commit
58b24e50ff
79 files changed
+2031
-6564
No files matched your search
+1
-1
@@ -13,7 +13,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class, Folder::class],
|
||||
version = 2
|
||||
version = 4
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class],
|
||||
version = 2
|
||||
version = 4
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SelectedAlbumDatabase: RoomDatabase() {
|
||||
|
||||
@@ -10,7 +10,10 @@ import androidx.room.PrimaryKey
|
||||
* @param displayedAlbumName The displayed album name
|
||||
* @param coverUri The cover uri of the album
|
||||
* @param initialized Whether the album has been initialized
|
||||
* @param wallpapersInQueue The wallpapers in the queue to be displayed
|
||||
* @param homeWallpapersInQueue The wallpapers in the queue to be displayed for the home screen or when the user schedules both lock and home together
|
||||
* @param lockWallpapersInQueue The wallpapers in the queue to be displayed for the lock screen when scheduled separately
|
||||
* @param currentHomeWallpaper The current wallpaper for the home screen
|
||||
* @param currentLockWallpaper The current wallpaper for the lock screen
|
||||
*/
|
||||
@Entity
|
||||
data class Album(
|
||||
@@ -18,6 +21,8 @@ data class Album(
|
||||
val displayedAlbumName: String,
|
||||
val coverUri: String?,
|
||||
val initialized: Boolean = false,
|
||||
val wallpapersInQueue: List<String> = emptyList(),
|
||||
val currentWallpaper: String? = null
|
||||
val homeWallpapersInQueue: List<String> = emptyList(),
|
||||
val lockWallpapersInQueue: List<String> = emptyList(),
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null
|
||||
)
|
||||
+6
-4
@@ -67,6 +67,7 @@ class MainActivity : ComponentActivity() {
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
|
||||
|
||||
if (isFirstLaunch) {
|
||||
val contentResolver = context.contentResolver
|
||||
val persistedUris = contentResolver.persistedUriPermissions
|
||||
@@ -78,7 +79,7 @@ class MainActivity : ComponentActivity() {
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
|
||||
lifecycleScope.launch {
|
||||
val serviceIntent = Intent(this@MainActivity, WallpaperService::class.java)
|
||||
val isAlreadyRunning = withContext(Dispatchers.IO) {5
|
||||
val isAlreadyRunning = withContext(Dispatchers.IO) {
|
||||
val activityManager = getSystemService(ACTIVITY_SERVICE) as? ActivityManager
|
||||
activityManager?.getRunningServices(Integer.MAX_VALUE)?.any {
|
||||
it.service == serviceIntent.component
|
||||
@@ -88,7 +89,9 @@ class MainActivity : ComponentActivity() {
|
||||
if (!isAlreadyRunning) {
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", settingsState.value.interval)
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
@@ -103,12 +106,11 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
PaperizeTheme(settingsState) {
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.dynamicTheming) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+430
-141
@@ -84,45 +84,63 @@ fun PaperizeApp(
|
||||
|
||||
// React to albumState changes and change selectedAlbum's details to keep it from being stale
|
||||
LaunchedEffect(albumState.value.albumsWithWallpapers) {
|
||||
albumState.value.albumsWithWallpapers.asSequence().forEach { albumWithWallpapers ->
|
||||
if (!albumWithWallpapers.album.initialized && (albumWithWallpapers.wallpapers.isNotEmpty() || albumWithWallpapers.folders.isNotEmpty())) {
|
||||
albumsViewModel.onEvent(AlbumsEvent.InitializeAlbum(albumWithWallpapers))
|
||||
}
|
||||
else if (albumWithWallpapers.wallpapers.isEmpty() && albumWithWallpapers.folders.isEmpty() && albumWithWallpapers.album.initialized) {
|
||||
if (navController.currentDestination?.route == Home::class.simpleName) {
|
||||
navController.popBackStack<Home>(inclusive = false)
|
||||
withContext(Dispatchers.IO) {
|
||||
albumState.value.albumsWithWallpapers.asSequence().forEach { albumWithWallpapers ->
|
||||
if (!albumWithWallpapers.album.initialized && (albumWithWallpapers.wallpapers.isNotEmpty() || albumWithWallpapers.folders.isNotEmpty())) {
|
||||
albumsViewModel.onEvent(AlbumsEvent.InitializeAlbum(albumWithWallpapers))
|
||||
} else if (albumWithWallpapers.wallpapers.isEmpty() && albumWithWallpapers.folders.isEmpty() && albumWithWallpapers.album.initialized) {
|
||||
if (navController.currentDestination?.route == Home::class.simpleName) {
|
||||
navController.popBackStack<Home>(inclusive = false)
|
||||
}
|
||||
albumsViewModel.onEvent(
|
||||
AlbumsEvent.DeleteAlbumWithWallpapers(
|
||||
albumWithWallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers))
|
||||
}
|
||||
}
|
||||
selectedState.value.selectedAlbum?.let { selectedAlbum ->
|
||||
albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }?.let { foundAlbum ->
|
||||
val albumNameHashCode = foundAlbum.album.initialAlbumName.hashCode()
|
||||
val wallpapers: List<Wallpaper> =
|
||||
foundAlbum.wallpapers + foundAlbum.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = foundAlbum.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + albumNameHashCode,
|
||||
selectedState.value.selectedAlbum?.let { selectedAlbum ->
|
||||
albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }
|
||||
?.let { foundAlbum ->
|
||||
val albumNameHashCode = foundAlbum.album.initialAlbumName.hashCode()
|
||||
val wallpapers: List<Wallpaper> =
|
||||
foundAlbum.wallpapers + foundAlbum.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = foundAlbum.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + albumNameHashCode,
|
||||
)
|
||||
}
|
||||
}
|
||||
val wallpaperUriSet = wallpapers.map { it.wallpaperUri }.toSet()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
homeWallpapersInQueue = selectedAlbum.album.homeWallpapersInQueue.filter { it in wallpaperUriSet },
|
||||
lockWallpapersInQueue = selectedAlbum.album.lockWallpapersInQueue.filter { it in wallpaperUriSet },
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(
|
||||
WallpaperEvent.UpdateSelectedAlbum(
|
||||
newSelectedAlbum,
|
||||
null,
|
||||
settingsState.value.scheduleSeparately
|
||||
)
|
||||
)
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetHomeWallpaperInterval(
|
||||
settingsState.value.homeInterval
|
||||
)
|
||||
}
|
||||
)
|
||||
} ?: run {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
val wallpaperUriSet = wallpapers.map { it.wallpaperUri }.toSet()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
wallpapersInQueue = selectedAlbum.album.wallpapersInQueue.filter { it in wallpaperUriSet },
|
||||
currentWallpaper = selectedAlbum.album.currentWallpaper
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum, null))
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperInterval(settingsState.value.interval))
|
||||
} ?: run {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,17 +154,25 @@ fun PaperizeApp(
|
||||
// Navigate to the startup screen to show the privacy policy and notification screen
|
||||
composable<Startup> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
StartupScreen(
|
||||
onAgree = {
|
||||
@@ -163,17 +189,25 @@ fun PaperizeApp(
|
||||
// Navigate to the notification screen to ask for notification permission
|
||||
composable<Notification> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
NotificationScreen(
|
||||
onAgree = {
|
||||
@@ -187,17 +221,25 @@ fun PaperizeApp(
|
||||
// Navigate to the home screen to view all albums and wallpapers
|
||||
composable<Home> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
HomeScreen(
|
||||
onSettingsClick = { navController.navigate(Settings) },
|
||||
@@ -207,54 +249,116 @@ fun PaperizeApp(
|
||||
onAlbumViewClick = {
|
||||
navController.navigate(AlbumView(it))
|
||||
},
|
||||
onScheduleWallpaperChanger = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperInterval(timeInMinutes))
|
||||
onScheduleWallpaperChanger1 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetHomeWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", timeInMinutes)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
},
|
||||
onStop = {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
},
|
||||
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))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", timeInMinutes)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
onScheduleWallpaperChanger2 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", timeInMinutes)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
onTimeChange1 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetHomeWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.REQUEUE.toString()
|
||||
putExtra("timeInMinutes1", timeInMinutes)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
selectedState.value.selectedAlbum?.album?.homeWallpapersInQueue.let { it1 ->
|
||||
if (it1 != null) { putExtra("currentSize", it1.size) }
|
||||
}
|
||||
selectedState.value.selectedAlbum?.wallpapers?.let { it1 -> putExtra("totalSize", it1.size) }
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
onTimeChange2 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.REQUEUE.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", timeInMinutes)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
selectedState.value.selectedAlbum?.album?.homeWallpapersInQueue.let { it1 ->
|
||||
if (it1 != null) { putExtra("currentSize", it1.size) }
|
||||
}
|
||||
selectedState.value.selectedAlbum?.wallpapers?.let { it1 -> putExtra("totalSize", it1.size) }
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
onStop = {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
}
|
||||
},
|
||||
animate = settingsState.value.animate,
|
||||
interval1 = settingsState.value.homeInterval,
|
||||
interval2 = settingsState.value.lockInterval,
|
||||
lastSetTime = settingsState.value.lastSetTime,
|
||||
nextSetTime = settingsState.value.nextSetTime,
|
||||
selectedAlbum = selectedState.value.selectedAlbum,
|
||||
enableChanger = settingsState.value.enableChanger,
|
||||
darkenPercentage = settingsState.value.darkenPercentage,
|
||||
darken = settingsState.value.darken,
|
||||
homeEnabled = settingsState.value.setHomeWallpaper,
|
||||
lockEnabled = settingsState.value.setLockWallpaper,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
blur = settingsState.value.blur,
|
||||
blurPercentage = settingsState.value.blurPercentage,
|
||||
onToggleChanger = { enableWallpaperChanger ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(enableWallpaperChanger))
|
||||
if (enableWallpaperChanger) {
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", settingsState.value.interval)
|
||||
if (selectedState.value.selectedAlbum!= null && enableWallpaperChanger && (settingsState.value.setHomeWallpaper || settingsState.value.setLockWallpaper)) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
else {
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
@@ -265,19 +369,24 @@ fun PaperizeApp(
|
||||
},
|
||||
onSelectAlbum = {album ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(true))
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(null, album))
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", settingsState.value.interval)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(null, album, settingsState.value.scheduleSeparately))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
},
|
||||
onDarkenPercentage = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDarkenPercentage(it))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
if (settingsState.value.enableChanger) {
|
||||
if (settingsState.value.enableChanger && settingsState.value.darken) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
@@ -287,10 +396,10 @@ fun PaperizeApp(
|
||||
},
|
||||
onDarkCheck = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDarken(it))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
if (settingsState.value.enableChanger) {
|
||||
if (settingsState.value.enableChanger && (settingsState.value.darken && settingsState.value.darkenPercentage < 100)) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
@@ -302,10 +411,10 @@ fun PaperizeApp(
|
||||
onScalingChange = {
|
||||
if (settingsState.value.wallpaperScaling != it) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperScaling(it))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
if (settingsState.value.enableChanger) {
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
@@ -313,22 +422,146 @@ fun PaperizeApp(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onHomeCheckedChange = { enableHome ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetHome(enableHome))
|
||||
if (selectedState.value.selectedAlbum!= null && !enableHome && !settingsState.value.setLockWallpaper) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
selectedState.value.selectedAlbum?.let {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
}
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum!= null && (enableHome && !settingsState.value.setLockWallpaper) || (!enableHome && settingsState.value.setLockWallpaper)) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(false))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", false)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
onLockCheckedChange = { enableLock ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLock(enableLock))
|
||||
if (selectedState.value.selectedAlbum!= null && !enableLock && !settingsState.value.setHomeWallpaper) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
selectedState.value.selectedAlbum?.let {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
}
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum!= null && (enableLock && !settingsState.value.setHomeWallpaper) || (!enableLock && settingsState.value.setHomeWallpaper)) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(false))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", false)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
onScheduleSeparatelyChange = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(it))
|
||||
if (selectedState.value.selectedAlbum!= null && settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", it)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
onBlurChange = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetBlur(it))
|
||||
if (settingsState.value.enableChanger && (settingsState.value.blur && settingsState.value.blurPercentage > 0)) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
onBlurPercentageChange = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetBlurPercentage(it))
|
||||
if (settingsState.value.enableChanger && settingsState.value.blur) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.UPDATE.toString()
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
// Navigate to the add album screen to create a new album and add wallpapers to it
|
||||
composable<AddEdit>(
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {backStackEntry ->
|
||||
val addEdit: AddEdit = backStackEntry.toRoute()
|
||||
@@ -354,17 +587,25 @@ fun PaperizeApp(
|
||||
// Navigate to wallpaper view screen to view individual wallpapers in full screen
|
||||
composable<WallpaperView> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val wallpaperView: WallpaperView = backStackEntry.toRoute()
|
||||
WallpaperViewScreen(
|
||||
@@ -376,17 +617,25 @@ fun PaperizeApp(
|
||||
// Navigate to folder view screen to view wallpapers in a particular folder
|
||||
/*composable<FolderView> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val folderView: FolderView = backStackEntry.toRoute()
|
||||
if (folderView.wallpapers.isNotEmpty()) {
|
||||
@@ -408,17 +657,25 @@ fun PaperizeApp(
|
||||
navArgument("wallpapers") { type = NavType.StringType }
|
||||
),
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val folderName = backStackEntry.arguments?.getString("folderName")
|
||||
val wallpapers = Gson().fromJson(
|
||||
@@ -440,17 +697,25 @@ fun PaperizeApp(
|
||||
// Navigate to the album view screen to view folders and wallpapers in an album
|
||||
composable<AlbumView> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val albumView: AlbumView = backStackEntry.toRoute()
|
||||
val albumWithWallpaper = albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == albumView.initialAlbumName }
|
||||
@@ -487,17 +752,25 @@ fun PaperizeApp(
|
||||
// Navigate to the settings screen to change app settings
|
||||
composable<Settings> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
SettingsScreen(
|
||||
settingsState = settingsViewModel.state,
|
||||
@@ -540,17 +813,25 @@ fun PaperizeApp(
|
||||
// Navigate to the privacy screen to view the privacy policy
|
||||
composable<Privacy> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
PrivacyScreen(
|
||||
onBackClick = { navController.navigateUp() },
|
||||
@@ -559,17 +840,25 @@ fun PaperizeApp(
|
||||
// Navigate to the licenses screen to view the licenses of the libraries used
|
||||
composable<Licenses> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
LicensesScreen(
|
||||
onBackClick = { navController.navigateUp() },
|
||||
|
||||
+5
-8
@@ -55,16 +55,13 @@ fun AddAlbumScreen(
|
||||
}
|
||||
var showSpotlight by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
showSpotlight = false
|
||||
selectionMode = false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** Image picker **/
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
|
||||
+5
-2
@@ -20,6 +20,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
@@ -68,7 +69,8 @@ fun AlbumItem(
|
||||
imageModel = { album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
@@ -90,7 +92,8 @@ fun AlbumItem(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
|
||||
+9
-5
@@ -11,8 +11,8 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -38,6 +38,7 @@ import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
@@ -120,7 +121,8 @@ fun FolderItem(
|
||||
imageModel = { folder.coverUri?.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
@@ -130,7 +132,7 @@ fun FolderItem(
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.height(configuration.screenHeightDp.dp / 4.0f)
|
||||
.aspectRatio(0.8f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
@@ -162,7 +164,8 @@ fun FolderItem(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
Text(
|
||||
@@ -171,7 +174,8 @@ fun FolderItem(
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
|
||||
+15
-2
@@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@@ -32,7 +33,9 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.times
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
@@ -60,6 +63,8 @@ fun WallpaperItem(
|
||||
animate: Boolean = true,
|
||||
darken: Boolean = false,
|
||||
darkenPercentage: Int? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercentage: Int? = null,
|
||||
scaling: ScalingConstants? = null
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
@@ -113,7 +118,7 @@ fun WallpaperItem(
|
||||
Box(modifier = boxModifier) {
|
||||
if (showUri) {
|
||||
val dimension = wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: (dimension.width.toFloat() / dimension.height.toFloat())
|
||||
val imageAspectRatio = aspectRatio ?: ((dimension?.width?.toFloat() ?: 9f) / (dimension?.height?.toFloat() ?: 19.5f))
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri },
|
||||
imageOptions = ImageOptions(
|
||||
@@ -124,6 +129,7 @@ fun WallpaperItem(
|
||||
ScalingConstants.STRETCH -> ContentScale.FillBounds
|
||||
}
|
||||
} else { ContentScale.Crop },
|
||||
requestSize = IntSize(300, 300),
|
||||
alignment = Alignment.Center,
|
||||
colorFilter = if (darken && darkenPercentage != null && darkenPercentage < 100) {
|
||||
ColorFilter.tint(
|
||||
@@ -145,7 +151,14 @@ fun WallpaperItem(
|
||||
.asBitmap()
|
||||
.format(DecodeFormat.PREFER_RGB_565)
|
||||
},
|
||||
modifier = Modifier.aspectRatio(imageAspectRatio).background(if (scaling != null) Color.Black else Color.Transparent),
|
||||
modifier = Modifier
|
||||
.aspectRatio(imageAspectRatio)
|
||||
.background(if (scaling != null) Color.Black else Color.Transparent)
|
||||
.blur(
|
||||
if (blur && blurPercentage != null && blurPercentage > 0 ) {
|
||||
blurPercentage.toFloat().div(100f) * 1.5.dp
|
||||
} else { 0.dp })
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
|
||||
+5
-7
@@ -86,15 +86,13 @@ fun AlbumViewScreen(
|
||||
}
|
||||
)
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
selectionMode = false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
|
||||
+55
-31
@@ -33,27 +33,39 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.Wa
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
onSettingsClick: () -> Unit,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onSetLockWithHome: (Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate : Boolean,
|
||||
interval: Int,
|
||||
setLockWithHome: Boolean,
|
||||
lastSetTime: String?,
|
||||
nextSetTime: String?,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
enableChanger: Boolean,
|
||||
darkenPercentage: Int,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled : Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled : Boolean,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
nextSetTime: String?,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onSettingsClick: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
onScalingChange: (ScalingConstants) -> Unit
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
scheduleSeparately: Boolean,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int
|
||||
) {
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val tabItems = getTabItems()
|
||||
@@ -128,24 +140,36 @@ fun HomeScreen(
|
||||
) { index ->
|
||||
when(index) {
|
||||
0 -> WallpaperScreen(
|
||||
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
|
||||
onStop = onStop,
|
||||
animate = animate,
|
||||
interval = interval,
|
||||
setLockWithHome = setLockWithHome,
|
||||
lastSetTime = lastSetTime,
|
||||
nextSetTime = nextSetTime,
|
||||
onSetLockWithHome = onSetLockWithHome,
|
||||
selectedAlbum = selectedAlbum,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = onToggleChanger,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
darkenPercentage = darkenPercentage,
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
enableChanger = enableChanger,
|
||||
homeEnabled = homeEnabled,
|
||||
interval1 = interval1,
|
||||
interval2 = interval2,
|
||||
lastSetTime = lastSetTime,
|
||||
lockEnabled = lockEnabled,
|
||||
nextSetTime = nextSetTime,
|
||||
onDarkCheck = onDarkCheck,
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
onScheduleWallpaperChanger1 = onScheduleWallpaperChanger1,
|
||||
onScheduleWallpaperChanger2 = onScheduleWallpaperChanger2,
|
||||
onScalingChange = onScalingChange,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onStop = onStop,
|
||||
onToggleChanger = onToggleChanger,
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange
|
||||
selectedAlbum = selectedAlbum,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onTimeChange1 = onTimeChange1,
|
||||
onTimeChange2 = onTimeChange2,
|
||||
blur = blur,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
|
||||
+7
-2
@@ -11,9 +11,14 @@ sealed class SettingsEvent {
|
||||
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
|
||||
data class SetAnimate(val animate: Boolean): SettingsEvent()
|
||||
data class SetDarken(val darken: Boolean): SettingsEvent()
|
||||
data class SetWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetBlur(val blur: Boolean): SettingsEvent()
|
||||
data class SetLock(val lock: Boolean): SettingsEvent()
|
||||
data class SetHome(val home: Boolean): SettingsEvent()
|
||||
data class SetScheduleSeparately(val scheduleSeparately: Boolean): SettingsEvent()
|
||||
data class SetHomeWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetLockWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetDarkenPercentage(val darkenPercentage: Int): SettingsEvent()
|
||||
data class SetLockWithHome(val lockWithHome: Boolean): SettingsEvent()
|
||||
data class SetBlurPercentage(val blurPercentage: Int): SettingsEvent()
|
||||
data class SetChangerToggle(val toggle: Boolean): SettingsEvent()
|
||||
data class SetWallpaperScaling(val scaling: ScalingConstants): SettingsEvent()
|
||||
}
|
||||
+10
-3
@@ -4,15 +4,22 @@ import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_D
|
||||
|
||||
data class SettingsState(
|
||||
val firstLaunch: Boolean = true,
|
||||
// App settings
|
||||
val darkMode: Boolean? = null,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
val interval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val setLockWithHome: Boolean = false,
|
||||
// Wallpaper settings
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null,
|
||||
val enableChanger: Boolean = false,
|
||||
val darkenPercentage: Int = 100,
|
||||
val darken: Boolean = false,
|
||||
val blur: Boolean = false,
|
||||
val blurPercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
|
||||
)
|
||||
+127
-50
@@ -34,25 +34,30 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
init {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val wallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val setLockWithHome = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val darkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val wallpaperScaling = async { ScalingConstants.valueOf(settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING) ?: ScalingConstants.FILL.name) }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
interval = wallpaperInterval.await(),
|
||||
setLockWithHome = setLockWithHome.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
@@ -61,6 +66,11 @@ class SettingsViewModel @Inject constructor (
|
||||
darkenPercentage = darkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
wallpaperScaling = wallpaperScaling.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
blurPercentage = blurPercentage.await()
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
@@ -82,10 +92,7 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.SetChangerToggle -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.toggle) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, false) }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
|
||||
_state.update {
|
||||
it.copy(
|
||||
enableChanger = event.toggle
|
||||
@@ -98,29 +105,38 @@ class SettingsViewModel @Inject constructor (
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val wallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val setLockWithHome = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val darkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 0 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
interval = wallpaperInterval.await(),
|
||||
setLockWithHome = setLockWithHome.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
darkenPercentage = darkenPercentage.await(),
|
||||
darken = darken.await()
|
||||
darken = darken.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
blurPercentage = blurPercentage.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -143,10 +159,7 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.SetDynamicTheming -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.dynamicTheming) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, false) }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, event.dynamicTheming)
|
||||
_state.update {
|
||||
it.copy(
|
||||
dynamicTheming = event.dynamicTheming
|
||||
@@ -157,10 +170,7 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.SetAnimate -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.animate) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, false) }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate)
|
||||
_state.update {
|
||||
it.copy(
|
||||
animate = event.animate
|
||||
@@ -169,7 +179,7 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetWallpaperInterval -> {
|
||||
is SettingsEvent.SetHomeWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
@@ -177,10 +187,10 @@ class SettingsViewModel @Inject constructor (
|
||||
val formattedNextSetTime = time.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, formattedLastSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, formattedNextSetTime)
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
_state.update {
|
||||
it.copy(
|
||||
interval = event.interval,
|
||||
homeInterval = event.interval,
|
||||
lastSetTime = formattedLastSetTime,
|
||||
nextSetTime = formattedNextSetTime
|
||||
)
|
||||
@@ -188,6 +198,47 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLockWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
val formattedLastSetTime = time.format(formatter)
|
||||
val formattedNextSetTime = time.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, formattedLastSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, formattedNextSetTime)
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
_state.update {
|
||||
it.copy(
|
||||
lockInterval = event.interval,
|
||||
lastSetTime = formattedLastSetTime,
|
||||
nextSetTime = formattedNextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHome -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.HOME_WALLPAPER, event.home)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setHomeWallpaper = event.home
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLock -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.LOCK_WALLPAPER, event.lock)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWallpaper = event.lock
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkenPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.DARKEN_PERCENTAGE, event.darkenPercentage)
|
||||
@@ -201,10 +252,7 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.SetDarken -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.darken) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, false) }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darken = event.darken
|
||||
@@ -213,20 +261,6 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLockWithHome -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.lockWithHome) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.SET_LOCK_WITH_HOME, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.SET_LOCK_WITH_HOME, false) }
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWithHome = event.lockWithHome
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetWallpaperScaling -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name)
|
||||
@@ -238,27 +272,63 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetScheduleSeparately -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately)
|
||||
_state.update {
|
||||
it.copy(
|
||||
scheduleSeparately = event.scheduleSeparately
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlur -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blur = event.blur
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlurPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.BLUR_PERCENTAGE, event.blurPercentage)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blurPercentage = event.blurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SET_LOCK_WITH_HOME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SCHEDULE_SEPARATELY)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.BLUR_PERCENTAGE)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = null,
|
||||
dynamicTheming = false,
|
||||
interval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
setLockWithHome = false,
|
||||
firstLaunch = true,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null,
|
||||
@@ -266,7 +336,14 @@ class SettingsViewModel @Inject constructor (
|
||||
enableChanger = false,
|
||||
darkenPercentage = 100,
|
||||
darken = false,
|
||||
wallpaperScaling = ScalingConstants.FILL
|
||||
wallpaperScaling = ScalingConstants.FILL,
|
||||
setHomeWallpaper = false,
|
||||
setLockWallpaper = false,
|
||||
lockInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
homeInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
scheduleSeparately = false,
|
||||
blur = false,
|
||||
blurPercentage = 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -12,11 +12,9 @@ import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
|
||||
|
||||
|
||||
private val LightColors = lightColorScheme(
|
||||
@@ -90,13 +88,14 @@ private val DarkColors = darkColorScheme(
|
||||
*/
|
||||
@Composable
|
||||
fun PaperizeTheme(
|
||||
settingsState: State<SettingsState>,
|
||||
darkMode: Boolean?,
|
||||
dynamicTheming: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val isDarkMode = isDarkMode(darkMode = settingsState.value.darkMode)
|
||||
val isDynamicTheming = isDynamicTheming(dynamicTheming = settingsState.value.dynamicTheming)
|
||||
val isDarkMode = isDarkMode(darkMode = darkMode)
|
||||
val isDynamicTheming = isDynamicTheming(dynamicTheming = dynamicTheming)
|
||||
val dynamicThemingSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
val colors = when {
|
||||
isDynamicTheming && dynamicThemingSupported && isDarkMode -> dynamicDarkColorScheme(context)
|
||||
|
||||
+6
-1
@@ -2,9 +2,14 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
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.settings_screen.SettingsEvent
|
||||
|
||||
sealed class WallpaperEvent {
|
||||
data class UpdateSelectedAlbum(val selectedAlbum: SelectedAlbum?, val album: AlbumWithWallpaperAndFolder?): WallpaperEvent()
|
||||
data class UpdateSelectedAlbum(
|
||||
val selectedAlbum: SelectedAlbum?,
|
||||
val album: AlbumWithWallpaperAndFolder?,
|
||||
val scheduleSeparately: Boolean = false
|
||||
): WallpaperEvent()
|
||||
object Reset : WallpaperEvent()
|
||||
object Refresh : WallpaperEvent()
|
||||
}
|
||||
+175
-119
@@ -34,36 +34,49 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperA
|
||||
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
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SetLockScreenSwitch
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShowLiveWallpaperEnabledDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperScalingRow
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun WallpaperScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onSetLockWithHome: (Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate: Boolean,
|
||||
interval: Int,
|
||||
setLockWithHome: Boolean,
|
||||
lastSetTime: String?,
|
||||
nextSetTime: String?,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
enableChanger: Boolean,
|
||||
darkenPercentage: Int,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled: Boolean,
|
||||
nextSetTime: String?,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
onScalingChange: (ScalingConstants) -> Unit
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
@@ -94,76 +107,87 @@ fun WallpaperScreen(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { padding ->
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(8.dp),
|
||||
modifier = Modifier.fillMaxSize().padding(8.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
item {
|
||||
CurrentSelectedAlbum(
|
||||
selectedAlbum = selectedAlbum,
|
||||
onOpenBottomSheet = {
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) {
|
||||
if (isLiveWallpaperSet(context)) {
|
||||
openDialog.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)
|
||||
}
|
||||
ChangerSelectionRow(
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange
|
||||
)
|
||||
}
|
||||
item {
|
||||
if (homeEnabled || lockEnabled) {
|
||||
CurrentSelectedAlbum(
|
||||
selectedAlbum = selectedAlbum,
|
||||
onOpenBottomSheet = {
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) {
|
||||
if (isLiveWallpaperSet(context)) {
|
||||
openDialog.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 = selectedAlbum != null,
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedAlbum != null) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
@@ -171,33 +195,41 @@ fun WallpaperScreen(
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedAlbum.album.currentWallpaper,
|
||||
checked = setLockWithHome,
|
||||
onCheckedChange = { onSetLockWithHome(it) },
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
animate = true,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedAlbum.album.currentWallpaper,
|
||||
checked = setLockWithHome,
|
||||
onCheckedChange = { onSetLockWithHome(it) },
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
animate = false,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -205,55 +237,51 @@ fun WallpaperScreen(
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
WallpaperScalingRow(
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
WallpaperScalingRow(
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
TimeSliders(
|
||||
timeInMinutes = interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
timeInMinutes1 = interval1,
|
||||
timeInMinutes2 = interval2,
|
||||
onTimeChange1 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
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 }
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
TimeSliders(
|
||||
timeInMinutes = interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
timeInMinutes1 = interval1,
|
||||
timeInMinutes2 = interval2,
|
||||
onTimeChange1 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
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 }
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -261,7 +289,7 @@ fun WallpaperScreen(
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
@@ -275,7 +303,7 @@ fun WallpaperScreen(
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
@@ -286,8 +314,36 @@ fun WallpaperScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
BlurSwitchAndSlider(
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (openBottomSheet) {
|
||||
if (((homeEnabled || lockEnabled)) && openBottomSheet) {
|
||||
AlbumBottomSheet(
|
||||
albums = albumState.value.albumsWithWallpapers,
|
||||
currentSelectedAlbum = selectedAlbum,
|
||||
@@ -295,7 +351,7 @@ fun WallpaperScreen(
|
||||
onSelect = { album ->
|
||||
openBottomSheet = false
|
||||
onSelectAlbum(album)
|
||||
onScheduleWallpaperChanger(interval)
|
||||
onScheduleWallpaperChanger1(interval1)
|
||||
},
|
||||
animate = animate
|
||||
)
|
||||
|
||||
+6
-3
@@ -61,11 +61,14 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
)
|
||||
}
|
||||
}.toList()
|
||||
val shuffledWallpapers = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val shuffledWallpapers1 = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val shuffledWallpapers2 = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = event.album.album.copy(
|
||||
wallpapersInQueue = shuffledWallpapers,
|
||||
currentWallpaper = shuffledWallpapers.firstOrNull()
|
||||
homeWallpapersInQueue = shuffledWallpapers1,
|
||||
lockWallpapersInQueue = shuffledWallpapers2,
|
||||
currentHomeWallpaper = shuffledWallpapers1.firstOrNull(),
|
||||
currentLockWallpaper = if (event.scheduleSeparately) shuffledWallpapers2.firstOrNull() else shuffledWallpapers1.firstOrNull(),
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
|
||||
+2
@@ -28,6 +28,7 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -105,6 +106,7 @@ fun AlbumBottomSheet(
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Composable that displays a switch and slider for the user to adjust the blur effect of the wallpaper
|
||||
*/
|
||||
@Composable
|
||||
fun BlurSwitchAndSlider(
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var percentage by rememberSaveable { mutableFloatStateOf(blurPercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = if (animate) {
|
||||
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
|
||||
} else { Modifier }
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.change_blur),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = blur,
|
||||
onCheckedChange = onBlurChange
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = blur,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Slider(
|
||||
value = percentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (blur) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Slider(
|
||||
value = percentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun ChangerSelectionRow(
|
||||
homeEnabled : Boolean,
|
||||
lockEnabled : Boolean,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
MultiChoiceSegmentedButtonRow (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(start = 16.dp, end = 16.dp,))
|
||||
) {
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2),
|
||||
onCheckedChange = onHomeCheckedChange,
|
||||
checked = homeEnabled
|
||||
) {
|
||||
Text(text = stringResource(R.string.home_screen_btn))
|
||||
}
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),
|
||||
onCheckedChange = onLockCheckedChange,
|
||||
checked = lockEnabled
|
||||
) {
|
||||
Text(stringResource(R.string.lock_screen_btn))
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -17,7 +17,6 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -70,10 +69,10 @@ fun CurrentAndNextChange(
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(PaddingValues(16.dp, 8.dp, 8.dp, 8.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
||||
+2
@@ -33,6 +33,7 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -100,6 +101,7 @@ fun CurrentSelectedAlbum(
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
|
||||
+4
-6
@@ -66,9 +66,7 @@ fun DarkenSwitchAndSlider(
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = if (animate) {
|
||||
Modifier.animateContentSize(
|
||||
animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing)
|
||||
)
|
||||
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
|
||||
} else { Modifier }
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
@@ -77,7 +75,7 @@ fun DarkenSwitchAndSlider(
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.adjust_brightness),
|
||||
text = stringResource(R.string.change_brightness),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
@@ -99,7 +97,7 @@ fun DarkenSwitchAndSlider(
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.brightness_percentage, percentage.roundToInt()),
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
@@ -125,7 +123,7 @@ fun DarkenSwitchAndSlider(
|
||||
if (darken) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.brightness_percentage, percentage.roundToInt()),
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
|
||||
-231
@@ -1,231 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
|
||||
/**
|
||||
* SetLockScreenSwitch is a composable that displays a switch to set the wallpaper as the lock screen wallpaper
|
||||
* Also shows a preview of lock and home screen when enabled along with brightness added
|
||||
*/
|
||||
@Composable
|
||||
fun SetLockScreenSwitch(
|
||||
albumUri : String?,
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
scaling: ScalingConstants?
|
||||
) {
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = remember {
|
||||
if (animate) {
|
||||
Modifier.animateContentSize(
|
||||
animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing)
|
||||
)
|
||||
} else { Modifier }
|
||||
}
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.set_as_lock_screen),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = checked,
|
||||
onCheckedChange = onCheckedChange
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = checked && albumUri != null,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
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,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
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,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
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,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+233
-57
@@ -9,6 +9,7 @@ import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@@ -21,10 +22,13 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -41,6 +45,7 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -50,16 +55,25 @@ import kotlinx.coroutines.launch
|
||||
*/
|
||||
@Composable
|
||||
fun TimeSliders(
|
||||
onTimeChange: (Int, Int, Int) -> Unit,
|
||||
timeInMinutes: Int,
|
||||
timeInMinutes1: Int,
|
||||
timeInMinutes2: Int,
|
||||
showInterval: Boolean,
|
||||
animate: Boolean,
|
||||
onShowIntervalChange: (Boolean) -> Unit
|
||||
onShowIntervalChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int, Int, Int) -> Unit,
|
||||
onTimeChange2: (Int, Int, Int) -> Unit,
|
||||
lockEnabled: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
) {
|
||||
val view = LocalView.current
|
||||
var days by rememberSaveable { mutableFloatStateOf((timeInMinutes / (24 * 60)).toFloat()) }
|
||||
var hours by rememberSaveable { mutableFloatStateOf(((timeInMinutes % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes by rememberSaveable { mutableFloatStateOf((timeInMinutes % 60).toFloat()) }
|
||||
var days1 by rememberSaveable { mutableFloatStateOf((timeInMinutes1 / (24 * 60)).toFloat()) }
|
||||
var hours1 by rememberSaveable { mutableFloatStateOf(((timeInMinutes1 % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes1 by rememberSaveable { mutableFloatStateOf((timeInMinutes1 % 60).toFloat()) }
|
||||
var days2 by rememberSaveable { mutableFloatStateOf((timeInMinutes2 / (24 * 60)).toFloat()) }
|
||||
var hours2 by rememberSaveable { mutableFloatStateOf(((timeInMinutes2 % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes2 by rememberSaveable { mutableFloatStateOf((timeInMinutes2 % 60).toFloat()) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalView.current
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
@@ -82,25 +96,54 @@ fun TimeSliders(
|
||||
Column (
|
||||
modifier = columnModifier
|
||||
) {
|
||||
val totalMinutes = (days.toInt() * 24 * 60) + (hours.toInt() * 60) + minutes.toInt()
|
||||
val displayDays = totalMinutes / (24 * 60)
|
||||
val displayHours = (totalMinutes % (24 * 60)) / 60
|
||||
val displayMinutes = totalMinutes % 60
|
||||
val formattedDays = if (displayDays > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays, displayDays)
|
||||
val totalMinutes1 = (days1.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
val displayDays1 = totalMinutes1 / (24 * 60)
|
||||
val displayHours1 = (totalMinutes1 % (24 * 60)) / 60
|
||||
val displayMinutes1 = totalMinutes1 % 60
|
||||
|
||||
val formattedDays1 = if (displayDays1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays1, displayDays1)
|
||||
} else {""}
|
||||
|
||||
val formattedHours = if (displayHours > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours, displayHours)
|
||||
val formattedHours1 = if (displayHours1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours1, displayHours1)
|
||||
} else {""}
|
||||
|
||||
val formattedMinutes = if (displayMinutes > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes, displayMinutes)
|
||||
val formattedMinutes1 = if (displayMinutes1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes1, displayMinutes1)
|
||||
} else {""}
|
||||
|
||||
val formattedTime = stringResource(
|
||||
R.string.interval,
|
||||
listOf(formattedDays, formattedHours, formattedMinutes).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
val formattedTime1 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_home
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays1, formattedHours1, formattedMinutes1).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
val totalMinutes2 = (days2.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
val displayDays2 = totalMinutes2 / (24 * 60)
|
||||
val displayHours2 = (totalMinutes2 % (24 * 60)) / 60
|
||||
val displayMinutes2 = totalMinutes2 % 60
|
||||
|
||||
val formattedDays2 = if (displayDays2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays2, displayDays2)
|
||||
} else {""}
|
||||
|
||||
val formattedHours2 = if (displayHours2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours2, displayHours2)
|
||||
} else {""}
|
||||
|
||||
val formattedMinutes2 = if (displayMinutes2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes2, displayMinutes2)
|
||||
} else {""}
|
||||
|
||||
val formattedTime2 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_lock
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays2, formattedHours2, formattedMinutes2).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
Row (
|
||||
@@ -110,20 +153,33 @@ fun TimeSliders(
|
||||
) {
|
||||
Spacer(modifier = Modifier.width(32.dp))
|
||||
Text(
|
||||
text = formattedTime,
|
||||
text = if (showInterval) {
|
||||
formattedTime1
|
||||
} else {
|
||||
if (scheduleSeparately) {
|
||||
stringResource(R.string.interval_text)
|
||||
} else {
|
||||
formattedTime1
|
||||
}
|
||||
},
|
||||
fontWeight = FontWeight.W500,
|
||||
)
|
||||
IconButton(
|
||||
onClick = { onShowIntervalChange(!showInterval) },
|
||||
) {
|
||||
Icon(imageVector = Icons.Filled.ArrowDropDown, contentDescription = "Show interval sliders")
|
||||
Icon(imageVector = Icons.Filled.ArrowDropDown, contentDescription = stringResource(R.string.show_interval_sliders))
|
||||
}
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = showInterval,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
enter = expandVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
@@ -133,18 +189,19 @@ fun TimeSliders(
|
||||
) {
|
||||
Column {
|
||||
Slider(
|
||||
value = days,
|
||||
value = days1,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days = newDays
|
||||
val totalMinute = (newDays.toInt() * 24 * 60) + (hours.toInt() * 60) + minutes.toInt()
|
||||
if (totalMinute < 15) {
|
||||
minutes = 15f - (hours.toInt() * 60)
|
||||
days1 = newDays
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(newDays.toInt(), hours.toInt(), minutes.toInt())
|
||||
onTimeChange1(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
@@ -153,18 +210,19 @@ fun TimeSliders(
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours,
|
||||
value = hours1,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours = newHours
|
||||
val totalMinute = (days.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes.toInt()
|
||||
if (totalMinute < 15) {
|
||||
minutes = 15f - (newHours.toInt() * 60)
|
||||
hours1 = newHours
|
||||
val totalMinute =
|
||||
(days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(days.toInt(), newHours.toInt(), minutes.toInt())
|
||||
onTimeChange1(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
@@ -173,24 +231,142 @@ fun TimeSliders(
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes,
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes = if (days.toInt() == 0 && hours.toInt() == 0 && newMinutes < 15) {
|
||||
15f
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
minutes1 =
|
||||
if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(days.toInt(), hours.toInt(), minutes.toInt())
|
||||
onTimeChange1(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
steps = 60,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (homeEnabled && lockEnabled) {
|
||||
AnimatedVisibility(
|
||||
visible = scheduleSeparately,
|
||||
enter = expandVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
),
|
||||
exit = shrinkVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = formattedTime2,
|
||||
fontWeight = FontWeight.W500,
|
||||
)
|
||||
Slider(
|
||||
value = days2,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days2 = newDays
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours2.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
newDays.toInt(),
|
||||
hours2.toInt(),
|
||||
minutes2.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours2,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours2 = newHours
|
||||
val totalMinute =
|
||||
(days2.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
days2.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes2.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes2,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes2 =
|
||||
if (days2.toInt() == 0 && hours2.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
days2.toInt(),
|
||||
hours2.toInt(),
|
||||
minutes2.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
steps = 60,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Text(text = stringResource(R.string.individual_scheduling), fontWeight = FontWeight.W500)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Switch(
|
||||
checked = scheduleSeparately,
|
||||
onCheckedChange = onScheduleSeparatelyChange
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
@@ -198,18 +374,18 @@ fun TimeSliders(
|
||||
else {
|
||||
if (showInterval) {
|
||||
Slider(
|
||||
value = days,
|
||||
value = days1,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days = newDays
|
||||
val totalMinute = (newDays.toInt() * 24 * 60) + (hours.toInt() * 60) + minutes.toInt()
|
||||
if (totalMinute < 15) {
|
||||
minutes = 15f - (hours.toInt() * 60)
|
||||
days1 = newDays
|
||||
val totalMinute = (newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(newDays.toInt(), hours.toInt(), minutes.toInt())
|
||||
onTimeChange1(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
@@ -218,18 +394,18 @@ fun TimeSliders(
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours,
|
||||
value = hours1,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours = newHours
|
||||
val totalMinute = (days.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes.toInt()
|
||||
if (totalMinute < 15) {
|
||||
minutes = 15f - (newHours.toInt() * 60)
|
||||
hours1 = newHours
|
||||
val totalMinute = (days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(days.toInt(), newHours.toInt(), minutes.toInt())
|
||||
onTimeChange1(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
@@ -238,18 +414,18 @@ fun TimeSliders(
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes,
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes = if (days.toInt() == 0 && hours.toInt() == 0 && newMinutes < 15) {
|
||||
15f
|
||||
minutes1 = if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(days.toInt(), hours.toInt(), minutes.toInt())
|
||||
onTimeChange1(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
|
||||
/**
|
||||
* SetLockScreenSwitch is a composable that displays a switch to set the wallpaper as the lock screen wallpaper
|
||||
* Also shows a preview of lock and home screen when enabled along with brightness added
|
||||
*/
|
||||
@Composable
|
||||
fun WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
homeEnabled: Boolean,
|
||||
lockEnabled: Boolean,
|
||||
scaling: ScalingConstants,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
) {
|
||||
var selectedIndex by rememberSaveable {
|
||||
mutableIntStateOf(
|
||||
when (scaling) {
|
||||
ScalingConstants.FILL -> 0
|
||||
ScalingConstants.FIT -> 1
|
||||
ScalingConstants.STRETCH -> 2
|
||||
}
|
||||
)
|
||||
}
|
||||
val options = listOf(
|
||||
stringResource(R.string.fill),
|
||||
stringResource(R.string.fit),
|
||||
stringResource(R.string.stretch)
|
||||
)
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val modifier = if (lockEnabled && homeEnabled) {
|
||||
Modifier.weight(1f).padding(8.dp)
|
||||
} else {
|
||||
Modifier.fillMaxSize(0.5f).padding(8.dp)
|
||||
}
|
||||
|
||||
if (lockEnabled) {
|
||||
Column(
|
||||
modifier = modifier,
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (currentLockWallpaper != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = currentLockWallpaper,
|
||||
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,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (homeEnabled) {
|
||||
Column(
|
||||
modifier = modifier,
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (currentHomeWallpaper != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = currentHomeWallpaper,
|
||||
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,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SingleChoiceSegmentedButtonRow (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(start = 8.dp, end = 8.dp, bottom = 16.dp))
|
||||
) {
|
||||
options.forEachIndexed { index, label ->
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
|
||||
onClick = {
|
||||
selectedIndex = index
|
||||
onScalingChange(
|
||||
when (index) {
|
||||
0 -> ScalingConstants.FILL
|
||||
1 -> ScalingConstants.FIT
|
||||
2 -> ScalingConstants.STRETCH
|
||||
else -> ScalingConstants.FILL
|
||||
}
|
||||
) },
|
||||
selected = index == selectedIndex
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Icon(
|
||||
painter = when (index) {
|
||||
0 -> painterResource(id = R.drawable.fill)
|
||||
1 -> painterResource(id = R.drawable.fit)
|
||||
2 -> painterResource(id = R.drawable.stretch)
|
||||
else -> painterResource(id = R.drawable.fill)
|
||||
},
|
||||
contentDescription = null,
|
||||
tint = Color.Unspecified,
|
||||
modifier = Modifier.size(40.dp)
|
||||
)
|
||||
Text(text = label, maxLines = 1, overflow = TextOverflow.Ellipsis )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
|
||||
/**
|
||||
* Row for selecting the scaling of the wallpaper
|
||||
*/
|
||||
@Composable
|
||||
fun WallpaperScalingRow(
|
||||
scaling: ScalingConstants,
|
||||
onScalingChange: (ScalingConstants) -> Unit
|
||||
) {
|
||||
var selectedIndex by rememberSaveable {
|
||||
mutableIntStateOf(
|
||||
when (scaling) {
|
||||
ScalingConstants.FILL -> 0
|
||||
ScalingConstants.FIT -> 1
|
||||
ScalingConstants.STRETCH -> 2
|
||||
}
|
||||
)
|
||||
}
|
||||
val options = listOf(
|
||||
stringResource(R.string.fill),
|
||||
stringResource(R.string.fit),
|
||||
stringResource(R.string.stretch)
|
||||
)
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column {
|
||||
Row (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(top = 16.dp, bottom = 4.dp)),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.wallpaper_scaling),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
}
|
||||
SingleChoiceSegmentedButtonRow (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(start = 16.dp, end = 16.dp, top = 4.dp, bottom = 16.dp))
|
||||
) {
|
||||
options.forEachIndexed { index, label ->
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
|
||||
onClick = {
|
||||
selectedIndex = index
|
||||
onScalingChange(
|
||||
when (index) {
|
||||
0 -> ScalingConstants.FILL
|
||||
1 -> ScalingConstants.FIT
|
||||
2 -> ScalingConstants.STRETCH
|
||||
else -> ScalingConstants.FILL
|
||||
}
|
||||
) },
|
||||
selected = index == selectedIndex
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Icon(
|
||||
painter = when (index) {
|
||||
0 -> painterResource(id = R.drawable.fill)
|
||||
1 -> painterResource(id = R.drawable.fit)
|
||||
2 -> painterResource(id = R.drawable.stretch)
|
||||
else -> painterResource(id = R.drawable.fill)
|
||||
},
|
||||
contentDescription = null,
|
||||
tint = Color.Unspecified,
|
||||
modifier = Modifier.size(36.dp)
|
||||
)
|
||||
Text(text = label)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -18,10 +18,8 @@ class WallpaperBootReceiver : BroadcastReceiver() {
|
||||
val serviceIntent = Intent(context, WallpaperService::class.java)
|
||||
serviceIntent.action = WallpaperService.Actions.START.toString()
|
||||
runBlocking {
|
||||
val timeInMinutes = settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val setLockWithHome = settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
|
||||
val timeInMinutes = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
serviceIntent.putExtra("timeInMinutes", timeInMinutes)
|
||||
serviceIntent.putExtra("setLockWithHome", setLockWithHome)
|
||||
}
|
||||
context.startForegroundService(serviceIntent)
|
||||
}
|
||||
|
||||
+442
-152
@@ -22,6 +22,7 @@ import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.blurBitmap
|
||||
import com.anthonyla.paperize.core.calculateInSampleSize
|
||||
import com.anthonyla.paperize.core.darkenBitmap
|
||||
import com.anthonyla.paperize.core.fillBitmap
|
||||
@@ -50,14 +51,19 @@ class WallpaperService: Service() {
|
||||
@Inject lateinit var selectedRepository: SelectedAlbumRepository
|
||||
@Inject lateinit var albumRepository: AlbumRepository
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private lateinit var runnableCode: Runnable
|
||||
private var timeInMinutes: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private val handler1 = Handler(Looper.getMainLooper())
|
||||
private val handler2 = Handler(Looper.getMainLooper())
|
||||
private lateinit var runnableCode1: Runnable
|
||||
private lateinit var runnableCode2: Runnable
|
||||
private var timeInMinutes1: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private var timeInMinutes2: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private var scheduleSeparately: Boolean = false
|
||||
|
||||
enum class Actions {
|
||||
START,
|
||||
REQUEUE,
|
||||
STOP,
|
||||
UPDATE,
|
||||
UPDATE
|
||||
}
|
||||
|
||||
override fun onBind(p0: Intent?): IBinder? {
|
||||
@@ -69,17 +75,31 @@ class WallpaperService: Service() {
|
||||
*/
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
startForeground(1, createNotification(0, 0))
|
||||
runnableCode = object : Runnable {
|
||||
startForeground(1, createNotification())
|
||||
runnableCode1 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService)
|
||||
changeWallpaper(this@WallpaperService, true)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler.postDelayed(self, timeInMinutes * 60 * 1000L)
|
||||
handler1.postDelayed(self, timeInMinutes1 * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
runnableCode2 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, false)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler2.postDelayed(self, timeInMinutes2 * 60 * 1000L + 10000)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,26 +110,123 @@ class WallpaperService: Service() {
|
||||
* Start the service and schedule the wallpaper change
|
||||
*/
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
handler.removeCallbacks(runnableCode)
|
||||
when(intent?.action) {
|
||||
Actions.START.toString() -> {
|
||||
timeInMinutes = intent.getIntExtra("timeInMinutes", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
// Schedule the next wallpaper change
|
||||
runnableCode = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler.postDelayed(self, timeInMinutes * 60 * 1000L)
|
||||
handler1.removeCallbacks(runnableCode1)
|
||||
handler2.removeCallbacks(runnableCode2)
|
||||
timeInMinutes1 = intent.getIntExtra("timeInMinutes1", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
timeInMinutes2 = intent.getIntExtra("timeInMinutes2", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
|
||||
if (!scheduleSeparately) {
|
||||
runnableCode1 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, null)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler1.postDelayed(self, timeInMinutes1 * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler1.postDelayed(runnableCode1, 1000)
|
||||
}
|
||||
else {
|
||||
runnableCode1 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, true)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler1.postDelayed(self, timeInMinutes1 * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler1.postDelayed(runnableCode1, 1000)
|
||||
runnableCode2 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, false)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler2.postDelayed(self, timeInMinutes2 * 60 * 1000L + 10000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler2.postDelayed(runnableCode2, 5000)
|
||||
}
|
||||
}
|
||||
Actions.REQUEUE.toString() -> {
|
||||
handler1.removeCallbacks(runnableCode1)
|
||||
handler2.removeCallbacks(runnableCode2)
|
||||
timeInMinutes1 = intent.getIntExtra("timeInMinutes1", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
timeInMinutes2 = intent.getIntExtra("timeInMinutes2", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
if (!scheduleSeparately) {
|
||||
runnableCode1 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, null)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler1.postDelayed(self, timeInMinutes1 * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler1.postDelayed(runnableCode1, timeInMinutes1 * 60 * 1000L)
|
||||
}
|
||||
else {
|
||||
runnableCode1 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, true)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler1.postDelayed(self, timeInMinutes1 * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler1.postDelayed(runnableCode1, timeInMinutes1 * 60 * 1000L)
|
||||
runnableCode2 = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService, false)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler2.postDelayed(self, timeInMinutes2 * 60 * 1000L + 10000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler2.postDelayed(runnableCode2, timeInMinutes2 * 60 * 1000L + 10000)
|
||||
}
|
||||
handler.postDelayed(runnableCode, 3000)
|
||||
}
|
||||
Actions.UPDATE.toString() -> {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
@@ -121,6 +238,8 @@ class WallpaperService: Service() {
|
||||
}
|
||||
}
|
||||
Actions.STOP.toString() -> {
|
||||
handler1.removeCallbacks(runnableCode1)
|
||||
handler2.removeCallbacks(runnableCode2)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, "")
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, "")
|
||||
@@ -136,7 +255,8 @@ class WallpaperService: Service() {
|
||||
*/
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
handler.removeCallbacks(runnableCode)
|
||||
handler1.removeCallbacks(runnableCode1)
|
||||
handler2.removeCallbacks(runnableCode2)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, "")
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, "")
|
||||
@@ -146,12 +266,12 @@ class WallpaperService: Service() {
|
||||
/**
|
||||
* Creates a notification for the wallpaper service
|
||||
*/
|
||||
private fun createNotification(current: Int = 0, total: Int = 0): Notification {
|
||||
private fun createNotification(): Notification {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return NotificationCompat.Builder(this, "wallpaper_service_channel")
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(resources.getQuantityString(R.plurals.notification_content_text, total, current, total, formatTime(timeInMinutes)))
|
||||
.setContentText(getString(R.string.paperize_is_running))
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build()
|
||||
@@ -161,103 +281,66 @@ class WallpaperService: Service() {
|
||||
* Changes the wallpaper to the next wallpaper in the queue of the selected album
|
||||
* If none left, reshuffle the wallpapers and pick the first one
|
||||
*/
|
||||
private suspend fun changeWallpaper(context: Context) {
|
||||
private suspend fun changeWallpaper(context: Context, setHomeOrLock: Boolean? = null) {
|
||||
try {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(
|
||||
SettingsConstants.NEXT_SET_TIME,
|
||||
time.plusMinutes(timeInMinutes.toLong()).format(formatter)
|
||||
)
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)
|
||||
?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val setLockWithHome =
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage =
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum == null) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
else {
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
|
||||
val toggled = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false
|
||||
if (!toggled || (!setHome && !setLock)) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(
|
||||
SettingsConstants.NEXT_SET_TIME,
|
||||
time.plusMinutes(timeInMinutes1.toLong()).format(formatter)
|
||||
)
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false
|
||||
val blurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0
|
||||
|
||||
selectedAlbum.let { it ->
|
||||
var wallpaper = it.album.wallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
val notification =
|
||||
createNotification(it.album.wallpapersInQueue.size, it.wallpapers.size)
|
||||
val notificationManager =
|
||||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
if (!setWallpaper(
|
||||
context,
|
||||
wallpaper.toUri(),
|
||||
setLockWithHome,
|
||||
darken,
|
||||
darkenPercentage,
|
||||
scaling
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = it.album.wallpapersInQueue.drop(
|
||||
1
|
||||
),
|
||||
currentWallpaper = null
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = it.album.wallpapersInQueue.drop(1),
|
||||
currentWallpaper = wallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val notification =
|
||||
createNotification(it.wallpapers.size, it.wallpapers.size)
|
||||
val notificationManager =
|
||||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (setHomeOrLock != null) {
|
||||
var wallpaper = if (setHomeOrLock) it.album.homeWallpapersInQueue.firstOrNull() else it.album.lockWallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context,
|
||||
wallpaper.toUri(),
|
||||
setLockWithHome,
|
||||
darken,
|
||||
darkenPercentage,
|
||||
scaling
|
||||
)
|
||||
) {
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = it.album.wallpapersInQueue.drop(
|
||||
1
|
||||
),
|
||||
currentWallpaper = null
|
||||
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
@@ -266,14 +349,153 @@ class WallpaperService: Service() {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = newWallpaperInQueue.drop(1),
|
||||
currentWallpaper = wallpaper
|
||||
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
onDestroy()
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else { onDestroy() }
|
||||
}
|
||||
}
|
||||
else {
|
||||
var wallpaper = it.album.homeWallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
|
||||
currentHomeWallpaper = wallpaper,
|
||||
currentLockWallpaper = wallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = newWallpaperInQueue.drop(1),
|
||||
currentHomeWallpaper = wallpaper,
|
||||
currentLockWallpaper = wallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else { onDestroy() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,35 +507,53 @@ class WallpaperService: Service() {
|
||||
|
||||
private suspend fun updateCurrentWallpaper(context: Context) {
|
||||
try {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, time.plusMinutes(timeInMinutes.toLong()).format(formatter))
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val setLockWithHome = settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum == null) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
else {
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false
|
||||
if (!setHome && !setLock) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, time.plusMinutes(timeInMinutes1.toLong()).format(formatter))
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false
|
||||
val blurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0
|
||||
|
||||
selectedAlbum.let { it ->
|
||||
val wallpaper = it.album.currentWallpaper
|
||||
if (wallpaper != null) {
|
||||
val notification = createNotification(it.album.wallpapersInQueue.size, it.wallpapers.size)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
if (!setWallpaper(context, wallpaper.toUri(), setLockWithHome, darken, darkenPercentage, scaling)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper }
|
||||
val wallpaper1 = it.album.currentHomeWallpaper
|
||||
val wallpaper2 = it.album.currentLockWallpaper
|
||||
if (wallpaper1 != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper1.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = true,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper1 }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = it.album.wallpapersInQueue.drop(1),
|
||||
currentWallpaper = null
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 },
|
||||
currentHomeWallpaper = null
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
@@ -322,6 +562,41 @@ class WallpaperService: Service() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wallpaper2 != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper2.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = false,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper2 }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 },
|
||||
currentLockWallpaper = null
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wallpaper1 != null || wallpaper2 != null) {
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -332,10 +607,20 @@ class WallpaperService: Service() {
|
||||
/**
|
||||
* Sets the wallpaper to the given uri
|
||||
*/
|
||||
private fun setWallpaper(context: Context, wallpaper: Uri, setLockWithHome: Boolean, darken: Boolean, percent: Int, scaling: ScalingConstants): Boolean {
|
||||
private fun setWallpaper(
|
||||
context: Context,
|
||||
wallpaper: Uri,
|
||||
darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
setHome: Boolean, setLock: Boolean,
|
||||
setLockOrHome: Boolean? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercent: Int
|
||||
): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
try {
|
||||
val imageSize = wallpaper.getImageDimensions(context)
|
||||
val imageSize = wallpaper.getImageDimensions(context) ?: return false
|
||||
val aspectRatio = imageSize.height.toFloat() / imageSize.width.toFloat()
|
||||
val device = context.resources.displayMetrics
|
||||
val targetWidth = min(4 * device.widthPixels, imageSize.width)
|
||||
@@ -345,11 +630,13 @@ class WallpaperService: Service() {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaper)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
decoder.setTargetSize(targetWidth, targetHeight)
|
||||
decoder.isMutableRequired = true
|
||||
}
|
||||
} else {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = calculateInSampleSize(imageSize, targetWidth, targetHeight)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
@@ -357,12 +644,18 @@ class WallpaperService: Service() {
|
||||
|
||||
if (bitmap == null) return false
|
||||
else {
|
||||
processBitmap(device, bitmap, darken, percent, scaling)?.let {
|
||||
image -> wallpaperManager.setBitmap(image, null, true, when (setLockWithHome) {
|
||||
true -> WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM
|
||||
false -> WallpaperManager.FLAG_SYSTEM
|
||||
})
|
||||
processBitmap(device, bitmap, darken, darkenPercent, scaling, blur, blurPercent)?.let { image ->
|
||||
when {
|
||||
setLockOrHome == true -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
setLockOrHome == false -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
setHome && setLock -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM)
|
||||
setHome -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
setLock -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
else -> {}
|
||||
}
|
||||
image.recycle()
|
||||
}
|
||||
bitmap.recycle()
|
||||
return true
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
@@ -371,28 +664,20 @@ class WallpaperService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the time in minutes to a human readable format
|
||||
*/
|
||||
private fun formatTime(timeInMinutes: Int): String {
|
||||
val days = timeInMinutes / (24 * 60)
|
||||
val hours = (timeInMinutes % (24 * 60)) / 60
|
||||
val minutes = timeInMinutes % 60
|
||||
|
||||
val formattedDays = if (days > 0) resources.getQuantityString(R.plurals.days, days, days) else ""
|
||||
val formattedHours = if (hours > 0) resources.getQuantityString(R.plurals.hours, hours, hours) else ""
|
||||
val formattedMinutes = if (minutes > 0) resources.getQuantityString(R.plurals.minutes, minutes, minutes) else ""
|
||||
|
||||
return listOf(formattedDays, formattedHours, formattedMinutes).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
}
|
||||
|
||||
/**
|
||||
* Darkens the bitmap by the given percentage and returns it
|
||||
* 0 - lightest, 100 - darkest
|
||||
*/
|
||||
private fun processBitmap(device: DisplayMetrics, source: Bitmap, darken: Boolean, percent: Int, scaling: ScalingConstants): Bitmap? {
|
||||
private fun processBitmap(
|
||||
device: DisplayMetrics,
|
||||
source: Bitmap, darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
blur: Boolean,
|
||||
blurPercent: Int
|
||||
): Bitmap? {
|
||||
try {
|
||||
var processedBitmap = source.copy(Bitmap.Config.ARGB_8888, true)
|
||||
var processedBitmap = source
|
||||
|
||||
// Apply wallpaper scaling effects
|
||||
processedBitmap = when (scaling) {
|
||||
@@ -402,8 +687,13 @@ class WallpaperService: Service() {
|
||||
}
|
||||
|
||||
// Apply brightness effect
|
||||
if (darken && percent < 100) {
|
||||
processedBitmap = darkenBitmap(processedBitmap, percent, device.widthPixels, device.heightPixels)
|
||||
if (darken && darkenPercent < 100) {
|
||||
processedBitmap = darkenBitmap(processedBitmap, darkenPercent)
|
||||
}
|
||||
|
||||
// Apply blur effect
|
||||
if (blur && blurPercent > 0) {
|
||||
processedBitmap = blurBitmap(processedBitmap, blurPercent)
|
||||
}
|
||||
return processedBitmap
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in new issue
Block a user