kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix 24hr time format bug on older OSes.
rodzic
a0235cbc6c
commit
93270b90df
|
@ -87,7 +87,7 @@ object NotificationProfileSelection {
|
|||
expansion.visible = model.isExpanded
|
||||
timeSlotB.text = context.getString(
|
||||
R.string.NotificationProfileSelection__until_s,
|
||||
LocalTime.from(model.timeSlotB).formatHours()
|
||||
LocalTime.from(model.timeSlotB).formatHours(context)
|
||||
)
|
||||
|
||||
if (TOGGLE_EXPANSION in payload || UPDATE_TIMESLOT in payload) {
|
||||
|
@ -107,7 +107,7 @@ object NotificationProfileSelection {
|
|||
|
||||
timeSlotB.text = context.getString(
|
||||
R.string.NotificationProfileSelection__until_s,
|
||||
LocalTime.from(model.timeSlotB).formatHours()
|
||||
LocalTime.from(model.timeSlotB).formatHours(context)
|
||||
)
|
||||
|
||||
itemView.isSelected = model.isOn
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.thoughtcrime.securesms.components.settings.app.notifications.profiles
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
|
@ -105,7 +106,7 @@ class EditNotificationProfileScheduleFragment : LoggingFragment(R.layout.fragmen
|
|||
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))
|
||||
DrawableCompat.setTintList(view.background, ContextCompat.getColorStateList(view.context, R.color.notification_profile_schedule_background_tint))
|
||||
view.setOnClickListener { viewModel.toggleDay(day) }
|
||||
view.setText(DAY_TO_STARTING_LETTER[day]!!)
|
||||
}
|
||||
|
@ -121,11 +122,11 @@ class EditNotificationProfileScheduleFragment : LoggingFragment(R.layout.fragmen
|
|||
view.isEnabled = schedule.enabled
|
||||
}
|
||||
|
||||
startTime.text = schedule.startTime().formatTime()
|
||||
startTime.text = schedule.startTime().formatTime(view.context)
|
||||
startTime.setOnClickListener { showTimeSelector(true, schedule.startTime()) }
|
||||
startTime.isEnabled = schedule.enabled
|
||||
|
||||
endTime.text = schedule.endTime().formatTime()
|
||||
endTime.text = schedule.endTime().formatTime(view.context)
|
||||
endTime.setOnClickListener { showTimeSelector(false, schedule.endTime()) }
|
||||
endTime.isEnabled = schedule.enabled
|
||||
|
||||
|
@ -168,11 +169,11 @@ class EditNotificationProfileScheduleFragment : LoggingFragment(R.layout.fragmen
|
|||
}
|
||||
}
|
||||
|
||||
private fun LocalTime.formatTime(): SpannableString {
|
||||
private fun LocalTime.formatTime(context: Context): SpannableString {
|
||||
val amPm = DateTimeFormatter.ofPattern("a")
|
||||
.format(this)
|
||||
|
||||
val formattedTime: String = this.formatHours()
|
||||
val formattedTime: String = this.formatHours(context)
|
||||
|
||||
return SpannableString(formattedTime).apply {
|
||||
val amPmIndex = formattedTime.indexOf(string = amPm, ignoreCase = true)
|
||||
|
|
|
@ -234,8 +234,8 @@ class NotificationProfileDetailsFragment : DSLSettingsFragment() {
|
|||
return getString(R.string.NotificationProfileDetails__schedule)
|
||||
}
|
||||
|
||||
val startTime = startTime().formatHours()
|
||||
val endTime = endTime().formatHours()
|
||||
val startTime = startTime().formatHours(requireContext())
|
||||
val endTime = endTime().formatHours(requireContext())
|
||||
|
||||
val days = StringBuilder()
|
||||
if (daysEnabled.size == 7) {
|
||||
|
|
|
@ -52,11 +52,11 @@ object NotificationProfiles {
|
|||
if (storeValues.manuallyEnabledUntil.isForever()) {
|
||||
return context.getString(R.string.NotificationProfilesFragment__on)
|
||||
} else if (now < storeValues.manuallyEnabledUntil) {
|
||||
return context.getString(R.string.NotificationProfileSelection__on_until_s, storeValues.manuallyEnabledUntil.toLocalTime().formatHours())
|
||||
return context.getString(R.string.NotificationProfileSelection__on_until_s, storeValues.manuallyEnabledUntil.toLocalTime().formatHours(context))
|
||||
}
|
||||
}
|
||||
|
||||
return context.getString(R.string.NotificationProfileSelection__on_until_s, profile.schedule.endTime().formatHours())
|
||||
return context.getString(R.string.NotificationProfileSelection__on_until_s, profile.schedule.endTime().formatHours(context))
|
||||
}
|
||||
|
||||
private fun Long.isForever(): Boolean {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.text.format.DateFormat
|
||||
import java.time.DayOfWeek
|
||||
import java.time.Instant
|
||||
import java.time.LocalDateTime
|
||||
|
@ -51,8 +54,12 @@ fun Long.toLocalTime(zoneId: ZoneId = ZoneId.systemDefault()): LocalTime {
|
|||
/**
|
||||
* Formats [LocalTime] as localized time. For example, "8:00 AM"
|
||||
*/
|
||||
fun LocalTime.formatHours(): String {
|
||||
return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(this)
|
||||
fun LocalTime.formatHours(context: Context): String {
|
||||
return if (Build.VERSION.SDK_INT >= 26 || !DateFormat.is24HourFormat(context)) {
|
||||
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(this)
|
||||
} else {
|
||||
DateTimeFormatter.ofPattern("HH:mm", Locale.getDefault()).format(this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Ładowanie…
Reference in New Issue