Fix wallpaper scheduling and effects handling bugs
Multiple fixes for scheduling logic and UI behavior: **Scheduling Fixes:** - Add required albums validation before scheduling WorkManager jobs - Only schedule when all required albums are selected based on enabled screens - Prevent scheduling with incomplete album selection (both screens enabled requires both albums) - Add hasRequiredAlbums check in HomeViewModel, WallpaperScreen, and BootReceiver **Race Condition Fixes:** - Fix toggleWallpaperChanger race condition with atomic updateEnableChanger() - Prevent phantom album selections by using atomic DataStore updates - Fix startup race condition - only cleanup stale album IDs after albums load **Display Settings:** - Separate scheduling changes from display changes (ScheduleSettings.kt) - Add hasSchedulingChanges() - intervals, screen enable/disable, separate schedules - Add hasDisplayChanges() - scaling, effects, adaptive brightness - Reapply wallpaper immediately when display settings change (no reschedule needed) - Prevent unnecessary WorkManager rescheduling for display-only changes **Effect Sliders:** - Fix effect sliders to respect separateSchedules setting - Show synchronized slider when individual scheduling OFF - Show separate sliders when individual scheduling ON - Applies to brightness/darken, blur, and vignette sliders **AlbumRefreshWorker:** - Fix duplicate detection to check both direct and folder wallpapers - Fix failure counting (increment failedCount on addWallpaper errors) - Prevent false error logs and database constraint violations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
9079306f8f
commit
9820581723
8 files changed
+266
-82
No files matched your search
@@ -307,6 +307,17 @@ class PreferencesManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ Atomic ScheduleSettings Operations ============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atomically update enableChanger setting without race conditions
|
||||||
|
*/
|
||||||
|
suspend fun updateEnableChanger(enabled: Boolean) {
|
||||||
|
dataStore.edit { prefs ->
|
||||||
|
prefs[booleanPreferencesKey(PreferenceKeys.ENABLE_CHANGER)] = enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ============ Individual Preference Operations ============
|
// ============ Individual Preference Operations ============
|
||||||
|
|
||||||
suspend fun <T> setValue(key: String, value: T) {
|
suspend fun <T> setValue(key: String, value: T) {
|
||||||
|
|||||||
@@ -62,4 +62,9 @@ class SettingsRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun updateFirstLaunch(isFirstLaunch: Boolean) =
|
override suspend fun updateFirstLaunch(isFirstLaunch: Boolean) =
|
||||||
preferencesManager.updateFirstLaunch(isFirstLaunch)
|
preferencesManager.updateFirstLaunch(isFirstLaunch)
|
||||||
|
|
||||||
|
// ============ Atomic ScheduleSettings Operations ============
|
||||||
|
|
||||||
|
override suspend fun updateEnableChanger(enabled: Boolean) =
|
||||||
|
preferencesManager.updateEnableChanger(enabled)
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,39 @@ data class ScheduleSettings(
|
|||||||
lockEffects = lockEffects.validate()
|
lockEffects = lockEffects.validate()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if scheduling-related settings changed (not just display settings)
|
||||||
|
*
|
||||||
|
* Returns true if any of these changed:
|
||||||
|
* - Screen enable/disable
|
||||||
|
* - Interval timing
|
||||||
|
* - Separate schedules toggle
|
||||||
|
* - Shuffle (handled separately with queue clearing)
|
||||||
|
*
|
||||||
|
* Display-only settings (scaling, effects, adaptive brightness) don't affect scheduling
|
||||||
|
*/
|
||||||
|
fun hasSchedulingChanges(other: ScheduleSettings): Boolean {
|
||||||
|
return homeEnabled != other.homeEnabled ||
|
||||||
|
lockEnabled != other.lockEnabled ||
|
||||||
|
homeIntervalMinutes != other.homeIntervalMinutes ||
|
||||||
|
lockIntervalMinutes != other.lockIntervalMinutes ||
|
||||||
|
separateSchedules != other.separateSchedules
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if display settings changed (scaling, effects, adaptive brightness)
|
||||||
|
*
|
||||||
|
* When these change, we should reapply the current wallpaper immediately
|
||||||
|
* to show the user the effect, but we don't need to reschedule WorkManager
|
||||||
|
*/
|
||||||
|
fun hasDisplayChanges(other: ScheduleSettings): Boolean {
|
||||||
|
return homeScalingType != other.homeScalingType ||
|
||||||
|
lockScalingType != other.lockScalingType ||
|
||||||
|
homeEffects != other.homeEffects ||
|
||||||
|
lockEffects != other.lockEffects ||
|
||||||
|
adaptiveBrightness != other.adaptiveBrightness
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun default() = ScheduleSettings()
|
fun default() = ScheduleSettings()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,4 +69,12 @@ interface SettingsRepository {
|
|||||||
suspend fun updateDynamicTheming(enabled: Boolean)
|
suspend fun updateDynamicTheming(enabled: Boolean)
|
||||||
suspend fun updateAnimate(enabled: Boolean)
|
suspend fun updateAnimate(enabled: Boolean)
|
||||||
suspend fun updateFirstLaunch(isFirstLaunch: Boolean)
|
suspend fun updateFirstLaunch(isFirstLaunch: Boolean)
|
||||||
|
|
||||||
|
// ============ Atomic ScheduleSettings Operations ============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atomically update enableChanger to prevent race conditions
|
||||||
|
* Use this instead of updateScheduleSettings when only toggling changer
|
||||||
|
*/
|
||||||
|
suspend fun updateEnableChanger(enabled: Boolean)
|
||||||
}
|
}
|
||||||
+136
-46
@@ -102,26 +102,52 @@ class HomeViewModel @Inject constructor(
|
|||||||
if (album == null && updated.lockAlbumId == null) {
|
if (album == null && updated.lockAlbumId == null) {
|
||||||
toggleWallpaperChanger(false)
|
toggleWallpaperChanger(false)
|
||||||
} else if (album != null && updated.enableChanger) {
|
} else if (album != null && updated.enableChanger) {
|
||||||
// Immediately change wallpaper when selecting album
|
// Check if we have all required albums before triggering wallpaper change
|
||||||
val screenType = if (
|
val homeActive = updated.homeEnabled && updated.homeAlbumId != null
|
||||||
updated.homeAlbumId == updated.lockAlbumId &&
|
val lockActive = updated.lockEnabled && updated.lockAlbumId != null
|
||||||
updated.homeAlbumId != null &&
|
val hasRequiredAlbums = when {
|
||||||
!updated.separateSchedules &&
|
updated.homeEnabled && updated.lockEnabled -> homeActive && lockActive
|
||||||
updated.homeEnabled &&
|
updated.homeEnabled -> homeActive
|
||||||
updated.lockEnabled
|
updated.lockEnabled -> lockActive
|
||||||
) {
|
else -> false
|
||||||
// Same album for both screens and not separately scheduled - use BOTH
|
|
||||||
ScreenType.BOTH
|
|
||||||
} else {
|
|
||||||
ScreenType.HOME
|
|
||||||
}
|
}
|
||||||
changeWallpaperNow(screenType)
|
|
||||||
|
|
||||||
// Then schedule future alarms
|
// Only change wallpaper and schedule if all required albums are selected
|
||||||
scheduleAlarms(updated)
|
if (hasRequiredAlbums) {
|
||||||
|
val screenType = if (
|
||||||
|
updated.homeAlbumId == updated.lockAlbumId &&
|
||||||
|
updated.homeAlbumId != null &&
|
||||||
|
!updated.separateSchedules &&
|
||||||
|
updated.homeEnabled &&
|
||||||
|
updated.lockEnabled
|
||||||
|
) {
|
||||||
|
// Same album for both screens and not separately scheduled - use BOTH
|
||||||
|
ScreenType.BOTH
|
||||||
|
} else {
|
||||||
|
ScreenType.HOME
|
||||||
|
}
|
||||||
|
changeWallpaperNow(screenType)
|
||||||
|
scheduleAlarms(updated)
|
||||||
|
} else {
|
||||||
|
// Not all required albums selected - cancel any existing schedules
|
||||||
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
|
}
|
||||||
} else if (updated.enableChanger) {
|
} else if (updated.enableChanger) {
|
||||||
// Just reschedule if changer is enabled but album was unselected
|
// Album was unselected - check if we still have all required albums
|
||||||
scheduleAlarms(updated)
|
val homeActive = updated.homeEnabled && updated.homeAlbumId != null
|
||||||
|
val lockActive = updated.lockEnabled && updated.lockAlbumId != null
|
||||||
|
val hasRequiredAlbums = when {
|
||||||
|
updated.homeEnabled && updated.lockEnabled -> homeActive && lockActive
|
||||||
|
updated.homeEnabled -> homeActive
|
||||||
|
updated.lockEnabled -> lockActive
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasRequiredAlbums) {
|
||||||
|
scheduleAlarms(updated)
|
||||||
|
} else {
|
||||||
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,42 +164,77 @@ class HomeViewModel @Inject constructor(
|
|||||||
if (album == null && updated.homeAlbumId == null) {
|
if (album == null && updated.homeAlbumId == null) {
|
||||||
toggleWallpaperChanger(false)
|
toggleWallpaperChanger(false)
|
||||||
} else if (album != null && updated.enableChanger) {
|
} else if (album != null && updated.enableChanger) {
|
||||||
// Immediately change wallpaper when selecting album
|
// Check if we have all required albums before triggering wallpaper change
|
||||||
val screenType = if (
|
val homeActive = updated.homeEnabled && updated.homeAlbumId != null
|
||||||
updated.homeAlbumId == updated.lockAlbumId &&
|
val lockActive = updated.lockEnabled && updated.lockAlbumId != null
|
||||||
updated.lockAlbumId != null &&
|
val hasRequiredAlbums = when {
|
||||||
!updated.separateSchedules &&
|
updated.homeEnabled && updated.lockEnabled -> homeActive && lockActive
|
||||||
updated.homeEnabled &&
|
updated.homeEnabled -> homeActive
|
||||||
updated.lockEnabled
|
updated.lockEnabled -> lockActive
|
||||||
) {
|
else -> false
|
||||||
// Same album for both screens and not separately scheduled - use BOTH
|
|
||||||
ScreenType.BOTH
|
|
||||||
} else {
|
|
||||||
ScreenType.LOCK
|
|
||||||
}
|
}
|
||||||
changeWallpaperNow(screenType)
|
|
||||||
|
|
||||||
// Then schedule future alarms
|
// Only change wallpaper and schedule if all required albums are selected
|
||||||
scheduleAlarms(updated)
|
if (hasRequiredAlbums) {
|
||||||
|
val screenType = if (
|
||||||
|
updated.homeAlbumId == updated.lockAlbumId &&
|
||||||
|
updated.lockAlbumId != null &&
|
||||||
|
!updated.separateSchedules &&
|
||||||
|
updated.homeEnabled &&
|
||||||
|
updated.lockEnabled
|
||||||
|
) {
|
||||||
|
// Same album for both screens and not separately scheduled - use BOTH
|
||||||
|
ScreenType.BOTH
|
||||||
|
} else {
|
||||||
|
ScreenType.LOCK
|
||||||
|
}
|
||||||
|
changeWallpaperNow(screenType)
|
||||||
|
scheduleAlarms(updated)
|
||||||
|
} else {
|
||||||
|
// Not all required albums selected - cancel any existing schedules
|
||||||
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
|
}
|
||||||
} else if (updated.enableChanger) {
|
} else if (updated.enableChanger) {
|
||||||
// Just reschedule if changer is enabled but album was unselected
|
// Album was unselected - check if we still have all required albums
|
||||||
scheduleAlarms(updated)
|
val homeActive = updated.homeEnabled && updated.homeAlbumId != null
|
||||||
|
val lockActive = updated.lockEnabled && updated.lockAlbumId != null
|
||||||
|
val hasRequiredAlbums = when {
|
||||||
|
updated.homeEnabled && updated.lockEnabled -> homeActive && lockActive
|
||||||
|
updated.homeEnabled -> homeActive
|
||||||
|
updated.lockEnabled -> lockActive
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasRequiredAlbums) {
|
||||||
|
scheduleAlarms(updated)
|
||||||
|
} else {
|
||||||
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleWallpaperChanger(enabled: Boolean) {
|
fun toggleWallpaperChanger(enabled: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val current = scheduleSettings.value
|
// Use atomic update to prevent race conditions with album selection updates
|
||||||
val updated = current.copy(enableChanger = enabled)
|
settingsRepository.updateEnableChanger(enabled)
|
||||||
settingsRepository.updateScheduleSettings(updated)
|
|
||||||
|
// Read updated settings after atomic write
|
||||||
|
val updated = settingsRepository.getScheduleSettings()
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// Immediately change wallpaper when enabling changer
|
// Check if we have all required albums before changing wallpaper
|
||||||
val homeActive = updated.homeEnabled && updated.homeAlbumId != null
|
val homeActive = updated.homeEnabled && updated.homeAlbumId != null
|
||||||
val lockActive = updated.lockEnabled && updated.lockAlbumId != null
|
val lockActive = updated.lockEnabled && updated.lockAlbumId != null
|
||||||
|
val hasRequiredAlbums = when {
|
||||||
|
updated.homeEnabled && updated.lockEnabled -> homeActive && lockActive
|
||||||
|
updated.homeEnabled -> homeActive
|
||||||
|
updated.lockEnabled -> lockActive
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
if (homeActive || lockActive) {
|
// Only change wallpaper and schedule if all required albums are selected
|
||||||
|
if (hasRequiredAlbums) {
|
||||||
val screenType = when {
|
val screenType = when {
|
||||||
homeActive && lockActive && updated.homeAlbumId == updated.lockAlbumId && !updated.separateSchedules ->
|
homeActive && lockActive && updated.homeAlbumId == updated.lockAlbumId && !updated.separateSchedules ->
|
||||||
ScreenType.BOTH
|
ScreenType.BOTH
|
||||||
@@ -185,10 +246,11 @@ class HomeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
screenType?.let { changeWallpaperNow(it) }
|
screenType?.let { changeWallpaperNow(it) }
|
||||||
|
scheduleAlarms(updated)
|
||||||
|
} else {
|
||||||
|
// Not all required albums selected - cancel any existing schedules
|
||||||
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then schedule future alarms
|
|
||||||
scheduleAlarms(updated)
|
|
||||||
} else {
|
} else {
|
||||||
wallpaperScheduler.cancelAllWallpaperChanges()
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
}
|
}
|
||||||
@@ -202,6 +264,11 @@ class HomeViewModel @Inject constructor(
|
|||||||
val shuffleChanged = currentSettings.shuffleEnabled != settings.shuffleEnabled
|
val shuffleChanged = currentSettings.shuffleEnabled != settings.shuffleEnabled
|
||||||
|
|
||||||
val validated = settings.validate()
|
val validated = settings.validate()
|
||||||
|
|
||||||
|
// Check what changed
|
||||||
|
val schedulingChanged = validated.hasSchedulingChanges(currentSettings)
|
||||||
|
val displayChanged = validated.hasDisplayChanges(currentSettings)
|
||||||
|
|
||||||
settingsRepository.updateScheduleSettings(validated)
|
settingsRepository.updateScheduleSettings(validated)
|
||||||
|
|
||||||
// If shuffle setting changed, clear all queues to force rebuild with new mode
|
// If shuffle setting changed, clear all queues to force rebuild with new mode
|
||||||
@@ -209,16 +276,39 @@ class HomeViewModel @Inject constructor(
|
|||||||
wallpaperRepository.clearAllQueues()
|
wallpaperRepository.clearAllQueues()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only reschedule if changer is enabled AND at least one album is selected
|
|
||||||
val homeActive = validated.homeEnabled && validated.homeAlbumId != null
|
val homeActive = validated.homeEnabled && validated.homeAlbumId != null
|
||||||
val lockActive = validated.lockEnabled && validated.lockAlbumId != null
|
val lockActive = validated.lockEnabled && validated.lockAlbumId != null
|
||||||
|
|
||||||
if (validated.enableChanger && (homeActive || lockActive)) {
|
// Determine if we have the required albums selected
|
||||||
|
val hasRequiredAlbums = when {
|
||||||
|
validated.homeEnabled && validated.lockEnabled -> homeActive && lockActive
|
||||||
|
validated.homeEnabled -> homeActive
|
||||||
|
validated.lockEnabled -> lockActive
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle scheduling changes (interval, screen enable/disable, etc.)
|
||||||
|
if (validated.enableChanger && hasRequiredAlbums && schedulingChanged) {
|
||||||
scheduleAlarms(validated)
|
scheduleAlarms(validated)
|
||||||
} else if (validated.enableChanger) {
|
} else if (validated.enableChanger && !hasRequiredAlbums) {
|
||||||
// Changer enabled but no albums selected - cancel existing schedules
|
// Changer enabled but required albums not selected - cancel existing schedules
|
||||||
wallpaperScheduler.cancelAllWallpaperChanges()
|
wallpaperScheduler.cancelAllWallpaperChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle display changes (scaling, effects, adaptive brightness)
|
||||||
|
// Reapply current wallpaper immediately to show the effect
|
||||||
|
if (validated.enableChanger && hasRequiredAlbums && displayChanged) {
|
||||||
|
val screenType = when {
|
||||||
|
homeActive && lockActive && validated.homeAlbumId == validated.lockAlbumId && !validated.separateSchedules ->
|
||||||
|
ScreenType.BOTH
|
||||||
|
homeActive && lockActive ->
|
||||||
|
ScreenType.BOTH // Change both even if different albums
|
||||||
|
homeActive -> ScreenType.HOME
|
||||||
|
lockActive -> ScreenType.LOCK
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
screenType?.let { changeWallpaperNow(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+29
-10
@@ -113,19 +113,35 @@ fun WallpaperScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auto-toggle wallpaper changer based on album selection state
|
// Auto-toggle wallpaper changer based on album selection state
|
||||||
LaunchedEffect(scheduleSettings.homeAlbumId, scheduleSettings.lockAlbumId, homeEnabled, lockEnabled) {
|
// IMPORTANT: Check if actual album OBJECTS exist, not just IDs
|
||||||
|
// IDs might be stale (album deleted) which would cause invalid state
|
||||||
|
LaunchedEffect(homeAlbum, lockAlbum, homeEnabled, lockEnabled, scheduleSettings.homeAlbumId, scheduleSettings.lockAlbumId, albums) {
|
||||||
|
// Clean up stale album IDs (ID exists but album doesn't)
|
||||||
|
// IMPORTANT: Only cleanup if albums list has loaded (not empty)
|
||||||
|
// Otherwise we might clear valid IDs during initial load race condition
|
||||||
|
if (albums.isNotEmpty()) {
|
||||||
|
if (homeEnabled && scheduleSettings.homeAlbumId != null && homeAlbum == null) {
|
||||||
|
// Home album ID is set but album doesn't exist in loaded list - clear it
|
||||||
|
onSelectHomeAlbum(null)
|
||||||
|
}
|
||||||
|
if (lockEnabled && scheduleSettings.lockAlbumId != null && lockAlbum == null) {
|
||||||
|
// Lock album ID is set but album doesn't exist in loaded list - clear it
|
||||||
|
onSelectLockAlbum(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val allRequiredAlbumsSet = when {
|
val allRequiredAlbumsSet = when {
|
||||||
homeEnabled && lockEnabled -> {
|
homeEnabled && lockEnabled -> {
|
||||||
// Both are enabled, require both albums to be set
|
// Both are enabled, require both album OBJECTS to exist
|
||||||
scheduleSettings.homeAlbumId != null && scheduleSettings.lockAlbumId != null
|
homeAlbum != null && lockAlbum != null
|
||||||
}
|
}
|
||||||
homeEnabled -> {
|
homeEnabled -> {
|
||||||
// Only home is enabled, require only home album
|
// Only home is enabled, require home album OBJECT to exist
|
||||||
scheduleSettings.homeAlbumId != null
|
homeAlbum != null
|
||||||
}
|
}
|
||||||
lockEnabled -> {
|
lockEnabled -> {
|
||||||
// Only lock is enabled, require only lock album
|
// Only lock is enabled, require lock album OBJECT to exist
|
||||||
scheduleSettings.lockAlbumId != null
|
lockAlbum != null
|
||||||
}
|
}
|
||||||
else -> false // Neither enabled, should be disabled
|
else -> false // Neither enabled, should be disabled
|
||||||
}
|
}
|
||||||
@@ -550,7 +566,8 @@ fun WallpaperScreen(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
bothEnabled = homeEnabled && lockEnabled,
|
// Show separate sliders only when both enabled AND separate schedules is on
|
||||||
|
bothEnabled = homeEnabled && lockEnabled && scheduleSettings.separateSchedules,
|
||||||
homePercentage = scheduleSettings.homeEffects.darkenPercentage,
|
homePercentage = scheduleSettings.homeEffects.darkenPercentage,
|
||||||
lockPercentage = scheduleSettings.lockEffects.darkenPercentage,
|
lockPercentage = scheduleSettings.lockEffects.darkenPercentage,
|
||||||
onPercentageChange = { homePercent, lockPercent ->
|
onPercentageChange = { homePercent, lockPercent ->
|
||||||
@@ -580,7 +597,8 @@ fun WallpaperScreen(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
bothEnabled = homeEnabled && lockEnabled,
|
// Show separate sliders only when both enabled AND separate schedules is on
|
||||||
|
bothEnabled = homeEnabled && lockEnabled && scheduleSettings.separateSchedules,
|
||||||
homePercentage = scheduleSettings.homeEffects.blurPercentage,
|
homePercentage = scheduleSettings.homeEffects.blurPercentage,
|
||||||
lockPercentage = scheduleSettings.lockEffects.blurPercentage,
|
lockPercentage = scheduleSettings.lockEffects.blurPercentage,
|
||||||
onPercentageChange = { homePercent, lockPercent ->
|
onPercentageChange = { homePercent, lockPercent ->
|
||||||
@@ -610,7 +628,8 @@ fun WallpaperScreen(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
bothEnabled = homeEnabled && lockEnabled,
|
// Show separate sliders only when both enabled AND separate schedules is on
|
||||||
|
bothEnabled = homeEnabled && lockEnabled && scheduleSettings.separateSchedules,
|
||||||
homePercentage = scheduleSettings.homeEffects.vignettePercentage,
|
homePercentage = scheduleSettings.homeEffects.vignettePercentage,
|
||||||
lockPercentage = scheduleSettings.lockEffects.vignettePercentage,
|
lockPercentage = scheduleSettings.lockEffects.vignettePercentage,
|
||||||
onPercentageChange = { homePercent, lockPercent ->
|
onPercentageChange = { homePercent, lockPercent ->
|
||||||
|
|||||||
@@ -48,34 +48,48 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
val settings = settingsRepository.getScheduleSettings()
|
val settings = settingsRepository.getScheduleSettings()
|
||||||
|
|
||||||
if (settings.enableChanger) {
|
if (settings.enableChanger) {
|
||||||
// Reschedule wallpaper changes with WorkManager
|
// Check if we have all required albums before scheduling
|
||||||
val homeInterval: Int
|
val homeActive = settings.homeEnabled && settings.homeAlbumId != null
|
||||||
val lockInterval: Int
|
val lockActive = settings.lockEnabled && settings.lockAlbumId != null
|
||||||
|
val hasRequiredAlbums = when {
|
||||||
if (settings.separateSchedules) {
|
settings.homeEnabled && settings.lockEnabled -> homeActive && lockActive
|
||||||
// Separate schedules for home and lock
|
settings.homeEnabled -> homeActive
|
||||||
homeInterval = if (settings.homeEnabled) settings.homeIntervalMinutes else 0
|
settings.lockEnabled -> lockActive
|
||||||
lockInterval = if (settings.lockEnabled) settings.lockIntervalMinutes else 0
|
else -> false
|
||||||
} else {
|
|
||||||
// Same interval for both (enabled screens)
|
|
||||||
val interval = settings.homeIntervalMinutes
|
|
||||||
homeInterval = if (settings.homeEnabled) interval else 0
|
|
||||||
lockInterval = if (settings.lockEnabled) interval else 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if screens should be synchronized
|
if (hasRequiredAlbums) {
|
||||||
val shouldSync = settings.homeEnabled && settings.lockEnabled &&
|
// Reschedule wallpaper changes with WorkManager
|
||||||
settings.homeAlbumId != null &&
|
val homeInterval: Int
|
||||||
settings.homeAlbumId == settings.lockAlbumId &&
|
val lockInterval: Int
|
||||||
!settings.separateSchedules
|
|
||||||
|
|
||||||
wallpaperScheduler.scheduleWallpaperChanges(
|
if (settings.separateSchedules) {
|
||||||
homeIntervalMinutes = homeInterval,
|
// Separate schedules for home and lock
|
||||||
lockIntervalMinutes = lockInterval,
|
homeInterval = if (settings.homeEnabled) settings.homeIntervalMinutes else 0
|
||||||
synchronized = shouldSync
|
lockInterval = if (settings.lockEnabled) settings.lockIntervalMinutes else 0
|
||||||
)
|
} else {
|
||||||
|
// Same interval for both (enabled screens)
|
||||||
|
val interval = settings.homeIntervalMinutes
|
||||||
|
homeInterval = if (settings.homeEnabled) interval else 0
|
||||||
|
lockInterval = if (settings.lockEnabled) interval else 0
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Wallpaper changes rescheduled successfully")
|
// Determine if screens should be synchronized
|
||||||
|
val shouldSync = settings.homeEnabled && settings.lockEnabled &&
|
||||||
|
settings.homeAlbumId != null &&
|
||||||
|
settings.homeAlbumId == settings.lockAlbumId &&
|
||||||
|
!settings.separateSchedules
|
||||||
|
|
||||||
|
wallpaperScheduler.scheduleWallpaperChanges(
|
||||||
|
homeIntervalMinutes = homeInterval,
|
||||||
|
lockIntervalMinutes = lockInterval,
|
||||||
|
synchronized = shouldSync
|
||||||
|
)
|
||||||
|
|
||||||
|
Log.d(TAG, "Wallpaper changes rescheduled successfully")
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Wallpaper changer enabled but required albums not selected, not scheduling")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Wallpaper changer disabled, not scheduling")
|
Log.d(TAG, "Wallpaper changer disabled, not scheduling")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,9 +73,12 @@ class AlbumRefreshWorker @AssistedInject constructor(
|
|||||||
when (val scanResult = wallpaperRepository.scanFolderForWallpapers(android.net.Uri.parse(folder.uri))) {
|
when (val scanResult = wallpaperRepository.scanFolderForWallpapers(android.net.Uri.parse(folder.uri))) {
|
||||||
is CoreResult.Success -> {
|
is CoreResult.Success -> {
|
||||||
val scannedWallpapers = scanResult.data
|
val scannedWallpapers = scanResult.data
|
||||||
val existingUris = album.wallpapers.map { it.uri }.toSet()
|
|
||||||
|
|
||||||
// Find new wallpapers not already in album
|
// Get ALL existing URIs (direct wallpapers + folder wallpapers)
|
||||||
|
val existingUris = (album.wallpapers.map { it.uri } +
|
||||||
|
album.folders.flatMap { it.wallpapers.map { w -> w.uri } }).toSet()
|
||||||
|
|
||||||
|
// Find new wallpapers not already in album (anywhere)
|
||||||
val newWallpapers = scannedWallpapers.filter { it.uri !in existingUris }
|
val newWallpapers = scannedWallpapers.filter { it.uri !in existingUris }
|
||||||
|
|
||||||
// Add new wallpapers to album
|
// Add new wallpapers to album
|
||||||
@@ -87,6 +90,7 @@ class AlbumRefreshWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
is CoreResult.Error -> {
|
is CoreResult.Error -> {
|
||||||
Log.e(TAG, "Error adding wallpaper to album '${album.name}'")
|
Log.e(TAG, "Error adding wallpaper to album '${album.name}'")
|
||||||
|
failedCount++
|
||||||
}
|
}
|
||||||
is CoreResult.Loading -> {
|
is CoreResult.Loading -> {
|
||||||
/* Loading state not used */
|
/* Loading state not used */
|
||||||
|
|||||||
Reference in new issue
Block a user