use the nicer time picker on system theme

This commit is contained in:
tibbi 2023-01-02 11:48:11 +01:00
parent e4a7253b87
commit fffe86dcb0
1 changed files with 31 additions and 9 deletions

View File

@ -6,6 +6,8 @@ import android.app.TimePickerDialog
import android.app.TimePickerDialog.OnTimeSetListener import android.app.TimePickerDialog.OnTimeSetListener
import android.text.format.DateFormat import android.text.format.DateFormat
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
@ -109,6 +111,25 @@ class ScheduleMessageDialog(
val hourOfDay = dateTime?.hourOfDay ?: getNextHour() val hourOfDay = dateTime?.hourOfDay ?: getNextHour()
val minute = dateTime?.minuteOfHour ?: getNextMinute() val minute = dateTime?.minuteOfHour ?: getNextMinute()
if (activity.config.isUsingSystemTheme) {
val timeFormat = if (DateFormat.is24HourFormat(activity)) {
TimeFormat.CLOCK_24H
} else {
TimeFormat.CLOCK_12H
}
val timePicker = MaterialTimePicker.Builder()
.setTimeFormat(timeFormat)
.setHour(hourOfDay)
.setMinute(minute)
.build()
timePicker.addOnPositiveButtonClickListener {
timeSet(timePicker.hour, timePicker.minute)
}
timePicker.show(activity.supportFragmentManager, "")
} else {
val timeSetListener = OnTimeSetListener { _, hours, minutes -> timeSet(hours, minutes) } val timeSetListener = OnTimeSetListener { _, hours, minutes -> timeSet(hours, minutes) }
TimePickerDialog( TimePickerDialog(
activity, activity.getDatePickerDialogTheme(), timeSetListener, hourOfDay, minute, DateFormat.is24HourFormat(activity) activity, activity.getDatePickerDialogTheme(), timeSetListener, hourOfDay, minute, DateFormat.is24HourFormat(activity)
@ -122,6 +143,7 @@ class ScheduleMessageDialog(
} }
} }
} }
}
private fun dateSet(year: Int, monthOfYear: Int, dayOfMonth: Int) { private fun dateSet(year: Int, monthOfYear: Int, dayOfMonth: Int) {
if (isNewMessage) { if (isNewMessage) {