sleep: fix date picker usage

The time the date picker uses needs to be updated.
Also make some variable names more logical.
This commit is contained in:
2026-06-18 14:28:28 +02:00
parent c75d4ed8a7
commit ddcc2fc492

View File

@@ -481,15 +481,15 @@ class MainActivity : AppCompatActivity() {
d.setTitle(event.getDialogTitle(this))
d.setView(dialogView)
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
val datePickerBegin = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
val datePickerEnd = dialogView.findViewById<TextView>(R.id.dialog_date_picker_end)
val dateDelimiter = dialogView.findViewById<TextView>(R.id.dialog_date_range_delimiter)
val durationTV = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
val datePickerBeginTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
val datePickerEndTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker_end)
val dateDelimiterTV = dialogView.findViewById<TextView>(R.id.dialog_date_range_delimiter)
val durationButtons = dialogView.findViewById<LinearLayout>(R.id.duration_buttons)
val durationNowButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_now)
val durationClearButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_clear)
val currentDurationTextColor = durationTextView.currentTextColor
val currentDurationTextColor = durationTV.currentTextColor
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
// in seconds
@@ -506,59 +506,59 @@ class MainActivity : AppCompatActivity() {
}
fun updateFields() {
datePickerBegin.text = DateUtils.formatDateTime(durationStart)
datePickerEnd.text = DateUtils.formatDateTime(durationEnd)
datePickerBeginTV.text = DateUtils.formatDateTime(durationStart)
datePickerEndTV.text = DateUtils.formatDateTime(durationEnd)
durationTextView.setTextColor(currentDurationTextColor)
dateTimePicker(durationStart, datePickerBeginTV) { pickedTime: Long ->
durationStart = pickedTime
if (datePickerEndTV.visibility == View.GONE) {
durationEnd = pickedTime
}
updateFields()
}
dateTimePicker(durationEnd, datePickerEndTV) { pickedTime: Long ->
durationEnd = pickedTime
updateFields()
}
durationTV.setTextColor(currentDurationTextColor)
val duration = durationEnd - durationStart
if (duration == 0L) {
// event is ongoing
durationTextView.text = "💤"
dateDelimiter.visibility = View.GONE
datePickerEnd.visibility = View.GONE
durationTV.text = "💤"
dateDelimiterTV.visibility = View.GONE
datePickerEndTV.visibility = View.GONE
} else {
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
durationTV.text = DateUtils.formatTimeDuration(applicationContext, duration)
if (!isValidTimeSpan(durationStart, durationEnd)) {
durationTextView.setTextColor(invalidDurationTextColor)
durationTV.setTextColor(invalidDurationTextColor)
}
dateDelimiter.visibility = View.VISIBLE
datePickerEnd.visibility = View.VISIBLE
dateDelimiterTV.visibility = View.VISIBLE
datePickerEndTV.visibility = View.VISIBLE
}
datePickerBegin.setTextColor(if (isValidTime(durationStart)) { currentDurationTextColor } else { invalidDurationTextColor })
datePickerEnd.setTextColor(if (isValidTime(durationEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
}
val colorBegin = if (isValidTime(durationStart)) { currentDurationTextColor } else { invalidDurationTextColor }
datePickerBeginTV.setTextColor(colorBegin)
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { pickedTime: Long ->
durationStart = pickedTime
if (datePickerEnd.visibility == View.GONE) {
durationEnd = pickedTime
}
updateFields()
}
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { pickedTime: Long ->
durationEnd = pickedTime
updateFields()
val colorEnd = if (isValidTime(durationEnd)) { currentDurationTextColor } else { invalidDurationTextColor }
datePickerEndTV.setTextColor(colorEnd)
}
if (showTime) {
dateDelimiter.visibility = View.GONE
datePickerEnd.visibility = View.GONE
durationTextView.visibility = View.GONE
dateDelimiterTV.visibility = View.GONE
datePickerEndTV.visibility = View.GONE
durationTV.visibility = View.GONE
durationButtons.visibility = View.GONE
//d.setMessage("")
} else {
dateDelimiter.visibility = View.VISIBLE
datePickerEnd.visibility = View.VISIBLE
durationTextView.visibility = View.VISIBLE
dateDelimiterTV.visibility = View.VISIBLE
datePickerEndTV.visibility = View.VISIBLE
durationTV.visibility = View.VISIBLE
durationButtons.visibility = View.VISIBLE
d.setMessage(event.getDialogMessage(this))
}
durationStart = pickedDateTimeBegin.time.time / 1000
durationEnd = pickedDateTimeEnd.time.time / 1000
updateFields()
durationClearButton.setOnClickListener {