Updated auto-restart alarm manager

This commit is contained in:
Anthonyy232 committed 2024-08-08 22:59:05 -07:00
1 parent cd1ed25ba1
commit 7823fe0327
4 files changed
+59 -11

No files matched your search

@@ -115,9 +115,52 @@ class MainActivity : ComponentActivity() {
WallpaperAlarmItem(
homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false,
setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false,
scheduleSeparately = shouldScheduleSeparately
), null, true, true
),
origin = null,
changeImmediate = true,
cancelImmediate = true
)
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
val selectedState = wallpaperScreenViewModel.state.value
val currentHomeAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName }
val currentLockAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName }
when {
settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> {
if (currentHomeAlbum != null && currentLockAlbum != null) {
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
))
}
}
!settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> {
if (currentHomeAlbum != null && currentLockAlbum != null) {
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
currentLockWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
))
}
}
settingsState.value.setHomeWallpaper -> {
if (currentHomeAlbum != null) {
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
currentLockWallpaper = if (settingsState.value.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
))
}
}
settingsState.value.setLockWallpaper -> {
if (currentLockAlbum != null) {
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
currentHomeWallpaper = if (settingsState.value.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri,
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
))
}
}
}
}
}
}
@@ -379,40 +379,40 @@ fun PaperizeApp(
},
onSelectAlbum = {album, lock, home ->
val notSameAlbum = settingsState.value.homeAlbumName != settingsState.value.lockAlbumName
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
when {
lock && home -> {
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(
album = album,
deleteAlbumName = if (notSameAlbum) settingsState.value.lockAlbumName else null)
)
settingsViewModel.onEvent(SettingsEvent.SetAlbumName(
homeAlbumName = album.album.initialAlbumName,
lockAlbumName = album.album.initialAlbumName,
))
}
lock -> {
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(
album = album,
deleteAlbumName = if (notSameAlbum) settingsState.value.lockAlbumName else null)
)
}
lock -> {
settingsViewModel.onEvent(SettingsEvent.SetAlbumName(
homeAlbumName = null,
lockAlbumName = album.album.initialAlbumName,
))
}
home -> {
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(
album = album,
deleteAlbumName = if (notSameAlbum) settingsState.value.homeAlbumName else null)
deleteAlbumName = if (notSameAlbum) settingsState.value.lockAlbumName else null)
)
}
home -> {
settingsViewModel.onEvent(SettingsEvent.SetAlbumName(
homeAlbumName = album.album.initialAlbumName,
lockAlbumName = null,
))
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(
album = album,
deleteAlbumName = if (notSameAlbum) settingsState.value.homeAlbumName else null)
)
}
}
scope.launch {
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
delay(1000) // Delay for enableChanger to refresh
if (settingsState.value.enableChanger) {
val currentHomeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName }
@@ -402,6 +402,8 @@ class HomeWallpaperService: Service() {
if (success) {
selectedRepository.upsertSelectedAlbum(homeAlbum.copy(album = homeAlbum.album.copy(homeWallpapersInQueue = newWallpapers.drop(1))))
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, wallpaper.toString())
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, wallpaper.toString())
}
else {
val wallpaperToDelete = homeAlbum.wallpapers.find { it.wallpaperUri == wallpaper }
@@ -433,6 +435,7 @@ class HomeWallpaperService: Service() {
if (success) {
selectedRepository.upsertSelectedAlbum(homeAlbum.copy(album = homeAlbum.album.copy(homeWallpapersInQueue = homeAlbum.album.homeWallpapersInQueue.drop(1))))
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, wallpaper.toString())
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, wallpaper.toString())
}
else {
val wallpaperToDelete = homeAlbum.wallpapers.find { it.wallpaperUri == wallpaper }
@@ -345,6 +345,7 @@ class LockWallpaperService: Service() {
if (success) {
selectedRepository.upsertSelectedAlbum(lockAlbum.copy(album = lockAlbum.album.copy(lockWallpapersInQueue = newWallpapers.drop(1))))
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, wallpaper.toString())
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, wallpaper.toString())
}
else {
val wallpaperToDelete = lockAlbum.wallpapers.find { it.wallpaperUri == wallpaper }
@@ -376,6 +377,7 @@ class LockWallpaperService: Service() {
if (success) {
selectedRepository.upsertSelectedAlbum(lockAlbum.copy(album = lockAlbum.album.copy(lockWallpapersInQueue = lockAlbum.album.lockWallpapersInQueue.drop(1))))
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, wallpaper.toString())
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, wallpaper.toString())
}
else {
val wallpaperToDelete = lockAlbum.wallpapers.find { it.wallpaperUri == wallpaper }