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

fork-5.53.8
Cody Henthorne 2021-12-09 11:42:56 -05:00
rodzic 884710fc30
commit 4c28619010
5 zmienionych plików z 66 dodań i 43 usunięć

Wyświetl plik

@ -25,10 +25,22 @@ import org.thoughtcrime.securesms.components.settings.app.notifications.profiles
import org.thoughtcrime.securesms.util.LifecycleDisposable import org.thoughtcrime.securesms.util.LifecycleDisposable
import org.thoughtcrime.securesms.util.ViewUtil import org.thoughtcrime.securesms.util.ViewUtil
import org.thoughtcrime.securesms.util.formatHours import org.thoughtcrime.securesms.util.formatHours
import org.thoughtcrime.securesms.util.orderOfDaysInWeek
import org.thoughtcrime.securesms.util.visible import org.thoughtcrime.securesms.util.visible
import java.time.DayOfWeek import java.time.DayOfWeek
import java.time.LocalTime import java.time.LocalTime
import java.time.format.DateTimeFormatter 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. * 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 day1: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_1)
val monday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_monday) val day2: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_2)
val tuesday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_tuesday) val day3: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_3)
val wednesday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_wednesday) val day4: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_4)
val thursday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_thursday) val day5: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_5)
val friday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_friday) val day6: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_6)
val saturday: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_saturday) val day7: CheckedTextView = view.findViewById(R.id.edit_notification_profile_schedule_day_7)
val days: Map<CheckedTextView, DayOfWeek> = mapOf( val days: Map<CheckedTextView, DayOfWeek> = listOf(day1, day2, day3, day4, day5, day6, day7).zip(Locale.getDefault().orderOfDaysInWeek()).toMap()
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
)
days.forEach { (view, day) -> days.forEach { (view, day) ->
DrawableCompat.setTintList(view.background, ContextCompat.getColorStateList(requireContext(), R.color.notification_profile_schedule_background_tint)) DrawableCompat.setTintList(view.background, ContextCompat.getColorStateList(requireContext(), R.color.notification_profile_schedule_background_tint))
view.setOnClickListener { viewModel.toggleDay(day) } view.setOnClickListener { viewModel.toggleDay(day) }
view.setText(DAY_TO_STARTING_LETTER[day]!!)
} }
lifecycleDisposable += viewModel.schedule() lifecycleDisposable += viewModel.schedule()

Wyświetl plik

@ -32,12 +32,11 @@ import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.util.LifecycleDisposable import org.thoughtcrime.securesms.util.LifecycleDisposable
import org.thoughtcrime.securesms.util.SpanUtil import org.thoughtcrime.securesms.util.SpanUtil
import org.thoughtcrime.securesms.util.formatHours import org.thoughtcrime.securesms.util.formatHours
import org.thoughtcrime.securesms.util.orderOfDaysInWeek
import java.time.DayOfWeek import java.time.DayOfWeek
import java.time.format.TextStyle import java.time.format.TextStyle
import java.util.Locale 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() { class NotificationProfileDetailsFragment : DSLSettingsFragment() {
private val viewModel: NotificationProfileDetailsViewModel by viewModels(factoryProducer = this::createFactory) private val viewModel: NotificationProfileDetailsViewModel by viewModels(factoryProducer = this::createFactory)
@ -221,7 +220,7 @@ class NotificationProfileDetailsFragment : DSLSettingsFragment() {
if (daysEnabled.size == 7) { if (daysEnabled.size == 7) {
days.append(getString(R.string.NotificationProfileDetails__everyday)) days.append(getString(R.string.NotificationProfileDetails__everyday))
} else { } else {
for (day in DAY_ORDER) { for (day: DayOfWeek in Locale.getDefault().orderOfDaysInWeek()) {
if (daysEnabled.contains(day)) { if (daysEnabled.contains(day)) {
if (days.isNotEmpty()) { if (days.isNotEmpty()) {
days.append(", ") days.append(", ")

Wyświetl plik

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.util package org.thoughtcrime.securesms.util
import java.time.DayOfWeek
import java.time.Instant import java.time.Instant
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.LocalTime import java.time.LocalTime
@ -8,6 +9,8 @@ import java.time.ZoneId
import java.time.ZoneOffset import java.time.ZoneOffset
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle
import java.time.temporal.WeekFields
import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
/** /**
@ -51,3 +54,19 @@ fun Long.toLocalTime(zoneId: ZoneId = ZoneId.systemDefault()): LocalTime {
fun LocalTime.formatHours(): String { fun LocalTime.formatHours(): String {
return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(this) 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),
)
}

Wyświetl plik

@ -43,7 +43,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginEnd="@dimen/dsl_settings_gutter" android:layout_marginEnd="@dimen/dsl_settings_gutter"
android:gravity="center" 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" android:textAppearance="@style/TextAppearance.Signal.Body1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -128,7 +128,7 @@
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:layout_marginEnd="16dp" 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_horizontalStyle="spread_inside"
app:flow_wrapMode="aligned" app:flow_wrapMode="aligned"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -136,7 +136,7 @@
app:layout_constraintTop_toBottomOf="@+id/edit_notification_profile_schedule_start_time" /> app:layout_constraintTop_toBottomOf="@+id/edit_notification_profile_schedule_start_time" />
<CheckedTextView <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_sunday" android:id="@+id/edit_notification_profile_schedule_day_1"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -144,13 +144,13 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__sunday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_monday" android:id="@+id/edit_notification_profile_schedule_day_2"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -158,13 +158,13 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__monday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_tuesday" android:id="@+id/edit_notification_profile_schedule_day_3"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -172,13 +172,13 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__tuesday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_wednesday" android:id="@+id/edit_notification_profile_schedule_day_4"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -186,13 +186,13 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__wednesday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_thursday" android:id="@+id/edit_notification_profile_schedule_day_5"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -200,13 +200,13 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__thursday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_friday" android:id="@+id/edit_notification_profile_schedule_day_6"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -214,13 +214,13 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__friday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <CheckedTextView
android:id="@+id/edit_notification_profile_schedule_saturday" android:id="@+id/edit_notification_profile_schedule_day_7"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle_tintable_padded" android:background="@drawable/circle_tintable_padded"
@ -228,10 +228,10 @@
android:foreground="?selectableItemBackgroundBorderless" android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center" android:gravity="center"
android:padding="6dp" android:padding="6dp"
android:text="@string/EditNotificationProfileSchedule__saturday_first_letter"
android:textAlignment="gravity" android:textAlignment="gravity"
android:textAppearance="@style/TextAppearance.Signal.Body1" 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 <com.dd.CircularProgressButton
android:id="@+id/edit_notification_profile_schedule__next" android:id="@+id/edit_notification_profile_schedule__next"

Wyświetl plik

@ -4148,7 +4148,7 @@
<!-- Title for add schedule to profile in create flow --> <!-- Title for add schedule to profile in create flow -->
<string name="EditNotificationProfileSchedule__add_a_schedule">Add a schedule</string> <string name="EditNotificationProfileSchedule__add_a_schedule">Add a schedule</string>
<!-- Descriptor text indicating what the user can do with this screen --> <!-- 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 --> <!-- Text shown next to toggle switch to enable/disable schedule -->
<string name="EditNotificationProfileSchedule__schedule">Schedule</string> <string name="EditNotificationProfileSchedule__schedule">Schedule</string>
<!-- Label for showing the start time for the schedule --> <!-- Label for showing the start time for the schedule -->