1 Commits

Author SHA1 Message Date
5ffeff445f allow editing of all events
Allow to set the date of each event
on creation.

Allow to change the date/time and
other relevant values of an event
after it was created.
2025-11-11 22:11:20 +01:00
8 changed files with 229 additions and 202 deletions

View File

@@ -62,7 +62,7 @@ class MainActivity : AppCompatActivity() {
val updateListRunnable: Runnable = Runnable { val updateListRunnable: Runnable = Runnable {
if (logbook != null && !pauseLogbookUpdate) if (logbook != null && !pauseLogbookUpdate)
loadLogbook(logbook!!.name) loadLogbook(logbook!!.name)
handler.postDelayed(updateListRunnable, 1000*60) handler.postDelayed(updateListRunnable, 1000 * 60)
} }
var logbookRepo: LogbookRepository? = null var logbookRepo: LogbookRepository? = null
var showingOverflowPopupWindow = false var showingOverflowPopupWindow = false
@@ -81,30 +81,30 @@ class MainActivity : AppCompatActivity() {
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext)) recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
// Set listeners // Set listeners
findViewById<View>(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog(true) } findViewById<View>(R.id.logbooks_add_button).setOnClickListener {
findViewById<View>(R.id.button_bottle).setOnClickListener { askBabyBottleContent(LunaEvent(LunaEvent.TYPE_BABY_BOTTLE)) } showAddLogbookDialog(true)
findViewById<View>(R.id.button_food).setOnClickListener { askNotes(LunaEvent(LunaEvent.TYPE_FOOD)) } }
findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent( findViewById<View>(R.id.button_bottle).setOnClickListener {
LunaEvent( addBabyBottleEvent()
LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE }
) findViewById<View>(R.id.button_food).setOnClickListener {
) } addNoteEvent(LunaEvent(LunaEvent.TYPE_FOOD))
findViewById<View>(R.id.button_nipple_both).setOnClickListener { logEvent( }
LunaEvent( findViewById<View>(R.id.button_nipple_left).setOnClickListener {
LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE addPlainEvent(LunaEvent(LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE))
) }
) } findViewById<View>(R.id.button_nipple_both).setOnClickListener {
findViewById<View>(R.id.button_nipple_right).setOnClickListener { logEvent( addPlainEvent(LunaEvent(LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE))
LunaEvent( }
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE findViewById<View>(R.id.button_nipple_right).setOnClickListener {
) addPlainEvent(LunaEvent(LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE))
) } }
findViewById<View>(R.id.button_change_poo).setOnClickListener { logEvent( findViewById<View>(R.id.button_change_poo).setOnClickListener {
LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_POO) addPlainEvent(LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_POO))
) } }
findViewById<View>(R.id.button_change_pee).setOnClickListener { logEvent( findViewById<View>(R.id.button_change_pee).setOnClickListener {
LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_PEE) addPlainEvent(LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_PEE))
) } }
val moreButton = findViewById<View>(R.id.button_more) val moreButton = findViewById<View>(R.id.button_more)
moreButton.setOnClickListener { moreButton.setOnClickListener {
showOverflowPopupWindow(moreButton) showOverflowPopupWindow(moreButton)
@@ -126,7 +126,7 @@ class MainActivity : AppCompatActivity() {
private fun setListAdapter(items: ArrayList<LunaEvent>) { private fun setListAdapter(items: ArrayList<LunaEvent>) {
val adapter = LunaEventRecyclerAdapter(this, items) val adapter = LunaEventRecyclerAdapter(this, items)
adapter.onItemClickListener = object: LunaEventRecyclerAdapter.OnItemClickListener { adapter.onItemClickListener = object : LunaEventRecyclerAdapter.OnItemClickListener {
override fun onItemClick(event: LunaEvent) { override fun onItemClick(event: LunaEvent) {
showEventDetailDialog(event) showEventDetailDialog(event)
} }
@@ -195,9 +195,16 @@ class MainActivity : AppCompatActivity() {
return logbook?.logs ?: arrayListOf() return logbook?.logs ?: arrayListOf()
} }
fun askBabyBottleContent(event: LunaEvent, showDetailsAtEnd : Boolean = false) { fun addBabyBottleEvent() {
val event = LunaEvent(LunaEvent.TYPE_BABY_BOTTLE)
askBabyBottleContent(event, true) {
saveEvent(event)
}
}
fun askBabyBottleContent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null) val dialogView = layoutInflater.inflate(R.layout.dialog_edit_volume, null)
d.setTitle(R.string.log_bottle_dialog_title) d.setTitle(R.string.log_bottle_dialog_title)
d.setMessage(R.string.log_bottle_dialog_description) d.setMessage(R.string.log_bottle_dialog_description)
d.setView(dialogView) d.setView(dialogView)
@@ -210,70 +217,63 @@ class MainActivity : AppCompatActivity() {
numberPicker.value = event.quantity / 10 numberPicker.value = event.quantity / 10
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) val pickedTime = datePickHelper(event.time, dateTV)
if (!showTime) {
dateTV.visibility = View.GONE
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val quantity = numberPicker.value * 10 event.time = pickedTime.time.time / 1000
val time = pickedDateTime.time.time / 1000 event.quantity = numberPicker.value * 10
onPositive()
if (event.time != time || event.quantity != quantity) { dialogInterface.dismiss()
event.time = time
event.quantity = quantity
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askWeightValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun addWeightEvent(event: LunaEvent) {
askWeightValue(event, true) { saveEvent(event) }
}
fun askWeightValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
// Show number picker dialog // Show number picker dialog
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.number_edit_dialog, null) val dialogView = layoutInflater.inflate(R.layout.dialog_edit_weight, null)
d.setTitle(R.string.log_weight_dialog_title) d.setTitle(R.string.log_weight_dialog_title)
d.setMessage(R.string.log_weight_dialog_description) d.setMessage(R.string.log_weight_dialog_description)
d.setView(dialogView) d.setView(dialogView)
val weightET = dialogView.findViewById<EditText>(R.id.dialog_number_edittext) val weightET = dialogView.findViewById<EditText>(R.id.dialog_number_edittext)
weightET.setText(event.quantity.toString())
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) val pickedTime = datePickHelper(event.time, dateTV)
if (!showTime) {
dateTV.visibility = View.GONE
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val weight = weightET.text.toString().toIntOrNull() val weight = weightET.text.toString().toIntOrNull()
if (weight != null) { if (weight != null) {
val quantity = weight event.time = pickedTime.time.time / 1000
val time = pickedDateTime.time.time / 1000 event.quantity = weight
if (event.time != time || event.quantity != quantity) {
event.time = time
event.quantity = quantity
saveEvent(event)
}
} 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()
} }
if (showDetailsAtEnd) { onPositive()
showEventDetailDialog(event) dialogInterface.dismiss()
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
dialogInterface.dismiss() dialogInterface.dismiss()
} }
@@ -281,13 +281,18 @@ class MainActivity : AppCompatActivity() {
alertDialog.show() alertDialog.show()
} }
fun askTemperatureValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun addTemperatureEvent(event: LunaEvent) {
askTemperatureValue(event, true) { saveEvent(event) }
}
fun askTemperatureValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
// Show number picker dialog // Show number picker dialog
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.temperature_dialog, null) val dialogView = layoutInflater.inflate(R.layout.temperature_dialog, null)
d.setTitle(R.string.log_temperature_dialog_title) d.setTitle(R.string.log_temperature_dialog_title)
d.setMessage(R.string.log_temperature_dialog_description) d.setMessage(R.string.log_temperature_dialog_description)
d.setView(dialogView) d.setView(dialogView)
val tempSlider = dialogView.findViewById<Slider>(R.id.dialog_temperature_value) val tempSlider = dialogView.findViewById<Slider>(R.id.dialog_temperature_value)
val range = NumericUtils(this).getValidEventQuantityRange(LunaEvent.TYPE_TEMPERATURE)!! val range = NumericUtils(this).getValidEventQuantityRange(LunaEvent.TYPE_TEMPERATURE)!!
tempSlider.valueFrom = range.first.toFloat() tempSlider.valueFrom = range.first.toFloat()
@@ -295,41 +300,35 @@ class MainActivity : AppCompatActivity() {
tempSlider.value = range.third.toFloat() tempSlider.value = range.third.toFloat()
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) val pickedTime = datePickHelper(event.time, dateTV)
if (!showTime) {
dateTV.visibility = View.GONE
}
val tempTextView = dialogView.findViewById<TextView>(R.id.dialog_temperature_display) val tempTextView = dialogView.findViewById<TextView>(R.id.dialog_temperature_display)
tempTextView.text = range.third.toString() tempTextView.text = range.third.toString()
tempSlider.addOnChangeListener({s, v, b -> tempTextView.text = v.toString()}) tempSlider.addOnChangeListener({ s, v, b -> tempTextView.text = v.toString() })
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val quantity = (tempSlider.value * 10).toInt() // temperature in tenth of a grade event.time = pickedTime.time.time / 1000
val time = pickedDateTime.time.time / 1000 event.quantity = (tempSlider.value * 10).toInt() // temperature in tenth of a grade
if (event.time != time || event.quantity != quantity) { onPositive()
event.time = time dialogInterface.dismiss()
event.quantity = quantity
saveEvent(event)
} }
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun datePickHelper(eventTime: Long, dateTextView: TextView): Calendar { fun datePickHelper(time: Long, dateTextView: TextView): Calendar {
val fmt = getString(R.string.dialog_event_detail_datetime_icon) dateTextView.text = DateUtils.formatDateTime(time)
dateTextView.text = String.format(fmt, DateUtils.formatDateTime(eventTime))
val dateTime = Calendar.getInstance() val dateTime = Calendar.getInstance()
dateTime.time = Date(eventTime * 1000) dateTime.time = Date(time * 1000)
dateTextView.setOnClickListener { dateTextView.setOnClickListener {
// Show datetime picker // Show datetime picker
val startYear = dateTime.get(Calendar.YEAR) val startYear = dateTime.get(Calendar.YEAR)
@@ -338,12 +337,17 @@ class MainActivity : AppCompatActivity() {
val startHour = dateTime.get(Calendar.HOUR_OF_DAY) val startHour = dateTime.get(Calendar.HOUR_OF_DAY)
val startMinute = dateTime.get(Calendar.MINUTE) val startMinute = dateTime.get(Calendar.MINUTE)
DatePickerDialog(this, { _, year, month, day -> DatePickerDialog(applicationContext, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute -> TimePickerDialog(
applicationContext,
{ _, hour, minute ->
dateTime.set(year, month, day, hour, minute) dateTime.set(year, month, day, hour, minute)
val time = dateTime.time.time / 1000 dateTextView.text = DateUtils.formatDateTime(dateTime.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() startHour,
startMinute,
android.text.format.DateFormat.is24HourFormat(this@MainActivity)
).show()
}, startYear, startMonth, startDay).show() }, startYear, startMonth, startDay).show()
} }
@@ -361,47 +365,52 @@ class MainActivity : AppCompatActivity() {
saveLogbook() saveLogbook()
} }
fun askPukeValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun addPukeEvent(event: LunaEvent) {
askPukeValue(event, true) { saveEvent(event) }
}
fun askPukeValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.puke_dialog, null) val dialogView = layoutInflater.inflate(R.layout.dialog_puke, null)
d.setTitle(R.string.log_puke_dialog_title) d.setTitle(R.string.log_puke_dialog_title)
d.setMessage(R.string.log_puke_dialog_description) d.setMessage(R.string.log_puke_dialog_description)
d.setView(dialogView) d.setView(dialogView)
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(
spinner.setSelection(event.quantity) this,
R.array.AmountLabels,
android.R.layout.simple_spinner_dropdown_item
)
spinner.setSelection(event.quantity - 1)
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) val pickedTime = datePickHelper(event.time, dateTV)
if (!showTime) {
dateTV.visibility = View.GONE
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val quantity = spinner.selectedItemPosition + 1 event.time = pickedTime.time.time / 1000
val time = pickedDateTime.time.time / 1000 event.quantity = spinner.selectedItemPosition + 1
if (event.time != time || event.quantity != quantity) { onPositive()
event.time = time dialogInterface.dismiss()
event.quantity = quantity
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun addPlainEvent(event: LunaEvent) {
askDateValue(event, true) { saveEvent(event) }
}
// Ask to edit events to be edited (only affects date) // Ask to edit events to be edited (only affects date)
fun askPlain(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun askDateValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_plain_event, null) val dialogView = layoutInflater.inflate(R.layout.dialog_plain_event, null)
d.setTitle(event.getTypeDescription(this)) d.setTitle(event.getTypeDescription(this))
@@ -410,34 +419,29 @@ class MainActivity : AppCompatActivity() {
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) val pickedDateTime = datePickHelper(event.time, dateTV)
if (!showTime) {
dateTV.visibility = View.GONE
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val time = pickedDateTime.time.time / 1000 event.time = pickedDateTime.time.time / 1000
if (event.time != time) { onPositive()
event.time = time dialogInterface.dismiss()
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
// a shortcut, since the only value to change is the date
dateTV.performClick()
} }
fun askNotes(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun addNoteEvent(event: LunaEvent) {
askNotes(event, true) { saveEvent(event) }
}
fun askNotes(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
val useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM) val useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM)
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
@@ -449,7 +453,11 @@ class MainActivity : AppCompatActivity() {
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext) val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
val dateTV = dialogView.findViewById<TextView>(R.id.notes_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) val pickedTime = datePickHelper(event.time, dateTV)
if (!showTime) {
dateTV.visibility = View.GONE
}
notesET.setText(event.notes) notesET.setText(event.notes)
@@ -461,42 +469,29 @@ class MainActivity : AppCompatActivity() {
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val notes = notesET.text.toString() val notes = notesET.text.toString()
val time = pickedDateTime.time.time / 1000
if (useQuantity) { if (useQuantity) {
val quantity = qtyET.text.toString().toIntOrNull() val quantity = qtyET.text.toString().toIntOrNull()
if (quantity != null) { if (quantity != null) {
if (event.time != time || event.notes != notes || event.quantity != quantity ) { event.time = pickedTime.time.time / 1000
event.time = time
event.notes = notes
event.quantity = quantity event.quantity = quantity
saveEvent(event) event.notes = notes
}
} 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()
} }
if (showDetailsAtEnd) { onPositive()
showEventDetailDialog(event)
}
} else { } else {
if (event.time != time || event.notes != notes) { event.time = pickedTime.time.time / 1000
event.time = time
event.notes = notes event.notes = notes
saveEvent(event) onPositive()
} }
if (showDetailsAtEnd) { dialogInterface.dismiss()
showEventDetailDialog(event)
}
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
@@ -551,55 +546,68 @@ class MainActivity : AppCompatActivity() {
return nextEvent return nextEvent
} }
fun showEventDetailDialog(event: LunaEvent) { fun showEventDetailDialog(originalEvent: LunaEvent) {
val event = LunaEvent(originalEvent)
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user // Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
pauseLogbookUpdate = true pauseLogbookUpdate = true
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
d.setTitle(R.string.dialog_event_detail_title) d.setTitle(R.string.dialog_event_detail_title)
val dialogView = layoutInflater.inflate(R.layout.dialog_event_detail, null)
val dialogView = layoutInflater.inflate(R.layout.dialog_event_details, null)
val emojiTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji) val emojiTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji)
val descriptionTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description) val descriptionTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description)
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date)
val quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity) val quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity)
val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes) val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes)
emojiTextView.text = event.getTypeEmoji(this) emojiTextView.text = event.getTypeEmoji(applicationContext)
descriptionTextView.text = event.getTypeDescription(this) descriptionTextView.text = event.getTypeDescription(applicationContext)
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
notesTextView.text = event.notes
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date) val pickedTime = datePickHelper(event.time, dateTextView)
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time)) val updateValues = {
quantityTextView.text = NumericUtils(applicationContext).formatEventQuantity(event)
notesTextView.text = event.notes
}
updateValues()
quantityTextView.setOnClickListener {
when (event.type) {
LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, false, updateValues)
LunaEvent.TYPE_WEIGHT -> askWeightValue(event, false, updateValues)
LunaEvent.TYPE_PUKE -> askPukeValue(event, false, updateValues)
LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, false, updateValues)
LunaEvent.TYPE_NOTE -> askNotes(event, false, updateValues)
}
}
notesTextView.setOnClickListener {
when (event.type) {
LunaEvent.TYPE_FOOD,
LunaEvent.TYPE_MEDICINE,
LunaEvent.TYPE_NOTE -> askNotes(event, false, updateValues)
}
}
d.setView(dialogView) d.setView(dialogView)
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() } d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i ->
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> deleteEvent(event) } deleteEvent(event)
d.setNegativeButton(R.string.dialog_event_detail_edit_button) { dialogInterface, i -> dialogInterface.dismiss()
when (event.type) {
LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, true)
LunaEvent.TYPE_WEIGHT -> askWeightValue(event, true)
LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE,
LunaEvent.TYPE_ENEMA,
LunaEvent.TYPE_BATH,
LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_CUSTOM,
LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE -> askPlain(event, true)
LunaEvent.TYPE_MEDICINE -> askNotes(event, true)
LunaEvent.TYPE_NOTE -> askNotes(event, true)
LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, true)
LunaEvent.TYPE_FOOD -> askNotes(event, true)
LunaEvent.TYPE_PUKE -> askPukeValue(event, true)
else -> {}
} }
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i ->
event.time = pickedTime.time.time / 1000
if (event.time != originalEvent.time
|| event.quantity != originalEvent.quantity
|| event.notes != originalEvent.notes) {
originalEvent.time = event.time
originalEvent.quantity = event.quantity
originalEvent.notes = event.notes
saveEvent(originalEvent)
} }
val alertDialog = d.create()
alertDialog.show() dialogInterface.dismiss()
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ContextCompat.getColor(this, R.color.danger))
alertDialog.setOnDismissListener {
// Resume logbook update
pauseLogbookUpdate = false
} }
// show optional signature // show optional signature
@@ -609,6 +617,9 @@ class MainActivity : AppCompatActivity() {
signatureTextEdit.visibility = View.VISIBLE signatureTextEdit.visibility = View.VISIBLE
} }
val alertDialog = d.create()
alertDialog.show()
// create next/previous links to events of the same type // create next/previous links to events of the same type
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous) val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next) val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
@@ -639,6 +650,15 @@ class MainActivity : AppCompatActivity() {
} else { } else {
nextTextView.visibility = View.GONE nextTextView.visibility = View.GONE
} }
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(
ContextCompat.getColor(this, R.color.danger)
)
alertDialog.setOnDismissListener {
// Resume logbook update
pauseLogbookUpdate = false
}
} }
fun showAddLogbookDialog(requestedByUser: Boolean) { fun showAddLogbookDialog(requestedByUser: Boolean) {
@@ -994,35 +1014,35 @@ class MainActivity : AppCompatActivity() {
val inflater = LayoutInflater.from(anchor.context) val inflater = LayoutInflater.from(anchor.context)
contentView = inflater.inflate(R.layout.more_events_popup, null) contentView = inflater.inflate(R.layout.more_events_popup, null)
contentView.findViewById<View>(R.id.button_medicine).setOnClickListener { contentView.findViewById<View>(R.id.button_medicine).setOnClickListener {
askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE)) addNoteEvent(LunaEvent(LunaEvent.TYPE_MEDICINE))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_enema).setOnClickListener { contentView.findViewById<View>(R.id.button_enema).setOnClickListener {
logEvent(LunaEvent(LunaEvent.TYPE_ENEMA)) addPlainEvent(LunaEvent(LunaEvent.TYPE_ENEMA))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_note).setOnClickListener { contentView.findViewById<View>(R.id.button_note).setOnClickListener {
askNotes(LunaEvent(LunaEvent.TYPE_NOTE)) addNoteEvent(LunaEvent(LunaEvent.TYPE_NOTE))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_temperature).setOnClickListener { contentView.findViewById<View>(R.id.button_temperature).setOnClickListener {
askTemperatureValue(LunaEvent(LunaEvent.TYPE_TEMPERATURE)) addTemperatureEvent(LunaEvent(LunaEvent.TYPE_TEMPERATURE))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_puke).setOnClickListener { contentView.findViewById<View>(R.id.button_puke).setOnClickListener {
askPukeValue(LunaEvent(LunaEvent.TYPE_PUKE, 1)) addPukeEvent(LunaEvent(LunaEvent.TYPE_PUKE, 1))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_colic).setOnClickListener { contentView.findViewById<View>(R.id.button_colic).setOnClickListener {
logEvent(LunaEvent(LunaEvent.TYPE_COLIC)) addPlainEvent(LunaEvent(LunaEvent.TYPE_COLIC))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_scale).setOnClickListener { contentView.findViewById<View>(R.id.button_scale).setOnClickListener {
askWeightValue(LunaEvent(LunaEvent.TYPE_WEIGHT)) addWeightEvent(LunaEvent(LunaEvent.TYPE_WEIGHT))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_bath).setOnClickListener { contentView.findViewById<View>(R.id.button_bath).setOnClickListener {
logEvent(LunaEvent(LunaEvent.TYPE_BATH)) addPlainEvent(LunaEvent(LunaEvent.TYPE_BATH))
dismiss() dismiss()
} }
}.also { popupWindow -> }.also { popupWindow ->

View File

@@ -69,6 +69,15 @@ class LunaEvent: Comparable<LunaEvent> {
throw IllegalArgumentException("JSONObject is not a LunaEvent") throw IllegalArgumentException("JSONObject is not a LunaEvent")
} }
constructor(event: LunaEvent) {
this.jo = JSONObject()
this.type = event.type
this.time = event.time
this.quantity = event.quantity
this.notes = event.notes
this.signature = event.signature
}
constructor(type: String) { constructor(type: String) {
this.jo = JSONObject() this.jo = JSONObject()
this.time = System.currentTimeMillis() / 1000 this.time = System.currentTimeMillis() / 1000

View File

@@ -60,21 +60,21 @@ class NumericUtils (val context: Context) {
) )
} }
fun formatEventQuantity(item: LunaEvent): String { fun formatEventQuantity(event: LunaEvent): String {
val formatted = StringBuilder() val formatted = StringBuilder()
if (item.quantity > 0) { if (event.quantity > 0) {
formatted.append(when (item.type) { formatted.append(when (event.type) {
LunaEvent.TYPE_TEMPERATURE -> LunaEvent.TYPE_TEMPERATURE ->
(item.quantity / 10.0f).toString() (event.quantity / 10.0f).toString()
LunaEvent.TYPE_PUKE -> LunaEvent.TYPE_PUKE ->
context.resources.getStringArray(R.array.AmountLabels)[item.quantity - 1] context.resources.getStringArray(R.array.AmountLabels)[event.quantity - 1]
else -> else ->
item.quantity event.quantity
}) })
formatted.append(" ") formatted.append(" ")
formatted.append( formatted.append(
when (item.type) { when (event.type) {
LunaEvent.TYPE_BABY_BOTTLE -> measurement_unit_liquid_base LunaEvent.TYPE_BABY_BOTTLE -> measurement_unit_liquid_base
LunaEvent.TYPE_WEIGHT -> measurement_unit_weight_base LunaEvent.TYPE_WEIGHT -> measurement_unit_weight_base
LunaEvent.TYPE_MEDICINE -> measurement_unit_weight_tiny LunaEvent.TYPE_MEDICINE -> measurement_unit_weight_tiny

View File

@@ -33,6 +33,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginEnd="20dp"/> android:layout_marginTop="20dp"/>
</LinearLayout> </LinearLayout>

View File

@@ -35,8 +35,7 @@
android:drawablePadding="10dp" android:drawablePadding="10dp"
android:drawableTint="@color/accent" android:drawableTint="@color/accent"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"/>
android:text="@string/dialog_event_detail_datetime_icon" />
<TextView <TextView
android:id="@+id/dialog_event_detail_type_quantity" android:id="@+id/dialog_event_detail_type_quantity"

View File

@@ -135,7 +135,6 @@
<string name="row_luna_event_time">Time</string> <string name="row_luna_event_time">Time</string>
<string name="dialog_event_detail_title">Event detail</string> <string name="dialog_event_detail_title">Event detail</string>
<string name="dialog_event_detail_datetime_icon" translatable="false">🕒 %s</string>
<string name="dialog_event_detail_close_button">OK</string> <string name="dialog_event_detail_close_button">OK</string>
<string name="dialog_event_detail_delete_button">Delete</string> <string name="dialog_event_detail_delete_button">Delete</string>
<string name="dialog_event_detail_quantity">Quantity</string> <string name="dialog_event_detail_quantity">Quantity</string>