diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleFragment.kt index 147bd9d6fb..15582f982b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/EditNotificationProfileScheduleFragment.kt @@ -25,10 +25,22 @@ import org.thoughtcrime.securesms.components.settings.app.notifications.profiles import org.thoughtcrime.securesms.util.LifecycleDisposable import org.thoughtcrime.securesms.util.ViewUtil import org.thoughtcrime.securesms.util.formatHours +import org.thoughtcrime.securesms.util.orderOfDaysInWeek import org.thoughtcrime.securesms.util.visible import java.time.DayOfWeek import java.time.LocalTime import java.time.format.DateTimeFormatter +import java.util.Locale + +private val DAY_TO_STARTING_LETTER: Map = mapOf( + DayOfWeek.SUNDAY to R.string.EditNotificationProfileSchedule__sunday_first_letter, + DayOfWeek.MONDAY to R.string.EditNotificationProfileSchedule__monday_first_letter, + DayOfWeek.TUESDAY to R.string.EditNotificationProfileSchedule__tuesday_first_letter, + DayOfWeek.WEDNESDAY to R.string.EditNotificationProfileSchedule__wednesday_first_letter, + DayOfWeek.THURSDAY to R.string.EditNotificationProfileSchedule__thursday_first_letter, + DayOfWeek.FRIDAY to R.string.EditNotificationProfileSchedule__friday_first_letter, + DayOfWeek.SATURDAY to R.string.EditNotificationProfileSchedule__saturday_first_letter, +) /** * Can edit existing or use during create flow to setup a profile schedule. @@ -82,27 +94,20 @@ class EditNotificationProfileScheduleFragment : LoggingFragment(R.layout.fragmen ) } - val sunday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_sunday) - val monday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_monday) - val tuesday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_tuesday) - val wednesday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_wednesday) - val thursday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_thursday) - val friday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_friday) - val saturday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_saturday) + val day1: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_1) + val day2: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_2) + val day3: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_3) + val day4: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_4) + val day5: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_5) + val day6: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_6) + val day7: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_7) - val days: Map = mapOf( - sunday to DayOfWeek.SUNDAY, - monday to DayOfWeek.MONDAY, - tuesday to DayOfWeek.TUESDAY, - wednesday to DayOfWeek.WEDNESDAY, - thursday to DayOfWeek.THURSDAY, - friday to DayOfWeek.FRIDAY, - saturday to DayOfWeek.SATURDAY - ) + val days: Map = listOf(day1, day2, day3, day4, day5, day6, day7).zip(Locale.getDefault().orderOfDaysInWeek()).toMap() days.forEach { (view, day) -> DrawableCompat.setTintList(view.background, ContextCompat.getColorStateList(requireContext(), R.color.notification_profile_schedule_background_tint)) view.setOnClickListener { viewModel.toggleDay(day) } + view.setText(DAY_TO_STARTING_LETTER[day]!!) } lifecycleDisposable += viewModel.schedule() diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsFragment.kt index 883e517de1..af59c2605f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/profiles/NotificationProfileDetailsFragment.kt @@ -32,12 +32,11 @@ import org.thoughtcrime.securesms.recipients.RecipientId import org.thoughtcrime.securesms.util.LifecycleDisposable import org.thoughtcrime.securesms.util.SpanUtil import org.thoughtcrime.securesms.util.formatHours +import org.thoughtcrime.securesms.util.orderOfDaysInWeek import java.time.DayOfWeek import java.time.format.TextStyle import java.util.Locale -private val DAY_ORDER: List = listOf(DayOfWeek.SUNDAY, DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY, DayOfWeek.SATURDAY) - class NotificationProfileDetailsFragment : DSLSettingsFragment() { private val viewModel: NotificationProfileDetailsViewModel by viewModels(factoryProducer = this::createFactory) @@ -221,7 +220,7 @@ class NotificationProfileDetailsFragment : DSLSettingsFragment() { if (daysEnabled.size == 7) { days.append(getString(R.string.NotificationProfileDetails__everyday)) } else { - for (day in DAY_ORDER) { + for (day: DayOfWeek in Locale.getDefault().orderOfDaysInWeek()) { if (daysEnabled.contains(day)) { if (days.isNotEmpty()) { days.append(", ") diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/LocalDateTimeExtensions.kt b/app/src/main/java/org/thoughtcrime/securesms/util/JavaTimeExtensions.kt similarity index 76% rename from app/src/main/java/org/thoughtcrime/securesms/util/LocalDateTimeExtensions.kt rename to app/src/main/java/org/thoughtcrime/securesms/util/JavaTimeExtensions.kt index 2b8faf3196..9c96bd48d6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/LocalDateTimeExtensions.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/JavaTimeExtensions.kt @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms.util +import java.time.DayOfWeek import java.time.Instant import java.time.LocalDateTime import java.time.LocalTime @@ -8,6 +9,8 @@ import java.time.ZoneId import java.time.ZoneOffset import java.time.format.DateTimeFormatter import java.time.format.FormatStyle +import java.time.temporal.WeekFields +import java.util.Locale import java.util.concurrent.TimeUnit /** @@ -51,3 +54,19 @@ fun Long.toLocalTime(zoneId: ZoneId = ZoneId.systemDefault()): LocalTime { fun LocalTime.formatHours(): String { return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(this) } + +/** + * Get the days of the week in order based on [Locale]. + */ +fun Locale.orderOfDaysInWeek(): List { + val firstDayOfWeek: DayOfWeek = WeekFields.of(this).firstDayOfWeek + return listOf( + firstDayOfWeek, + firstDayOfWeek.plus(1), + firstDayOfWeek.plus(2), + firstDayOfWeek.plus(3), + firstDayOfWeek.plus(4), + firstDayOfWeek.plus(5), + firstDayOfWeek.plus(6), + ) +} diff --git a/app/src/main/res/layout/fragment_edit_notification_profile_schedule.xml b/app/src/main/res/layout/fragment_edit_notification_profile_schedule.xml index 1c0fc876e8..6e0d82daf2 100644 --- a/app/src/main/res/layout/fragment_edit_notification_profile_schedule.xml +++ b/app/src/main/res/layout/fragment_edit_notification_profile_schedule.xml @@ -43,7 +43,7 @@ android:layout_marginTop="12dp" android:layout_marginEnd="@dimen/dsl_settings_gutter" android:gravity="center" - android:text="@string/EditNotificationProfileSchedule__turn_on_and_edit_your_schedule_to_automate_this_profile" + android:text="@string/EditNotificationProfileSchedule__set_up_a_schedule_to_enable_this_notification_profile_automatically" android:textAppearance="@style/TextAppearance.Signal.Body1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -128,7 +128,7 @@ android:layout_marginStart="16dp" android:layout_marginTop="24dp" android:layout_marginEnd="16dp" - app:constraint_referenced_ids="edit_notification_profile_schedule_sunday,edit_notification_profile_schedule_monday,edit_notification_profile_schedule_tuesday,edit_notification_profile_schedule_wednesday,edit_notification_profile_schedule_thursday,edit_notification_profile_schedule_friday,edit_notification_profile_schedule_saturday" + app:constraint_referenced_ids="edit_notification_profile_schedule_day_1,edit_notification_profile_schedule_day_2,edit_notification_profile_schedule_day_3,edit_notification_profile_schedule_day_4,edit_notification_profile_schedule_day_5,edit_notification_profile_schedule_day_6,edit_notification_profile_schedule_day_7" app:flow_horizontalStyle="spread_inside" app:flow_wrapMode="aligned" app:layout_constraintEnd_toEndOf="parent" @@ -136,7 +136,7 @@ app:layout_constraintTop_toBottomOf="@+id/edit_notification_profile_schedule_start_time" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__sunday_first_letter" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__monday_first_letter" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__tuesday_first_letter" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__wednesday_first_letter" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__thursday_first_letter" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__friday_first_letter" /> + android:textColor="@color/notification_profile_schedule_text_selector" + tools:text="@string/EditNotificationProfileSchedule__saturday_first_letter" /> Add a schedule - Turn on and edit your schedule to automate this profile. + Set up a schedule to enable this notification profile automatically. Schedule