Update Schedule UI and use locale specific first day of week.

This commit is contained in:
Cody Henthorne 2021-12-09 11:42:56 -05:00
parent 884710fc30
commit 4c28619010
5 changed files with 66 additions and 43 deletions

View file

@ -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<DayOfWeek, Int> = 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<CheckedTextView, DayOfWeek> = 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<CheckedTextView, DayOfWeek> = 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()

View file

@ -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<DayOfWeek> = 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(", ")

View file

@ -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<DayOfWeek> {
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),
)
}

View file

@ -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" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_sunday"
android:id="@+id/edit_notification_profile_schedule_day_1"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -144,13 +144,13 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__sunday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__sunday_first_letter" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_monday"
android:id="@+id/edit_notification_profile_schedule_day_2"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -158,13 +158,13 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__monday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__monday_first_letter" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_tuesday"
android:id="@+id/edit_notification_profile_schedule_day_3"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -172,13 +172,13 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__tuesday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__tuesday_first_letter" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_wednesday"
android:id="@+id/edit_notification_profile_schedule_day_4"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -186,13 +186,13 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__wednesday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__wednesday_first_letter" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_thursday"
android:id="@+id/edit_notification_profile_schedule_day_5"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -200,13 +200,13 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__thursday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__thursday_first_letter" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_friday"
android:id="@+id/edit_notification_profile_schedule_day_6"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -214,13 +214,13 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__friday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__friday_first_letter" />
<CheckedTextView
android:id="@+id/edit_notification_profile_schedule_saturday"
android:id="@+id/edit_notification_profile_schedule_day_7"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded"
@ -228,10 +228,10 @@
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__saturday_first_letter"
android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1"
android:textColor="@color/notification_profile_schedule_text_selector" />
android:textColor="@color/notification_profile_schedule_text_selector"
tools:text="@string/EditNotificationProfileSchedule__saturday_first_letter" />
<com.dd.CircularProgressButton
android:id="@+id/edit_notification_profile_schedule__next"

View file

@ -4148,7 +4148,7 @@
<!-- Title for add schedule to profile in create flow -->
<string name="EditNotificationProfileSchedule__add_a_schedule">Add a schedule</string>
<!-- Descriptor text indicating what the user can do with this screen -->
<string name="EditNotificationProfileSchedule__turn_on_and_edit_your_schedule_to_automate_this_profile">Turn on and edit your schedule to automate this profile.</string>
<string name="EditNotificationProfileSchedule__set_up_a_schedule_to_enable_this_notification_profile_automatically">Set up a schedule to enable this notification profile automatically.</string>
<!-- Text shown next to toggle switch to enable/disable schedule -->
<string name="EditNotificationProfileSchedule__schedule">Schedule</string>
<!-- Label for showing the start time for the schedule -->