|
|
|
|
@@ -6,6 +6,7 @@ import android.content.DialogInterface
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.text.Editable
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
@@ -21,6 +22,7 @@ import android.widget.Toast
|
|
|
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
|
import androidx.core.widget.doOnTextChanged
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
|
import com.google.android.material.progressindicator.LinearProgressIndicator
|
|
|
|
|
@@ -29,6 +31,7 @@ import com.thegrizzlylabs.sardineandroid.impl.SardineException
|
|
|
|
|
import it.danieleverducci.lunatracker.adapters.LunaEventRecyclerAdapter
|
|
|
|
|
import it.danieleverducci.lunatracker.entities.Logbook
|
|
|
|
|
import it.danieleverducci.lunatracker.entities.LunaEvent
|
|
|
|
|
import it.danieleverducci.lunatracker.entities.LunaEvent.Companion.TYPE_BABY_BOTTLE
|
|
|
|
|
import it.danieleverducci.lunatracker.repository.FileLogbookRepository
|
|
|
|
|
import it.danieleverducci.lunatracker.repository.LocalSettingsRepository
|
|
|
|
|
import it.danieleverducci.lunatracker.repository.LogbookListObtainedListener
|
|
|
|
|
@@ -82,7 +85,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
// Set listeners
|
|
|
|
|
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_bottle).setOnClickListener { askBabyBottleContent() }
|
|
|
|
|
findViewById<View>(R.id.button_food).setOnClickListener { askNotes(LunaEvent(LunaEvent.TYPE_FOOD)) }
|
|
|
|
|
findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent(
|
|
|
|
|
LunaEvent(
|
|
|
|
|
@@ -100,10 +103,14 @@ 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 {
|
|
|
|
|
@@ -195,7 +202,15 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
return logbook?.logs ?: arrayListOf()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askBabyBottleContent(event: LunaEvent, showDetailsAtEnd : Boolean = false) {
|
|
|
|
|
fun askBabyBottleContent(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) {
|
|
|
|
|
val isNewEvent = (existingEvent != null)
|
|
|
|
|
val event = if (existingEvent == null) {
|
|
|
|
|
LunaEvent(TYPE_BABY_BOTTLE)
|
|
|
|
|
} else {
|
|
|
|
|
existingEvent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val previous = getPreviousSameEvent(event, getAllEvents())
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null)
|
|
|
|
|
d.setTitle(R.string.log_bottle_dialog_title)
|
|
|
|
|
@@ -207,39 +222,56 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
numberPicker.maxValue = 25 // "250
|
|
|
|
|
numberPicker.displayedValues = ((10..250 step 10).map { it.toString() }.toTypedArray())
|
|
|
|
|
numberPicker.wrapSelectorWheel = false
|
|
|
|
|
numberPicker.value = event.quantity / 10
|
|
|
|
|
if (previous != null) {
|
|
|
|
|
numberPicker.value = previous.quantity / 10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
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 {
|
|
|
|
|
// 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
|
|
|
|
|
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 ->
|
|
|
|
|
val quantity = numberPicker.value * 10
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
|
|
|
|
|
if (event.time != time || event.quantity != quantity) {
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
event.quantity = numberPicker.value * 10
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askWeightValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
fun askWeightValue() {
|
|
|
|
|
// Show number picker dialog
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.number_edit_dialog, null)
|
|
|
|
|
@@ -247,41 +279,19 @@ 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) {
|
|
|
|
|
val quantity = weight
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.quantity != quantity || event.time != time) {
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (weight != null)
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_WEIGHT, weight))
|
|
|
|
|
else
|
|
|
|
|
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askTemperatureValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
fun askTemperatureValue() {
|
|
|
|
|
// Show number picker dialog
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.temperature_dialog, null)
|
|
|
|
|
@@ -293,75 +303,26 @@ 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 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.quantity = quantity
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
val temperature = (tempSlider.value * 10).toInt() // In tenth of a grade
|
|
|
|
|
logEvent(LunaEvent(LunaEvent.TYPE_TEMPERATURE, temperature))
|
|
|
|
|
}
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
fun askPukeValue(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) {
|
|
|
|
|
val isNewEvent = (existingEvent != null)
|
|
|
|
|
val event = if (existingEvent == null) {
|
|
|
|
|
LunaEvent(LunaEvent.TYPE_PUKE)
|
|
|
|
|
} else {
|
|
|
|
|
existingEvent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
@@ -372,69 +333,90 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
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 pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
val quantity = spinner.selectedItemPosition + 1
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.quantity != quantity || event.time != time) {
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
event.quantity = spinner.selectedItemPosition
|
|
|
|
|
if (isNewEvent) {
|
|
|
|
|
logEvent(event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
onEnd?.invoke
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ask to edit events to be edited (only affects date)
|
|
|
|
|
fun askPlain(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
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 dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedDateTime = datePickHelper(event.time, dateTV)
|
|
|
|
|
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 ->
|
|
|
|
|
val time = pickedDateTime.time.time / 1000
|
|
|
|
|
if (event.time != time) {
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
// 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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
logbook?.sort()
|
|
|
|
|
recyclerView.adapter?.notifyDataSetChanged()
|
|
|
|
|
saveLogbook()
|
|
|
|
|
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
alertDialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askNotes(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
|
|
|
|
|
fun askNotes(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) {
|
|
|
|
|
val isNewEvent = (existingEvent != null)
|
|
|
|
|
val event = if (existingEvent == null) {
|
|
|
|
|
LunaEvent(LunaEvent.TYPE_NOTE)
|
|
|
|
|
} else {
|
|
|
|
|
existingEvent
|
|
|
|
|
}
|
|
|
|
|
val useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM)
|
|
|
|
|
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
@@ -444,9 +426,29 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
d.setView(dialogView)
|
|
|
|
|
val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext)
|
|
|
|
|
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
|
|
|
|
|
val dateET = 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 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()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notesET.setText(event.notes)
|
|
|
|
|
|
|
|
|
|
@@ -457,43 +459,32 @@ 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) {
|
|
|
|
|
if (event.time != time || event.notes != notes || event.quantity != quantity ) {
|
|
|
|
|
event.quantity = quantity
|
|
|
|
|
event.notes = notes
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
val qty = qtyET.text.toString().toIntOrNull()
|
|
|
|
|
if (qty != null) {
|
|
|
|
|
event.quantity = qty
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
return@setPositiveButton
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (event.time != time || event.notes != notes) {
|
|
|
|
|
event.notes = notes
|
|
|
|
|
event.time = time
|
|
|
|
|
saveEvent(event)
|
|
|
|
|
}
|
|
|
|
|
event.notes = notesET.text.toString()
|
|
|
|
|
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
|
|
|
|
|
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
if (isNewEvent) {
|
|
|
|
|
logEvent(event)
|
|
|
|
|
}
|
|
|
|
|
logbook?.sort()
|
|
|
|
|
recyclerView.adapter?.notifyDataSetChanged()
|
|
|
|
|
saveLogbook()
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
|
|
|
|
dialogInterface.dismiss()
|
|
|
|
|
if (showDetailsAtEnd) {
|
|
|
|
|
showEventDetailDialog(event)
|
|
|
|
|
}
|
|
|
|
|
onEnd?.invoke()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val alertDialog = d.create()
|
|
|
|
|
@@ -573,22 +564,22 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
d.setNegativeButton(R.string.dialog_event_detail_edit_button) { dialogInterface, i ->
|
|
|
|
|
Log.d("MainActivity", "negative button pressed: ${event.type}")
|
|
|
|
|
when (event.type) {
|
|
|
|
|
LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, true)
|
|
|
|
|
LunaEvent.TYPE_WEIGHT -> askWeightValue(event, true)
|
|
|
|
|
TYPE_BABY_BOTTLE -> askBabyBottleContent(event, { showEventDetailDialog(event) })
|
|
|
|
|
LunaEvent.TYPE_WEIGHT -> {}
|
|
|
|
|
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)
|
|
|
|
|
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 -> {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -996,34 +987,38 @@ 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(LunaEvent(LunaEvent.TYPE_TEMPERATURE))
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_temperature).setOnClickListener({
|
|
|
|
|
askTemperatureValue()
|
|
|
|
|
dismiss()
|
|
|
|
|
}
|
|
|
|
|
contentView.findViewById<View>(R.id.button_puke).setOnClickListener {
|
|
|
|
|
askPukeValue(LunaEvent(LunaEvent.TYPE_PUKE))
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_puke).setOnClickListener({
|
|
|
|
|
askPukeValue()
|
|
|
|
|
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(LunaEvent(LunaEvent.TYPE_WEIGHT))
|
|
|
|
|
})
|
|
|
|
|
contentView.findViewById<View>(R.id.button_scale).setOnClickListener({
|
|
|
|
|
askWeightValue()
|
|
|
|
|
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({
|
|
|
|
|
|