Fix bug when changing schedule end time and end is before start.

This commit is contained in:
Cody Henthorne
2021-12-10 10:40:11 -05:00
parent 50d2faf381
commit 08a305cb0f
4 changed files with 31 additions and 34 deletions

View File

@@ -76,12 +76,11 @@ class EditNotificationProfileScheduleViewModel(
repository.updateSchedule(schedule)
.toSingleDefault(SaveScheduleResult.Success)
.flatMap { r ->
if (createMode && schedule.enabled && schedule.coversTime(System.currentTimeMillis())) {
repository.manuallyToggleProfile(profileId, schedule)
if (schedule.enabled && schedule.coversTime(System.currentTimeMillis())) {
repository.manuallyEnableProfileForSchedule(profileId, schedule)
.toSingleDefault(r)
} else {
repository.updateManuallyEnabledDataIfNecessary(profileId, schedule)
.toSingleDefault(r)
Single.just(r)
}
}
}

View File

@@ -133,17 +133,12 @@ class NotificationProfilesRepository {
.subscribeOn(Schedulers.io())
}
fun updateManuallyEnabledDataIfNecessary(profileId: Long, schedule: NotificationProfileSchedule, now: Long = System.currentTimeMillis()): Completable {
fun manuallyEnableProfileForSchedule(profileId: Long, schedule: NotificationProfileSchedule, now: Long = System.currentTimeMillis()): Completable {
return Completable.fromAction {
val profiles = database.getProfiles()
val activeProfile = NotificationProfiles.getActiveProfile(profiles, now)
if (profileId == activeProfile?.id) {
val inScheduledWindow = schedule.isCurrentlyActive(now)
SignalStore.notificationProfileValues().manuallyEnabledProfile = if (inScheduledWindow) profileId else 0
SignalStore.notificationProfileValues().manuallyEnabledUntil = if (inScheduledWindow) schedule.endDateTime(now.toLocalDateTime()).toMillis() else Long.MAX_VALUE
SignalStore.notificationProfileValues().manuallyDisabledAt = if (inScheduledWindow) now else 0
}
val inScheduledWindow = schedule.isCurrentlyActive(now)
SignalStore.notificationProfileValues().manuallyEnabledProfile = if (inScheduledWindow) profileId else 0
SignalStore.notificationProfileValues().manuallyEnabledUntil = if (inScheduledWindow) schedule.endDateTime(now.toLocalDateTime()).toMillis() else Long.MAX_VALUE
SignalStore.notificationProfileValues().manuallyDisabledAt = if (inScheduledWindow) now else 0
}
.doOnComplete { ApplicationDependencies.getDatabaseObserver().notifyNotificationProfileObservers() }
.subscribeOn(Schedulers.io())