diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleViewModel.kt index 15a59e781e..f947a08647 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleViewModel.kt @@ -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) } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt index e3a09ba354..0d53608de4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfilesRepository.kt @@ -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()) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java index 981711266e..57a7d462f1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java @@ -1069,24 +1069,6 @@ public class ConversationListFragment extends MainFragment implements ActionMode } private void updateNotificationProfileStatus(@NonNull List 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) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt index a1fb446178..76725f6419 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt @@ -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 + } } }