Skip to content

Commit

Permalink
Use 24h mode for time picker if appropriate (openhab#3582)
Browse files Browse the repository at this point in the history
Fixes openhab#3581

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 authored Jan 25, 2024
1 parent 2a7face commit efbb75a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.text.InputType.TYPE_CLASS_NUMBER
import android.text.InputType.TYPE_CLASS_TEXT
import android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL
import android.text.InputType.TYPE_NUMBER_FLAG_SIGNED
import android.text.format.DateFormat
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
Expand Down Expand Up @@ -67,6 +68,7 @@ import com.google.android.material.materialswitch.MaterialSwitch
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import java.io.IOException
import java.time.Instant
import java.time.LocalDate
Expand Down Expand Up @@ -760,7 +762,13 @@ class WidgetAdapter(
private fun showTimePicker(widget: Widget, dt: LocalDateTime?) {
val date = dt?.truncatedTo(ChronoUnit.MINUTES)
?: LocalDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneOffset.UTC)
val timeFormat = if (DateFormat.is24HourFormat(itemView.context)) {
TimeFormat.CLOCK_24H
} else {
TimeFormat.CLOCK_12H
}
val timePicker = MaterialTimePicker.Builder()
.setTimeFormat(timeFormat)
.setHour(date.hour)
.setMinute(date.minute)
.build()
Expand Down

0 comments on commit efbb75a

Please sign in to comment.