1 Commits

Author SHA1 Message Date
53bab2d22c use creation dialog as edit dialog 2025-11-09 23:29:26 +01:00

View File

@@ -229,8 +229,6 @@ class MainActivity : AppCompatActivity() {
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
dateTextView.text = dateTextView.text =
String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time)) String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
val pickedDateTime = Calendar.getInstance()
val currentDateTime = Calendar.getInstance() val currentDateTime = Calendar.getInstance()
currentDateTime.time = Date(event.time * 1000) currentDateTime.time = Date(event.time * 1000)
dateTextView.setOnClickListener { dateTextView.setOnClickListener {
@@ -243,16 +241,17 @@ class MainActivity : AppCompatActivity() {
DatePickerDialog(this, { _, year, month, day -> DatePickerDialog(this, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute -> TimePickerDialog(this, { _, hour, minute ->
val pickedDateTime = Calendar.getInstance()
pickedDateTime.set(year, month, day, hour, minute) pickedDateTime.set(year, month, day, hour, minute)
val time = pickedDateTime.time.time / 1000 // Save event and move it to the right position in the logbook
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(time)) event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show() }, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
}, startYear, startMonth, startDay).show() }, startYear, startMonth, startDay).show()
} }
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
event.quantity = numberPicker.value * 10 event.quantity = numberPicker.value * 10
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
if (isNewEvent) { if (isNewEvent) {
logEvent(event) logEvent(event)
} }
@@ -261,12 +260,10 @@ class MainActivity : AppCompatActivity() {
saveLogbook() saveLogbook()
onEnd?.invoke() onEnd?.invoke()
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
onEnd?.invoke() onEnd?.invoke()
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
@@ -331,7 +328,7 @@ class MainActivity : AppCompatActivity() {
val spinner = dialogView.findViewById<Spinner>(R.id.dialog_puke_value) val spinner = dialogView.findViewById<Spinner>(R.id.dialog_puke_value)
spinner.adapter = ArrayAdapter.createFromResource(this, R.array.AmountLabels, android.R.layout.simple_spinner_dropdown_item) spinner.adapter = ArrayAdapter.createFromResource(this, R.array.AmountLabels, android.R.layout.simple_spinner_dropdown_item)
spinner.setSelection(event.quantity) spinner.setSelection(1)
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
event.quantity = spinner.selectedItemPosition event.quantity = spinner.selectedItemPosition
@@ -340,72 +337,7 @@ class MainActivity : AppCompatActivity() {
} }
onEnd?.invoke() onEnd?.invoke()
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
dialogInterface.dismiss()
onEnd?.invoke
}
val alertDialog = d.create()
alertDialog.show()
}
// Ask to edit events to be edited (only affects date)
fun askPlain(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) {
val isNewEvent = (existingEvent != null)
val event = if (existingEvent == null) {
LunaEvent(LunaEvent.TYPE_NOTE)
} else {
existingEvent
}
val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_plain_event, null)
d.setTitle(event.getTypeDescription(this))
d.setMessage(event.getDialogMessage(this))
d.setView(dialogView)
val dateET = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val pickedDateTime = Calendar.getInstance()
val currentDateTime = Calendar.getInstance()
currentDateTime.time = Date(event.time * 1000)
dateET.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
dateET.setOnClickListener {
// Show datetime picker
val startYear = currentDateTime.get(Calendar.YEAR)
val startMonth = currentDateTime.get(Calendar.MONTH)
val startDay = currentDateTime.get(Calendar.DAY_OF_MONTH)
val startHour = currentDateTime.get(Calendar.HOUR_OF_DAY)
val startMinute = currentDateTime.get(Calendar.MINUTE)
DatePickerDialog(this, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute ->
pickedDateTime.set(year, month, day, hour, minute)
val time = pickedDateTime.time.time / 1000
dateET.setText(String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(time)))
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
}, startYear, startMonth, startDay).show()
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
// Save event and move it to the right position in the logbook
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
if (isNewEvent) {
logEvent(event)
}
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
onEnd?.invoke()
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
onEnd?.invoke()
}
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
@@ -428,7 +360,6 @@ class MainActivity : AppCompatActivity() {
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext) val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
val dateET = dialogView.findViewById<TextView>(R.id.notes_date_picker) val dateET = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val pickedDateTime = Calendar.getInstance()
val currentDateTime = Calendar.getInstance() val currentDateTime = Calendar.getInstance()
currentDateTime.time = Date(event.time * 1000) currentDateTime.time = Date(event.time * 1000)
@@ -443,9 +374,14 @@ class MainActivity : AppCompatActivity() {
DatePickerDialog(this, { _, year, month, day -> DatePickerDialog(this, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute -> TimePickerDialog(this, { _, hour, minute ->
val pickedDateTime = Calendar.getInstance()
pickedDateTime.set(year, month, day, hour, minute) pickedDateTime.set(year, month, day, hour, minute)
val time = pickedDateTime.time.time / 1000 // Save event and move it to the right position in the logbook
dateET.setText(String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(time))) event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
dateET.setText(String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time)))
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show() }, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
}, startYear, startMonth, startDay).show() }, startYear, startMonth, startDay).show()
} }
@@ -463,22 +399,20 @@ class MainActivity : AppCompatActivity() {
val qty = qtyET.text.toString().toIntOrNull() val qty = qtyET.text.toString().toIntOrNull()
if (qty != null) { if (qty != null) {
event.quantity = qty event.quantity = qty
event.notes = notesET.text.toString()
} else { } else {
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
onEnd?.invoke() onEnd?.invoke()
return@setPositiveButton return@setPositiveButton
} }
} else {
event.notes = notesET.text.toString()
} }
event.notes = notesET.text.toString()
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
if (isNewEvent) { if (isNewEvent) {
logEvent(event) logEvent(event)
} }
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
onEnd?.invoke() onEnd?.invoke()
} }
@@ -555,8 +489,33 @@ class MainActivity : AppCompatActivity() {
quantityTextView.text = NumericUtils(this).formatEventQuantity(event) quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
notesTextView.text = event.notes notesTextView.text = event.notes
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date) val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date)
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time)) dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
/*
val currentDateTime = Calendar.getInstance()
currentDateTime.time = Date(event.time * 1000)
dateTextView.setOnClickListener {
// Show datetime picker
val startYear = currentDateTime.get(Calendar.YEAR)
val startMonth = currentDateTime.get(Calendar.MONTH)
val startDay = currentDateTime.get(Calendar.DAY_OF_MONTH)
val startHour = currentDateTime.get(Calendar.HOUR_OF_DAY)
val startMinute = currentDateTime.get(Calendar.MINUTE)
DatePickerDialog(this, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute ->
val pickedDateTime = Calendar.getInstance()
pickedDateTime.set(year, month, day, hour, minute)
// Save event and move it to the right position in the logbook
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
}, startYear, startMonth, startDay).show()
}*/
d.setView(dialogView) d.setView(dialogView)
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() } d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() }
@@ -568,18 +527,18 @@ class MainActivity : AppCompatActivity() {
LunaEvent.TYPE_WEIGHT -> {} LunaEvent.TYPE_WEIGHT -> {}
LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE, LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE, LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE, LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE -> {}
LunaEvent.TYPE_ENEMA,
LunaEvent.TYPE_BATH,
LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_DIAPERCHANGE_POO, LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE -> { askPlain(event, { showEventDetailDialog(event) }) } LunaEvent.TYPE_DIAPERCHANGE_PEE -> {}
LunaEvent.TYPE_MEDICINE -> askNotes(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_MEDICINE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_ENEMA -> {}
LunaEvent.TYPE_NOTE -> askNotes(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_NOTE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_TEMPERATURE, //todo LunaEvent.TYPE_TEMPERATURE,
LunaEvent.TYPE_FOOD -> askNotes(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_FOOD -> {}
LunaEvent.TYPE_PUKE -> askPukeValue(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_PUKE -> askPukeValue(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_CUSTOM -> {} // todo? LunaEvent.TYPE_BATH,
LunaEvent.TYPE_CUSTOM -> {}
else -> {} else -> {}
} }
} }