use the nicer time picker on system theme
This commit is contained in:
parent
e4a7253b87
commit
fffe86dcb0
|
@ -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,15 +111,35 @@ class ScheduleMessageDialog(
|
||||||
val hourOfDay = dateTime?.hourOfDay ?: getNextHour()
|
val hourOfDay = dateTime?.hourOfDay ?: getNextHour()
|
||||||
val minute = dateTime?.minuteOfHour ?: getNextMinute()
|
val minute = dateTime?.minuteOfHour ?: getNextMinute()
|
||||||
|
|
||||||
val timeSetListener = OnTimeSetListener { _, hours, minutes -> timeSet(hours, minutes) }
|
if (activity.config.isUsingSystemTheme) {
|
||||||
TimePickerDialog(
|
val timeFormat = if (DateFormat.is24HourFormat(activity)) {
|
||||||
activity, activity.getDatePickerDialogTheme(), timeSetListener, hourOfDay, minute, DateFormat.is24HourFormat(activity)
|
TimeFormat.CLOCK_24H
|
||||||
).apply {
|
} else {
|
||||||
show()
|
TimeFormat.CLOCK_12H
|
||||||
getButton(AlertDialog.BUTTON_NEGATIVE).apply {
|
}
|
||||||
text = activity.getString(R.string.cancel)
|
|
||||||
setOnClickListener {
|
val timePicker = MaterialTimePicker.Builder()
|
||||||
dismiss()
|
.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) }
|
||||||
|
TimePickerDialog(
|
||||||
|
activity, activity.getDatePickerDialogTheme(), timeSetListener, hourOfDay, minute, DateFormat.is24HourFormat(activity)
|
||||||
|
).apply {
|
||||||
|
show()
|
||||||
|
getButton(AlertDialog.BUTTON_NEGATIVE).apply {
|
||||||
|
text = activity.getString(R.string.cancel)
|
||||||
|
setOnClickListener {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue