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