4 Commits

Author SHA1 Message Date
aaccef54a5 use creation dialog as edit dialog 2025-11-10 17:51:02 +01:00
5eeb462836 Bumped version 2025-11-06 22:21:05 +01:00
5b777c0b88 Merge pull request 'fix puke event quantity' (#18) from mwarning/luna-tracker:fixpuke into master
I already tagged the commit when I accepted the previous PR, so it may have already been picked up by the F-Droid build pipeline. I'll send this one too and see if it makes in time.
2025-11-06 22:17:40 +01:00
6f3061974d fix puke event quantity
The LunaEvent class treats quantities of 0
as a value to set. To workaround this, the
quantity index needs to start at >0.
2025-11-06 21:49:08 +01:00
7 changed files with 260 additions and 208 deletions

View File

@@ -12,8 +12,8 @@ android {
applicationId = "it.danieleverducci.lunatracker" applicationId = "it.danieleverducci.lunatracker"
minSdk = 21 minSdk = 21
targetSdk = 34 targetSdk = 34
versionCode = 6 versionCode = 7
versionName = "0.8" versionName = "0.9"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@@ -6,7 +6,6 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.text.Editable
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@@ -22,7 +21,6 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.widget.doOnTextChanged
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.progressindicator.LinearProgressIndicator import com.google.android.material.progressindicator.LinearProgressIndicator
@@ -31,7 +29,6 @@ import com.thegrizzlylabs.sardineandroid.impl.SardineException
import it.danieleverducci.lunatracker.adapters.LunaEventRecyclerAdapter import it.danieleverducci.lunatracker.adapters.LunaEventRecyclerAdapter
import it.danieleverducci.lunatracker.entities.Logbook import it.danieleverducci.lunatracker.entities.Logbook
import it.danieleverducci.lunatracker.entities.LunaEvent 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.FileLogbookRepository
import it.danieleverducci.lunatracker.repository.LocalSettingsRepository import it.danieleverducci.lunatracker.repository.LocalSettingsRepository
import it.danieleverducci.lunatracker.repository.LogbookListObtainedListener import it.danieleverducci.lunatracker.repository.LogbookListObtainedListener
@@ -85,7 +82,7 @@ class MainActivity : AppCompatActivity() {
// Set listeners // Set listeners
findViewById<View>(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog(true) } 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_food).setOnClickListener { askNotes(LunaEvent(LunaEvent.TYPE_FOOD)) }
findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent( findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent(
LunaEvent( LunaEvent(
@@ -103,14 +100,10 @@ class MainActivity : AppCompatActivity() {
) )
) } ) }
findViewById<View>(R.id.button_change_poo).setOnClickListener { logEvent( findViewById<View>(R.id.button_change_poo).setOnClickListener { logEvent(
LunaEvent( LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_POO)
LunaEvent.TYPE_DIAPERCHANGE_POO
)
) } ) }
findViewById<View>(R.id.button_change_pee).setOnClickListener { logEvent( findViewById<View>(R.id.button_change_pee).setOnClickListener { logEvent(
LunaEvent( LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_PEE)
LunaEvent.TYPE_DIAPERCHANGE_PEE
)
) } ) }
val moreButton = findViewById<View>(R.id.button_more) val moreButton = findViewById<View>(R.id.button_more)
moreButton.setOnClickListener { moreButton.setOnClickListener {
@@ -202,15 +195,7 @@ class MainActivity : AppCompatActivity() {
return logbook?.logs ?: arrayListOf() return logbook?.logs ?: arrayListOf()
} }
fun askBabyBottleContent(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) { fun askBabyBottleContent(event: LunaEvent, showDetailsAtEnd : Boolean = false) {
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 d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null) val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null)
d.setTitle(R.string.log_bottle_dialog_title) d.setTitle(R.string.log_bottle_dialog_title)
@@ -222,56 +207,39 @@ class MainActivity : AppCompatActivity() {
numberPicker.maxValue = 25 // "250 numberPicker.maxValue = 25 // "250
numberPicker.displayedValues = ((10..250 step 10).map { it.toString() }.toTypedArray()) numberPicker.displayedValues = ((10..250 step 10).map { it.toString() }.toTypedArray())
numberPicker.wrapSelectorWheel = false numberPicker.wrapSelectorWheel = false
if (previous != null) { numberPicker.value = event.quantity / 10
numberPicker.value = previous.quantity / 10
}
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
dateTextView.text = val pickedDateTime = datePickHelper(event.time, dateTV)
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 -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
event.quantity = numberPicker.value * 10 val quantity = numberPicker.value * 10
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch val time = pickedDateTime.time.time / 1000
if (isNewEvent) {
logEvent(event) if (event.time != time || event.quantity != quantity) {
event.quantity = quantity
event.time = time
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
} }
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
onEnd?.invoke()
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
onEnd?.invoke()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askWeightValue() { fun askWeightValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
// 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.number_edit_dialog, null)
@@ -279,19 +247,41 @@ class MainActivity : AppCompatActivity() {
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)
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV)
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) {
logEvent(LunaEvent(LunaEvent.TYPE_WEIGHT, weight)) val quantity = weight
else val time = pickedDateTime.time.time / 1000
if (event.quantity != quantity || event.time != time) {
event.quantity = quantity
event.time = time
saveEvent(event)
}
} 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()
} }
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() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askTemperatureValue() { fun askTemperatureValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
// 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)
@@ -303,26 +293,75 @@ class MainActivity : AppCompatActivity() {
tempSlider.valueFrom = range.first.toFloat() tempSlider.valueFrom = range.first.toFloat()
tempSlider.valueTo = range.second.toFloat() tempSlider.valueTo = range.second.toFloat()
tempSlider.value = range.third.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) 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 temperature = (tempSlider.value * 10).toInt() // In tenth of a grade val quantity = (tempSlider.value * 10).toInt() // temperature in tenth of a grade
logEvent(LunaEvent(LunaEvent.TYPE_TEMPERATURE, temperature)) 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)
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askPukeValue(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) { fun datePickHelper(eventTime: Long, dateTextView: TextView): Calendar {
val isNewEvent = (existingEvent != null) val fmt = getString(R.string.dialog_event_detail_datetime_icon)
val event = if (existingEvent == null) { dateTextView.text = String.format(fmt, DateUtils.formatDateTime(eventTime))
LunaEvent(LunaEvent.TYPE_PUKE)
} else { val dateTime = Calendar.getInstance()
existingEvent 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 d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.puke_dialog, null) val dialogView = layoutInflater.inflate(R.layout.puke_dialog, null)
d.setTitle(R.string.log_puke_dialog_title) d.setTitle(R.string.log_puke_dialog_title)
@@ -333,90 +372,69 @@ class MainActivity : AppCompatActivity() {
spinner.adapter = ArrayAdapter.createFromResource(this, R.array.AmountLabels, android.R.layout.simple_spinner_dropdown_item) spinner.adapter = ArrayAdapter.createFromResource(this, R.array.AmountLabels, android.R.layout.simple_spinner_dropdown_item)
spinner.setSelection(event.quantity) 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 -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
event.quantity = spinner.selectedItemPosition val quantity = spinner.selectedItemPosition + 1
if (isNewEvent) { val time = pickedDateTime.time.time / 1000
logEvent(event) if (event.quantity != quantity || event.time != time) {
event.quantity = quantity
event.time = time
saveEvent(event)
} }
onEnd?.invoke()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
} }
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
onEnd?.invoke if (showDetailsAtEnd) {
showEventDetailDialog(event)
} }
}
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
// Ask to edit events to be edited (only affects date) // Ask to edit events to be edited (only affects date)
fun askPlain(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) { fun askPlain(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
val isNewEvent = (existingEvent != null)
val event = if (existingEvent == null) {
LunaEvent(LunaEvent.TYPE_NOTE)
} else {
existingEvent
}
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))
d.setMessage(event.getDialogMessage(this)) d.setMessage(event.getDialogMessage(this))
d.setView(dialogView) d.setView(dialogView)
val dateET = dialogView.findViewById<TextView>(R.id.notes_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_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()
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
// Save event and move it to the right position in the logbook val time = pickedDateTime.time.time / 1000
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch if (event.time != time) {
if (isNewEvent) { event.time = time
logEvent(event) saveEvent(event)
} }
logbook?.sort() if (showDetailsAtEnd) {
recyclerView.adapter?.notifyDataSetChanged() showEventDetailDialog(event)
saveLogbook() }
onEnd?.invoke()
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
onEnd?.invoke() if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askNotes(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) { fun askNotes(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
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 useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM)
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
@@ -426,29 +444,9 @@ class MainActivity : AppCompatActivity() {
d.setView(dialogView) d.setView(dialogView)
val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext) val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext)
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext) val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
val dateET = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val pickedDateTime = Calendar.getInstance() val dateTV = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val currentDateTime = Calendar.getInstance() val pickedDateTime = datePickHelper(event.time, dateTV)
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) notesET.setText(event.notes)
@@ -459,32 +457,43 @@ 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 time = pickedDateTime.time.time / 1000
if (useQuantity) { if (useQuantity) {
val qty = qtyET.text.toString().toIntOrNull() val quantity = qtyET.text.toString().toIntOrNull()
if (qty != null) { if (quantity != null) {
event.quantity = qty if (event.time != time || event.notes != notes || event.quantity != quantity ) {
event.quantity = quantity
event.notes = notes
event.time = time
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()
onEnd?.invoke()
return@setPositiveButton
}
} }
event.notes = notesET.text.toString() if (showDetailsAtEnd) {
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch showEventDetailDialog(event)
}
if (isNewEvent) { } else {
logEvent(event) if (event.time != time || event.notes != notes) {
event.notes = notes
event.time = time
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
onEnd?.invoke()
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
onEnd?.invoke() if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
@@ -564,22 +573,22 @@ class MainActivity : AppCompatActivity() {
d.setNegativeButton(R.string.dialog_event_detail_edit_button) { dialogInterface, i -> d.setNegativeButton(R.string.dialog_event_detail_edit_button) { dialogInterface, i ->
Log.d("MainActivity", "negative button pressed: ${event.type}") Log.d("MainActivity", "negative button pressed: ${event.type}")
when (event.type) { when (event.type) {
TYPE_BABY_BOTTLE -> askBabyBottleContent(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, true)
LunaEvent.TYPE_WEIGHT -> {} LunaEvent.TYPE_WEIGHT -> askWeightValue(event, true)
LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE, LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE, LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE, LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE,
LunaEvent.TYPE_ENEMA, LunaEvent.TYPE_ENEMA,
LunaEvent.TYPE_BATH, LunaEvent.TYPE_BATH,
LunaEvent.TYPE_COLIC, LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_CUSTOM,
LunaEvent.TYPE_DIAPERCHANGE_POO, LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE -> { askPlain(event, { showEventDetailDialog(event) }) } LunaEvent.TYPE_DIAPERCHANGE_PEE -> askPlain(event, true)
LunaEvent.TYPE_MEDICINE -> askNotes(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_MEDICINE -> askNotes(event, true)
LunaEvent.TYPE_NOTE -> askNotes(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_NOTE -> askNotes(event, true)
LunaEvent.TYPE_TEMPERATURE, //todo LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, true)
LunaEvent.TYPE_FOOD -> askNotes(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_FOOD -> askNotes(event, true)
LunaEvent.TYPE_PUKE -> askPukeValue(event, { showEventDetailDialog(event) }) LunaEvent.TYPE_PUKE -> askPukeValue(event, true)
LunaEvent.TYPE_CUSTOM -> {} // todo?
else -> {} else -> {}
} }
} }
@@ -987,38 +996,34 @@ class MainActivity : AppCompatActivity() {
askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE)) askNotes(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)) logEvent(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)) askNotes(LunaEvent(LunaEvent.TYPE_NOTE))
dismiss() dismiss()
}) }
contentView.findViewById<View>(R.id.button_temperature).setOnClickListener({ contentView.findViewById<View>(R.id.button_temperature).setOnClickListener {
askTemperatureValue() askTemperatureValue(LunaEvent(LunaEvent.TYPE_TEMPERATURE))
dismiss() dismiss()
}) }
contentView.findViewById<View>(R.id.button_puke).setOnClickListener({ contentView.findViewById<View>(R.id.button_puke).setOnClickListener {
askPukeValue() askPukeValue(LunaEvent(LunaEvent.TYPE_PUKE))
dismiss() dismiss()
}) }
contentView.findViewById<View>(R.id.button_colic).setOnClickListener({ contentView.findViewById<View>(R.id.button_colic).setOnClickListener {
logEvent( logEvent(LunaEvent(LunaEvent.TYPE_COLIC))
LunaEvent(LunaEvent.TYPE_COLIC)
)
dismiss() dismiss()
}) }
contentView.findViewById<View>(R.id.button_scale).setOnClickListener({ contentView.findViewById<View>(R.id.button_scale).setOnClickListener {
askWeightValue() askWeightValue(LunaEvent(LunaEvent.TYPE_WEIGHT))
dismiss() dismiss()
}) }
contentView.findViewById<View>(R.id.button_bath).setOnClickListener({ contentView.findViewById<View>(R.id.button_bath).setOnClickListener {
logEvent( logEvent(LunaEvent(LunaEvent.TYPE_BATH))
LunaEvent(LunaEvent.TYPE_BATH)
)
dismiss() dismiss()
}) }
}.also { popupWindow -> }.also { popupWindow ->
popupWindow.setOnDismissListener({ popupWindow.setOnDismissListener({
Handler(mainLooper).postDelayed({ Handler(mainLooper).postDelayed({

View File

@@ -67,7 +67,7 @@ class NumericUtils (val context: Context) {
LunaEvent.TYPE_TEMPERATURE -> LunaEvent.TYPE_TEMPERATURE ->
(item.quantity / 10.0f).toString() (item.quantity / 10.0f).toString()
LunaEvent.TYPE_PUKE -> LunaEvent.TYPE_PUKE ->
context.resources.getStringArray(R.array.AmountLabels)[item.quantity] context.resources.getStringArray(R.array.AmountLabels)[item.quantity - 1]
else -> else ->
item.quantity item.quantity
}) })

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/dialog_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"/>
</LinearLayout>

View File

@@ -1,10 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center"> android:gravity="center"
android:orientation="horizontal">
<EditText <EditText
android:id="@+id/dialog_number_edittext" android:id="@+id/dialog_number_edittext"
@@ -19,4 +25,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:text="g"/> android:text="g"/>
</LinearLayout>
<TextView
android:id="@+id/dialog_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"/>
</LinearLayout> </LinearLayout>

View File

@@ -14,4 +14,11 @@
android:paddingHorizontal="16dp" android:paddingHorizontal="16dp"
android:paddingVertical="8dp"/> android:paddingVertical="8dp"/>
<TextView
android:id="@+id/dialog_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"/>
</LinearLayout> </LinearLayout>

View File

@@ -23,4 +23,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="30sp" android:textSize="30sp"
android:textColor="@color/accent"/> android:textColor="@color/accent"/>
<TextView
android:id="@+id/dialog_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"/>
</LinearLayout> </LinearLayout>