|
|
|
|
@@ -82,7 +82,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
// Set listeners
|
|
|
|
|
findViewById<View>(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog(true) }
|
|
|
|
|
findViewById<View>(R.id.button_bottle).setOnClickListener { askBabyBottleContent() }
|
|
|
|
|
findViewById<View>(R.id.button_bottle).setOnClickListener { askBabyBottleContent(LunaEvent(LunaEvent.TYPE_BABY_BOTTLE)) }
|
|
|
|
|
findViewById<View>(R.id.button_food).setOnClickListener { askNotes(LunaEvent(LunaEvent.TYPE_FOOD)) }
|
|
|
|
|
findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent(
|
|
|
|
|
LunaEvent(
|
|
|
|
|
@@ -100,14 +100,10 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
)
|
|
|
|
|
) }
|
|
|
|
|
findViewById<View>(R.id.button_change_poo).setOnClickListener { logEvent(
|
|
|
|
|
LunaEvent(
|
|
|
|
|
LunaEvent.TYPE_DIAPERCHANGE_POO
|
|
|
|
|
)
|
|
|
|
|
LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_POO)
|
|
|
|
|
) }
|
|
|
|
|
findViewById<View>(R.id.button_change_pee).setOnClickListener { logEvent(
|
|
|
|
|
LunaEvent(
|
|
|
|
|
LunaEvent.TYPE_DIAPERCHANGE_PEE
|
|
|
|
|
)
|
|
|
|
|
LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_PEE)
|
|
|
|
|
) }
|
|
|
|
|
val moreButton = findViewById<View>(R.id.button_more)
|
|
|
|
|
moreButton.setOnClickListener {
|
|
|
|
|
@@ -132,7 +128,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
val adapter = LunaEventRecyclerAdapter(this, items)
|
|
|
|
|
adapter.onItemClickListener = object: LunaEventRecyclerAdapter.OnItemClickListener {
|
|
|
|
|
override fun onItemClick(event: LunaEvent) {
|
|
|
|
|
showEventDetailDialog(event, items)
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
recyclerView.adapter = adapter
|
|
|
|
|
@@ -195,30 +191,55 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
super.onStop()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askBabyBottleContent() {
|
|
|
|
|
// Show number picker dialog
|
|
|
|
|
val localSettings = LocalSettingsRepository(this)
|
|
|
|
|
fun getAllEvents(): ArrayList<LunaEvent> {
|
|
|
|
|
return logbook?.logs ?: arrayListOf()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askBabyBottleContent(event: LunaEvent, showDetailsAtEnd : Boolean = false) {
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null)
|
|
|
|
|
d.setTitle(R.string.log_bottle_dialog_title)
|
|
|
|
|
d.setMessage(R.string.log_bottle_dialog_description)
|
|
|
|
|
d.setView(dialogView)
|
|
|
|
|
|
|
|
|
|
val numberPicker = dialogView.findViewById<NumberPicker>(R.id.dialog_number_picker)
|
|
|
|
|
numberPicker.minValue = 1 // "10"
|
|
|
|
|
numberPicker.maxValue = 25 // "250
|
|
|
|
|
numberPicker.displayedValues = ((10..250 step 10).map { it.toString() }.toTypedArray())
|
|
|
|
|
numberPicker.wrapSelectorWheel = false
|
|
|
|
|
numberPicker.value = localSettings.loadBabyBottleContent()
|
|
|
|
|
numberPicker.value = event.quantity / 10
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_BABY_BOTTLE, numberPicker.value * 10))
|
|
|
|
|
localSettings.saveBabyBottleContent(numberPicker.value)
|
|
|
|
|
val quantity = numberPicker.value * 10
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
|
|
|
|
|
if (event.time != time || event.quantity != quantity) {
|
|
|
|
|
event.time = time
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askWeightValue() {
|
|
|
|
|
fun askWeightValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
// Show number picker dialog
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.number_edit_dialog, null)
|
|
|
|
|
@@ -226,19 +247,41 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
d.setMessage(R.string.log_weight_dialog_description)
|
|
|
|
|
d.setView(dialogView)
|
|
|
|
|
val weightET = dialogView.findViewById<EditText>(R.id.dialog_number_edittext)
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
val weight = weightET.text.toString().toIntOrNull()
|
|
|
|
|
if (weight != null)
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_WEIGHT, weight))
|
|
|
|
|
else
|
|
|
|
|
if (weight != null) {
|
|
|
|
|
val quantity = weight
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.time != time || event.quantity != quantity) {
|
|
|
|
|
event.time = time
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askTemperatureValue() {
|
|
|
|
|
fun askTemperatureValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
// Show number picker dialog
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.temperature_dialog, null)
|
|
|
|
|
@@ -250,19 +293,75 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
tempSlider.valueFrom = range.first.toFloat()
|
|
|
|
|
tempSlider.valueTo = range.second.toFloat()
|
|
|
|
|
tempSlider.value = range.third.toFloat()
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
val tempTextView = dialogView.findViewById<TextView>(R.id.dialog_temperature_display)
|
|
|
|
|
|
|
|
|
|
tempTextView.text = range.third.toString()
|
|
|
|
|
tempSlider.addOnChangeListener({s, v, b -> tempTextView.text = v.toString()})
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
val temperature = (tempSlider.value * 10).toInt() // In tenth of a grade
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_TEMPERATURE, temperature))
|
|
|
|
|
val quantity = (tempSlider.value * 10).toInt() // temperature in tenth of a grade
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.time != time || event.quantity != quantity) {
|
|
|
|
|
event.time = time
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askPukeValue() {
|
|
|
|
|
fun datePickHelper(eventTime: Long, dateTextView: TextView): Calendar {
|
|
|
|
|
val fmt = getString(R.string.dialog_event_detail_datetime_icon)
|
|
|
|
|
dateTextView.text = String.format(fmt, DateUtils.formatDateTime(eventTime))
|
|
|
|
|
|
|
|
|
|
val dateTime = Calendar.getInstance()
|
|
|
|
|
dateTime.time = Date(eventTime * 1000)
|
|
|
|
|
dateTextView.setOnClickListener {
|
|
|
|
|
// Show datetime picker
|
|
|
|
|
val startYear = dateTime.get(Calendar.YEAR)
|
|
|
|
|
val startMonth = dateTime.get(Calendar.MONTH)
|
|
|
|
|
val startDay = dateTime.get(Calendar.DAY_OF_MONTH)
|
|
|
|
|
val startHour = dateTime.get(Calendar.HOUR_OF_DAY)
|
|
|
|
|
val startMinute = dateTime.get(Calendar.MINUTE)
|
|
|
|
|
|
|
|
|
|
DatePickerDialog(this, { _, year, month, day ->
|
|
|
|
|
TimePickerDialog(this, { _, hour, minute ->
|
|
|
|
|
dateTime.set(year, month, day, hour, minute)
|
|
|
|
|
val time = 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()
|
|
|
|
|
}, startYear, startMonth, startDay).show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dateTime
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun saveEvent(event: LunaEvent) {
|
|
|
|
|
if (!getAllEvents().contains(event)) {
|
|
|
|
|
// new event
|
|
|
|
|
logEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logbook?.sort()
|
|
|
|
|
recyclerView.adapter?.notifyDataSetChanged()
|
|
|
|
|
saveLogbook()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askPukeValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.puke_dialog, null)
|
|
|
|
|
d.setTitle(R.string.log_puke_dialog_title)
|
|
|
|
|
@@ -271,42 +370,135 @@ 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)
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
val pos = spinner.selectedItemPosition
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_PUKE, pos + 1))
|
|
|
|
|
val quantity = spinner.selectedItemPosition + 1
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.time != time || event.quantity != quantity) {
|
|
|
|
|
event.time = time
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askNotes(lunaEvent: LunaEvent) {
|
|
|
|
|
// Ask to edit events to be edited (only affects date)
|
|
|
|
|
fun askPlain(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
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 dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.time != time) {
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
|
|
|
|
|
// a shortcut, since the only value to change is the date
|
|
|
|
|
dateTV.performClick()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askNotes(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
val useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM)
|
|
|
|
|
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null)
|
|
|
|
|
d.setTitle(lunaEvent.getTypeDescription(this))
|
|
|
|
|
d.setMessage(lunaEvent.getDialogMessage(this))
|
|
|
|
|
d.setTitle(event.getTypeDescription(this))
|
|
|
|
|
d.setMessage(event.getDialogMessage(this))
|
|
|
|
|
d.setView(dialogView)
|
|
|
|
|
val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext)
|
|
|
|
|
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
|
|
|
|
|
if (lunaEvent.type == LunaEvent.TYPE_NOTE || lunaEvent.type == LunaEvent.TYPE_CUSTOM)
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.notes_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
notesET.setText(event.notes)
|
|
|
|
|
|
|
|
|
|
if (useQuantity) {
|
|
|
|
|
qtyET.setText(event.quantity.toString())
|
|
|
|
|
} else {
|
|
|
|
|
qtyET.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
val qtyStr = qtyET.text.toString()
|
|
|
|
|
if (qtyStr.isNotEmpty()) {
|
|
|
|
|
val qty = qtyStr.toIntOrNull()
|
|
|
|
|
if (qty == null) {
|
|
|
|
|
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
|
|
|
|
return@setPositiveButton
|
|
|
|
|
}
|
|
|
|
|
lunaEvent.quantity = qty
|
|
|
|
|
}
|
|
|
|
|
val notes = notesET.text.toString()
|
|
|
|
|
lunaEvent.notes = notes
|
|
|
|
|
logEvent(lunaEvent)
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
|
|
|
|
|
if (useQuantity) {
|
|
|
|
|
val quantity = qtyET.text.toString().toIntOrNull()
|
|
|
|
|
if (quantity != null) {
|
|
|
|
|
if (event.time != time || event.notes != notes || event.quantity != quantity ) {
|
|
|
|
|
event.time = time
|
|
|
|
|
event.notes = notes
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (event.time != time || event.notes != notes) {
|
|
|
|
|
event.time = time
|
|
|
|
|
event.notes = notes
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
@@ -359,55 +551,56 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
return nextEvent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun showEventDetailDialog(event: LunaEvent, items: ArrayList<LunaEvent>) {
|
|
|
|
|
fun showEventDetailDialog(event: LunaEvent) {
|
|
|
|
|
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
|
|
|
|
|
pauseLogbookUpdate = true
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
d.setTitle(R.string.dialog_event_detail_title)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.dialog_event_detail, null)
|
|
|
|
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji).text = event.getTypeEmoji(this)
|
|
|
|
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description).text = event.getTypeDescription(this)
|
|
|
|
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity).text =
|
|
|
|
|
NumericUtils(this).formatEventQuantity(event)
|
|
|
|
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).text = event.notes
|
|
|
|
|
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 quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity)
|
|
|
|
|
val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes)
|
|
|
|
|
|
|
|
|
|
val currentDateTime = Calendar.getInstance()
|
|
|
|
|
currentDateTime.time = Date(event.time * 1000)
|
|
|
|
|
emojiTextView.text = event.getTypeEmoji(this)
|
|
|
|
|
descriptionTextView.text = event.getTypeDescription(this)
|
|
|
|
|
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))
|
|
|
|
|
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() }
|
|
|
|
|
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> deleteEvent(event) }
|
|
|
|
|
d.setNegativeButton(R.string.dialog_event_detail_edit_button) { dialogInterface, i ->
|
|
|
|
|
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 -> {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ContextCompat.getColor(this, R.color.danger))
|
|
|
|
|
alertDialog.setOnDismissListener({
|
|
|
|
|
alertDialog.setOnDismissListener {
|
|
|
|
|
// Resume logbook update
|
|
|
|
|
pauseLogbookUpdate = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// show optional signature
|
|
|
|
|
if (event.signature.isNotEmpty()) {
|
|
|
|
|
@@ -417,11 +610,11 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create next/previous links to events of the same type
|
|
|
|
|
|
|
|
|
|
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
|
|
|
|
|
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
|
|
|
|
|
val nextEvent = getNextSameEvent(event, items)
|
|
|
|
|
val previousEvent = getPreviousSameEvent(event, items)
|
|
|
|
|
val allEvents = getAllEvents()
|
|
|
|
|
val nextEvent = getNextSameEvent(event, allEvents)
|
|
|
|
|
val previousEvent = getPreviousSameEvent(event, allEvents)
|
|
|
|
|
|
|
|
|
|
if (previousEvent != null) {
|
|
|
|
|
val emoji = previousEvent.getTypeEmoji(applicationContext)
|
|
|
|
|
@@ -429,7 +622,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
previousTextView.text = String.format("⬅️ %s %s", emoji, time)
|
|
|
|
|
previousTextView.setOnClickListener {
|
|
|
|
|
alertDialog.cancel()
|
|
|
|
|
showEventDetailDialog(previousEvent, items)
|
|
|
|
|
showEventDetailDialog(previousEvent)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
previousTextView.visibility = View.GONE
|
|
|
|
|
@@ -441,7 +634,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
nextTextView.text = String.format("%s %s ➡️", time, emoji)
|
|
|
|
|
nextTextView.setOnClickListener {
|
|
|
|
|
alertDialog.cancel()
|
|
|
|
|
showEventDetailDialog(nextEvent, items)
|
|
|
|
|
showEventDetailDialog(nextEvent)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nextTextView.visibility = View.GONE
|
|
|
|
|
@@ -804,38 +997,34 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE))
|
|
|
|
|
dismiss()
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_enema).setOnClickListener({
|
|
|
|
|
contentView.findViewById<View>(R.id.button_enema).setOnClickListener {
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_ENEMA))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_note).setOnClickListener({
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_note).setOnClickListener {
|
|
|
|
|
askNotes(LunaEvent(LunaEvent.TYPE_NOTE))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_temperature).setOnClickListener({
|
|
|
|
|
askTemperatureValue()
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_temperature).setOnClickListener {
|
|
|
|
|
askTemperatureValue(LunaEvent(LunaEvent.TYPE_TEMPERATURE))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_puke).setOnClickListener({
|
|
|
|
|
askPukeValue()
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_puke).setOnClickListener {
|
|
|
|
|
askPukeValue(LunaEvent(LunaEvent.TYPE_PUKE, 1))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_colic).setOnClickListener({
|
|
|
|
|
logEvent(
|
|
|
|
|
LunaEvent(LunaEvent.TYPE_COLIC)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_colic).setOnClickListener {
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_COLIC))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_scale).setOnClickListener({
|
|
|
|
|
askWeightValue()
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_scale).setOnClickListener {
|
|
|
|
|
askWeightValue(LunaEvent(LunaEvent.TYPE_WEIGHT))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_bath).setOnClickListener({
|
|
|
|
|
logEvent(
|
|
|
|
|
LunaEvent(LunaEvent.TYPE_BATH)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_bath).setOnClickListener {
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_BATH))
|
|
|
|
|
dismiss()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}.also { popupWindow ->
|
|
|
|
|
popupWindow.setOnDismissListener({
|
|
|
|
|
Handler(mainLooper).postDelayed({
|
|
|
|
|
|