1 Commits

Author SHA1 Message Date
4e9eeff6aa use creation dialog as edit dialog 2025-11-10 00:04:40 +01:00

View File

@@ -229,6 +229,8 @@ class MainActivity : AppCompatActivity() {
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
dateTextView.text =
String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
val pickedDateTime = Calendar.getInstance()
val currentDateTime = Calendar.getInstance()
currentDateTime.time = Date(event.time * 1000)
dateTextView.setOnClickListener {
@@ -241,17 +243,16 @@ class MainActivity : AppCompatActivity() {
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))
val time = pickedDateTime.time.time / 1000
dateTextView.text = 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 ->
event.quantity = numberPicker.value * 10
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
if (isNewEvent) {
logEvent(event)
}
@@ -260,10 +261,12 @@ class MainActivity : AppCompatActivity() {
saveLogbook()
onEnd?.invoke()
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
onEnd?.invoke()
}
val alertDialog = d.create()
alertDialog.show()
}
@@ -328,7 +331,7 @@ class MainActivity : AppCompatActivity() {
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.setSelection(1)
spinner.setSelection(event.quantity)
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
event.quantity = spinner.selectedItemPosition
@@ -337,7 +340,72 @@ class MainActivity : AppCompatActivity() {
}
onEnd?.invoke()
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
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()
alertDialog.show()
}
@@ -360,6 +428,7 @@ class MainActivity : AppCompatActivity() {
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
val dateET = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val pickedDateTime = Calendar.getInstance()
val currentDateTime = Calendar.getInstance()
currentDateTime.time = Date(event.time * 1000)
@@ -374,14 +443,9 @@ class MainActivity : AppCompatActivity() {
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
dateET.setText(String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time)))
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
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()
}
@@ -399,20 +463,22 @@ class MainActivity : AppCompatActivity() {
val qty = qtyET.text.toString().toIntOrNull()
if (qty != null) {
event.quantity = qty
event.notes = notesET.text.toString()
} else {
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
onEnd?.invoke()
return@setPositiveButton
}
} else {
event.notes = notesET.text.toString()
}
event.notes = notesET.text.toString()
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
if (isNewEvent) {
logEvent(event)
}
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
onEnd?.invoke()
}
@@ -489,33 +555,8 @@ class MainActivity : AppCompatActivity() {
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
notesTextView.text = event.notes
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))
/*
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.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() }
@@ -527,18 +568,18 @@ class MainActivity : AppCompatActivity() {
LunaEvent.TYPE_WEIGHT -> {}
LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE -> {}
LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE -> {}
LunaEvent.TYPE_MEDICINE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_ENEMA -> {}
LunaEvent.TYPE_NOTE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_TEMPERATURE,
LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_FOOD -> {}
LunaEvent.TYPE_PUKE -> askPukeValue(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE,
LunaEvent.TYPE_ENEMA,
LunaEvent.TYPE_BATH,
LunaEvent.TYPE_CUSTOM -> {}
LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE -> { askPlain(event, { showEventDetailDialog(event) }) }
LunaEvent.TYPE_MEDICINE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_NOTE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_TEMPERATURE, //todo
LunaEvent.TYPE_FOOD -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_PUKE -> askPukeValue(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_CUSTOM -> {} // todo?
else -> {}
}
}