use a more modern timepicker with material theme

This commit is contained in:
tibbi 2022-12-26 09:55:32 +01:00
parent 2542d6fa59
commit 22d86f9214
2 changed files with 36 additions and 10 deletions

View File

@ -64,7 +64,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:971e86fcd2'
implementation 'com.github.SimpleMobileTools:Simple-Commons:0eb2785498'
implementation 'com.facebook.stetho:stetho:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.shawnlin:number-picker:2.4.6'

View File

@ -7,6 +7,8 @@ import android.media.RingtoneManager
import android.text.format.DateFormat
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SimpleActivity
import com.simplemobiletools.clock.extensions.*
@ -31,14 +33,34 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
view.apply {
edit_alarm_time.setOnClickListener {
TimePickerDialog(
context,
context.getTimePickerDialogTheme(),
timeSetListener,
alarm.timeInMinutes / 60,
alarm.timeInMinutes % 60,
DateFormat.is24HourFormat(activity)
).show()
if (activity.config.isUsingSystemTheme) {
val timeFormat = if (DateFormat.is24HourFormat(activity)) {
TimeFormat.CLOCK_24H
} else {
TimeFormat.CLOCK_12H
}
val timePicker = MaterialTimePicker.Builder()
.setTimeFormat(timeFormat)
.setHour(alarm.timeInMinutes / 60)
.setMinute(alarm.timeInMinutes % 60)
.build()
timePicker.addOnPositiveButtonClickListener {
timePicked(timePicker.hour, timePicker.minute)
}
timePicker.show(activity.supportFragmentManager, "")
} else {
TimePickerDialog(
context,
context.getTimePickerDialogTheme(),
timeSetListener,
alarm.timeInMinutes / 60,
alarm.timeInMinutes % 60,
DateFormat.is24HourFormat(activity)
).show()
}
}
edit_alarm_sound.colorCompoundDrawable(textColor)
@ -169,7 +191,11 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
}
private val timeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
alarm.timeInMinutes = hourOfDay * 60 + minute
timePicked(hourOfDay, minute)
}
private fun timePicked(hours: Int, minutes: Int) {
alarm.timeInMinutes = hours * 60 + minutes
updateAlarmTime()
}