kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix bug when changing schedule end time and end is before start.
rodzic
50d2faf381
commit
08a305cb0f
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -1069,24 +1069,6 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
}
|
||||
|
||||
private void updateNotificationProfileStatus(@NonNull List<NotificationProfile> notificationProfiles) {
|
||||
if (notificationProfiles.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SignalStore.notificationProfileValues().getHasSeenTooltip()) {
|
||||
View target = findOverflowMenuButton(getToolbar(requireView()));
|
||||
if (target != null) {
|
||||
TooltipPopup.forTarget(target)
|
||||
.setText(R.string.ConversationListFragment__turn_your_notification_profile_on_or_off_here)
|
||||
.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.signal_button_primary))
|
||||
.setTextColor(ContextCompat.getColor(requireContext(), R.color.signal_button_primary_text))
|
||||
.setOnDismissListener(() -> SignalStore.notificationProfileValues().setHasSeenTooltip(true))
|
||||
.show(POSITION_BELOW);
|
||||
} else {
|
||||
Log.w(TAG, "Unable to find overflow menu to show Notification Profile tooltip");
|
||||
}
|
||||
}
|
||||
|
||||
NotificationProfile activeProfile = NotificationProfiles.getActiveProfile(notificationProfiles);
|
||||
|
||||
if (activeProfile != null) {
|
||||
|
@ -1117,6 +1099,20 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
} else {
|
||||
notificationProfileStatus.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (!SignalStore.notificationProfileValues().getHasSeenTooltip() && Util.hasItems(notificationProfiles)) {
|
||||
View target = findOverflowMenuButton(getToolbar(requireView()));
|
||||
if (target != null) {
|
||||
TooltipPopup.forTarget(target)
|
||||
.setText(R.string.ConversationListFragment__turn_your_notification_profile_on_or_off_here)
|
||||
.setBackgroundTint(ContextCompat.getColor(requireContext(), R.color.signal_button_primary))
|
||||
.setTextColor(ContextCompat.getColor(requireContext(), R.color.signal_button_primary_text))
|
||||
.setOnDismissListener(() -> SignalStore.notificationProfileValues().setHasSeenTooltip(true))
|
||||
.show(POSITION_BELOW);
|
||||
} else {
|
||||
Log.w(TAG, "Unable to find overflow menu to show Notification Profile tooltip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable View findOverflowMenuButton(@NonNull Toolbar viewGroup) {
|
||||
|
|
|
@ -59,8 +59,15 @@ data class NotificationProfileSchedule(
|
|||
return LocalTime.of(end / 100, end % 100)
|
||||
}
|
||||
|
||||
fun endDateTime(now: LocalDateTime): LocalDateTime {
|
||||
return end.toLocalDateTime(now).plusDays(if (end < start) 1 else 0)
|
||||
fun endDateTime(localNow: LocalDateTime): LocalDateTime {
|
||||
val localStart: LocalDateTime = start.toLocalDateTime(localNow)
|
||||
val localEnd: LocalDateTime = end.toLocalDateTime(localNow)
|
||||
|
||||
return if (end < start && (daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd.plusDays(1)))) {
|
||||
localEnd.plusDays(1)
|
||||
} else {
|
||||
localEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue