1 Commits

Author SHA1 Message Date
4e9eeff6aa use creation dialog as edit dialog 2025-11-10 00:04:40 +01:00
7 changed files with 208 additions and 260 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 = 7 versionCode = 6
versionName = "0.9" versionName = "0.8"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@@ -6,6 +6,7 @@ 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
@@ -21,6 +22,7 @@ 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
@@ -29,6 +31,7 @@ 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
@@ -82,7 +85,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(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_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(
@@ -100,10 +103,14 @@ class MainActivity : AppCompatActivity() {
) )
) } ) }
findViewById<View>(R.id.button_change_poo).setOnClickListener { logEvent( 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( 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) val moreButton = findViewById<View>(R.id.button_more)
moreButton.setOnClickListener { moreButton.setOnClickListener {
@@ -195,7 +202,15 @@ class MainActivity : AppCompatActivity() {
return logbook?.logs ?: arrayListOf() 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 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)
@@ -207,39 +222,56 @@ 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
numberPicker.value = event.quantity / 10 if (previous != null) {
numberPicker.value = previous.quantity / 10
}
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV) 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 -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val quantity = numberPicker.value * 10 event.quantity = numberPicker.value * 10
val time = pickedDateTime.time.time / 1000 event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
if (isNewEvent) {
if (event.time != time || event.quantity != quantity) { logEvent(event)
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(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun askWeightValue() {
// 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)
@@ -247,41 +279,19 @@ 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)
val quantity = weight logEvent(LunaEvent(LunaEvent.TYPE_WEIGHT, weight))
val time = pickedDateTime.time.time / 1000 else
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()
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
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(event: LunaEvent, showDetailsAtEnd: Boolean = false) { fun askTemperatureValue() {
// 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)
@@ -293,75 +303,26 @@ 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 quantity = (tempSlider.value * 10).toInt() // temperature in tenth of a grade val temperature = (tempSlider.value * 10).toInt() // In tenth of a grade
val time = pickedDateTime.time.time / 1000 logEvent(LunaEvent(LunaEvent.TYPE_TEMPERATURE, temperature))
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 datePickHelper(eventTime: Long, dateTextView: TextView): Calendar { fun askPukeValue(existingEvent: LunaEvent? = null, onEnd: (() -> Unit)? = null) {
val fmt = getString(R.string.dialog_event_detail_datetime_icon) val isNewEvent = (existingEvent != null)
dateTextView.text = String.format(fmt, DateUtils.formatDateTime(eventTime)) val event = if (existingEvent == null) {
LunaEvent(LunaEvent.TYPE_PUKE)
val dateTime = Calendar.getInstance() } else {
dateTime.time = Date(eventTime * 1000) existingEvent
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)
@@ -372,69 +333,90 @@ 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 ->
val quantity = spinner.selectedItemPosition + 1 event.quantity = spinner.selectedItemPosition
val time = pickedDateTime.time.time / 1000 if (isNewEvent) {
if (event.quantity != quantity || event.time != time) { logEvent(event)
event.quantity = quantity
event.time = time
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
} }
onEnd?.invoke()
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) { onEnd?.invoke
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(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 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 dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateET = 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()
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val time = pickedDateTime.time.time / 1000 // Save event and move it to the right position in the logbook
if (event.time != time) { event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
event.time = time if (isNewEvent) {
saveEvent(event) logEvent(event)
} }
if (showDetailsAtEnd) { logbook?.sort()
showEventDetailDialog(event) 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()
if (showDetailsAtEnd) { onEnd?.invoke()
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() 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 useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM)
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
@@ -444,9 +426,29 @@ 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 dateTV = dialogView.findViewById<TextView>(R.id.notes_date_picker) val pickedDateTime = Calendar.getInstance()
val pickedDateTime = datePickHelper(event.time, dateTV) 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) notesET.setText(event.notes)
@@ -457,43 +459,32 @@ 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 quantity = qtyET.text.toString().toIntOrNull() val qty = qtyET.text.toString().toIntOrNull()
if (quantity != null) { if (qty != null) {
if (event.time != time || event.notes != notes || event.quantity != quantity ) { event.quantity = qty
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
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} else {
if (event.time != time || event.notes != notes) {
event.notes = notes
event.time = time
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
} }
} }
event.notes = notesET.text.toString()
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 -> d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss() dialogInterface.dismiss()
if (showDetailsAtEnd) { onEnd?.invoke()
showEventDetailDialog(event)
}
} }
val alertDialog = d.create() val alertDialog = d.create()
@@ -573,22 +564,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) {
LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, true) TYPE_BABY_BOTTLE -> askBabyBottleContent(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_WEIGHT -> askWeightValue(event, true) LunaEvent.TYPE_WEIGHT -> {}
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, true) LunaEvent.TYPE_DIAPERCHANGE_PEE -> { askPlain(event, { showEventDetailDialog(event) }) }
LunaEvent.TYPE_MEDICINE -> askNotes(event, true) LunaEvent.TYPE_MEDICINE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_NOTE -> askNotes(event, true) LunaEvent.TYPE_NOTE -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, true) LunaEvent.TYPE_TEMPERATURE, //todo
LunaEvent.TYPE_FOOD -> askNotes(event, true) LunaEvent.TYPE_FOOD -> askNotes(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_PUKE -> askPukeValue(event, true) LunaEvent.TYPE_PUKE -> askPukeValue(event, { showEventDetailDialog(event) })
LunaEvent.TYPE_CUSTOM -> {} // todo?
else -> {} else -> {}
} }
} }
@@ -996,34 +987,38 @@ 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(LunaEvent(LunaEvent.TYPE_TEMPERATURE)) askTemperatureValue()
dismiss() dismiss()
} })
contentView.findViewById<View>(R.id.button_puke).setOnClickListener { contentView.findViewById<View>(R.id.button_puke).setOnClickListener({
askPukeValue(LunaEvent(LunaEvent.TYPE_PUKE)) askPukeValue()
dismiss() dismiss()
} })
contentView.findViewById<View>(R.id.button_colic).setOnClickListener { contentView.findViewById<View>(R.id.button_colic).setOnClickListener({
logEvent(LunaEvent(LunaEvent.TYPE_COLIC)) logEvent(
LunaEvent(LunaEvent.TYPE_COLIC)
)
dismiss() dismiss()
} })
contentView.findViewById<View>(R.id.button_scale).setOnClickListener { contentView.findViewById<View>(R.id.button_scale).setOnClickListener({
askWeightValue(LunaEvent(LunaEvent.TYPE_WEIGHT)) askWeightValue()
dismiss() dismiss()
} })
contentView.findViewById<View>(R.id.button_bath).setOnClickListener { contentView.findViewById<View>(R.id.button_bath).setOnClickListener({
logEvent(LunaEvent(LunaEvent.TYPE_BATH)) logEvent(
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 - 1] context.resources.getStringArray(R.array.AmountLabels)[item.quantity]
else -> else ->
item.quantity item.quantity
}) })

View File

@@ -1,16 +0,0 @@
<?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

@@ -3,36 +3,20 @@
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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:layout_gravity="center"
android:gravity="center">
<LinearLayout <EditText
android:layout_width="match_parent" android:id="@+id/dialog_number_edittext"
android:layout_height="match_parent" android:layout_width="150dp"
android:layout_gravity="center" android:layout_height="wrap_content"
android:gravity="center" android:inputType="number"
android:orientation="horizontal"> android:hint="0"
android:background="@drawable/textview_background"/>
<EditText
android:id="@+id/dialog_number_edittext"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="0"
android:background="@drawable/textview_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="g"/>
</LinearLayout>
<TextView <TextView
android:id="@+id/dialog_date_picker"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"/> android:text="g"/>
</LinearLayout> </LinearLayout>

View File

@@ -14,11 +14,4 @@
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,12 +23,4 @@
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>