1 Commits

Author SHA1 Message Date
b719903a73 use creation dialog as edit dialog 2025-11-10 20:53:51 +01:00
10 changed files with 387 additions and 136 deletions

View File

@@ -82,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(
@@ -100,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 {
@@ -132,7 +128,7 @@ class MainActivity : AppCompatActivity() {
val adapter = LunaEventRecyclerAdapter(this, items) val adapter = LunaEventRecyclerAdapter(this, items)
adapter.onItemClickListener = object: LunaEventRecyclerAdapter.OnItemClickListener { adapter.onItemClickListener = object: LunaEventRecyclerAdapter.OnItemClickListener {
override fun onItemClick(event: LunaEvent) { override fun onItemClick(event: LunaEvent) {
showEventDetailDialog(event, items) showEventDetailDialog(event)
} }
} }
recyclerView.adapter = adapter recyclerView.adapter = adapter
@@ -195,30 +191,55 @@ class MainActivity : AppCompatActivity() {
super.onStop() super.onStop()
} }
fun askBabyBottleContent() { fun getAllEvents(): ArrayList<LunaEvent> {
// Show number picker dialog return logbook?.logs ?: arrayListOf()
val localSettings = LocalSettingsRepository(this) }
fun askBabyBottleContent(event: LunaEvent, showDetailsAtEnd : Boolean = false) {
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)
d.setMessage(R.string.log_bottle_dialog_description) d.setMessage(R.string.log_bottle_dialog_description)
d.setView(dialogView) d.setView(dialogView)
val numberPicker = dialogView.findViewById<NumberPicker>(R.id.dialog_number_picker) val numberPicker = dialogView.findViewById<NumberPicker>(R.id.dialog_number_picker)
numberPicker.minValue = 1 // "10" numberPicker.minValue = 1 // "10"
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 = localSettings.loadBabyBottleContent() numberPicker.value = event.quantity / 10
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV)
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
logEvent(LunaEvent(LunaEvent.TYPE_BABY_BOTTLE, numberPicker.value * 10)) val quantity = numberPicker.value * 10
localSettings.saveBabyBottleContent(numberPicker.value) val time = pickedDateTime.time.time / 1000
if (event.time != time || event.quantity != quantity) {
event.time = time
event.quantity = quantity
saveEvent(event)
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
val alertDialog = d.create() 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)
@@ -226,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.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() 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)
@@ -250,19 +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.time = time
event.quantity = quantity
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askPukeValue() { fun datePickHelper(eventTime: Long, dateTextView: TextView): Calendar {
val fmt = getString(R.string.dialog_event_detail_datetime_icon)
dateTextView.text = String.format(fmt, DateUtils.formatDateTime(eventTime))
val dateTime = Calendar.getInstance()
dateTime.time = Date(eventTime * 1000)
dateTextView.setOnClickListener {
// Show datetime picker
val startYear = dateTime.get(Calendar.YEAR)
val startMonth = dateTime.get(Calendar.MONTH)
val startDay = dateTime.get(Calendar.DAY_OF_MONTH)
val startHour = dateTime.get(Calendar.HOUR_OF_DAY)
val startMinute = dateTime.get(Calendar.MINUTE)
DatePickerDialog(this, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute ->
dateTime.set(year, month, day, hour, minute)
val time = dateTime.time.time / 1000
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(time))
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
}, startYear, startMonth, startDay).show()
}
return dateTime
}
fun saveEvent(event: LunaEvent) {
if (!getAllEvents().contains(event)) {
// new event
logEvent(event)
}
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
}
fun askPukeValue(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
val d = AlertDialog.Builder(this) val 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)
@@ -271,42 +370,135 @@ class MainActivity : AppCompatActivity() {
val spinner = dialogView.findViewById<Spinner>(R.id.dialog_puke_value) 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.adapter = ArrayAdapter.createFromResource(this, R.array.AmountLabels, android.R.layout.simple_spinner_dropdown_item)
spinner.setSelection(1) spinner.setSelection(event.quantity)
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV)
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val pos = spinner.selectedItemPosition val quantity = spinner.selectedItemPosition + 1
logEvent(LunaEvent(LunaEvent.TYPE_PUKE, pos + 1)) val time = pickedDateTime.time.time / 1000
if (event.time != time || event.quantity != quantity) {
event.time = time
event.quantity = quantity
saveEvent(event)
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
fun askNotes(lunaEvent: LunaEvent) { // Ask to edit events to be edited (only affects date)
fun askPlain(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_plain_event, null)
d.setTitle(event.getTypeDescription(this))
d.setMessage(event.getDialogMessage(this))
d.setView(dialogView)
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV)
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val time = pickedDateTime.time.time / 1000
if (event.time != time) {
event.time = time
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
val alertDialog = d.create()
alertDialog.show()
// a shortcut, since the only value to change is the date
dateTV.performClick()
}
fun askNotes(event: LunaEvent, showDetailsAtEnd: Boolean = false) {
val useQuantity = (event.type != LunaEvent.TYPE_NOTE && event.type != LunaEvent.TYPE_CUSTOM)
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null) val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null)
d.setTitle(lunaEvent.getTypeDescription(this)) d.setTitle(event.getTypeDescription(this))
d.setMessage(lunaEvent.getDialogMessage(this)) d.setMessage(event.getDialogMessage(this))
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)
if (lunaEvent.type == LunaEvent.TYPE_NOTE || lunaEvent.type == LunaEvent.TYPE_CUSTOM)
val dateTV = dialogView.findViewById<TextView>(R.id.notes_date_picker)
val pickedDateTime = datePickHelper(event.time, dateTV)
notesET.setText(event.notes)
if (useQuantity) {
qtyET.setText(event.quantity.toString())
} else {
qtyET.visibility = View.GONE qtyET.visibility = View.GONE
}
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
val qtyStr = qtyET.text.toString()
if (qtyStr.isNotEmpty()) {
val qty = qtyStr.toIntOrNull()
if (qty == null) {
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
return@setPositiveButton
}
lunaEvent.quantity = qty
}
val notes = notesET.text.toString() val notes = notesET.text.toString()
lunaEvent.notes = notes val time = pickedDateTime.time.time / 1000
logEvent(lunaEvent)
if (useQuantity) {
val quantity = qtyET.text.toString().toIntOrNull()
if (quantity != null) {
if (event.time != time || event.notes != notes || event.quantity != quantity ) {
event.time = time
event.notes = notes
event.quantity = quantity
saveEvent(event)
} }
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() } } else {
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
} else {
if (event.time != time || event.notes != notes) {
event.time = time
event.notes = notes
saveEvent(event)
}
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
}
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
dialogInterface.dismiss()
if (showDetailsAtEnd) {
showEventDetailDialog(event)
}
}
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
} }
@@ -359,55 +551,56 @@ class MainActivity : AppCompatActivity() {
return nextEvent return nextEvent
} }
fun showEventDetailDialog(event: LunaEvent, items: ArrayList<LunaEvent>) { fun showEventDetailDialog(event: LunaEvent) {
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user // Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
pauseLogbookUpdate = true pauseLogbookUpdate = true
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
d.setTitle(R.string.dialog_event_detail_title) d.setTitle(R.string.dialog_event_detail_title)
val dialogView = layoutInflater.inflate(R.layout.dialog_event_detail, null) val dialogView = layoutInflater.inflate(R.layout.dialog_event_detail, null)
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji).text = event.getTypeEmoji(this) val emojiTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji)
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description).text = event.getTypeDescription(this) val descriptionTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description)
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity).text = val quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity)
NumericUtils(this).formatEventQuantity(event) val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes)
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).text = event.notes
val currentDateTime = Calendar.getInstance() emojiTextView.text = event.getTypeEmoji(this)
currentDateTime.time = Date(event.time * 1000) descriptionTextView.text = event.getTypeDescription(this)
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
notesTextView.text = event.notes
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date) val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date)
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time)) dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
dateTextView.setOnClickListener {
// Show datetime picker
val startYear = currentDateTime.get(Calendar.YEAR)
val startMonth = currentDateTime.get(Calendar.MONTH)
val startDay = currentDateTime.get(Calendar.DAY_OF_MONTH)
val startHour = currentDateTime.get(Calendar.HOUR_OF_DAY)
val startMinute = currentDateTime.get(Calendar.MINUTE)
DatePickerDialog(this, { _, year, month, day ->
TimePickerDialog(this, { _, hour, minute ->
val pickedDateTime = Calendar.getInstance()
pickedDateTime.set(year, month, day, hour, minute)
// Save event and move it to the right position in the logbook
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
logbook?.sort()
recyclerView.adapter?.notifyDataSetChanged()
saveLogbook()
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
}, startYear, startMonth, startDay).show()
}
d.setView(dialogView) d.setView(dialogView)
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() } 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.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> deleteEvent(event) }
d.setNegativeButton(R.string.dialog_event_detail_edit_button) { dialogInterface, i ->
when (event.type) {
LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, true)
LunaEvent.TYPE_WEIGHT -> askWeightValue(event, true)
LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE,
LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE,
LunaEvent.TYPE_ENEMA,
LunaEvent.TYPE_BATH,
LunaEvent.TYPE_COLIC,
LunaEvent.TYPE_CUSTOM,
LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE -> askPlain(event, true)
LunaEvent.TYPE_MEDICINE -> askNotes(event, true)
LunaEvent.TYPE_NOTE -> askNotes(event, true)
LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, true)
LunaEvent.TYPE_FOOD -> askNotes(event, true)
LunaEvent.TYPE_PUKE -> askPukeValue(event, true)
else -> {}
}
}
val alertDialog = d.create() val alertDialog = d.create()
alertDialog.show() alertDialog.show()
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ContextCompat.getColor(this, R.color.danger)) alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ContextCompat.getColor(this, R.color.danger))
alertDialog.setOnDismissListener({ alertDialog.setOnDismissListener {
// Resume logbook update // Resume logbook update
pauseLogbookUpdate = false pauseLogbookUpdate = false
}) }
// show optional signature // show optional signature
if (event.signature.isNotEmpty()) { if (event.signature.isNotEmpty()) {
@@ -417,11 +610,11 @@ class MainActivity : AppCompatActivity() {
} }
// create next/previous links to events of the same type // create next/previous links to events of the same type
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous) val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next) val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
val nextEvent = getNextSameEvent(event, items) val allEvents = getAllEvents()
val previousEvent = getPreviousSameEvent(event, items) val nextEvent = getNextSameEvent(event, allEvents)
val previousEvent = getPreviousSameEvent(event, allEvents)
if (previousEvent != null) { if (previousEvent != null) {
val emoji = previousEvent.getTypeEmoji(applicationContext) val emoji = previousEvent.getTypeEmoji(applicationContext)
@@ -429,7 +622,7 @@ class MainActivity : AppCompatActivity() {
previousTextView.text = String.format("⬅️ %s %s", emoji, time) previousTextView.text = String.format("⬅️ %s %s", emoji, time)
previousTextView.setOnClickListener { previousTextView.setOnClickListener {
alertDialog.cancel() alertDialog.cancel()
showEventDetailDialog(previousEvent, items) showEventDetailDialog(previousEvent)
} }
} else { } else {
previousTextView.visibility = View.GONE previousTextView.visibility = View.GONE
@@ -441,7 +634,7 @@ class MainActivity : AppCompatActivity() {
nextTextView.text = String.format("%s %s ➡️", time, emoji) nextTextView.text = String.format("%s %s ➡️", time, emoji)
nextTextView.setOnClickListener { nextTextView.setOnClickListener {
alertDialog.cancel() alertDialog.cancel()
showEventDetailDialog(nextEvent, items) showEventDetailDialog(nextEvent)
} }
} else { } else {
nextTextView.visibility = View.GONE nextTextView.visibility = View.GONE
@@ -804,38 +997,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, 1))
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

@@ -23,14 +23,6 @@ class LocalSettingsRepository(val context: Context) {
sharedPreferences = context.getSharedPreferences(SHARED_PREFS_FILE_NAME, MODE_PRIVATE) sharedPreferences = context.getSharedPreferences(SHARED_PREFS_FILE_NAME, MODE_PRIVATE)
} }
fun saveBabyBottleContent(content: Int) {
sharedPreferences.edit { putInt(SHARED_PREFS_BB_CONTENT, content) }
}
fun loadBabyBottleContent(): Int {
return sharedPreferences.getInt(SHARED_PREFS_BB_CONTENT, 1)
}
fun saveSignature(content: String) { fun saveSignature(content: String) {
sharedPreferences.edit { putString(SHARED_PREFS_SIGNATURE, content) } sharedPreferences.edit { putString(SHARED_PREFS_SIGNATURE, content) }
} }

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@@ -37,8 +36,7 @@
android:drawableTint="@color/accent" android:drawableTint="@color/accent"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
android:text="@string/dialog_event_detail_datetime_icon" android:text="@string/dialog_event_detail_datetime_icon" />
app:drawableEndCompat="@drawable/ic_edit" />
<TextView <TextView
android:id="@+id/dialog_event_detail_type_quantity" android:id="@+id/dialog_event_detail_type_quantity"

View File

@@ -24,4 +24,11 @@
android:hint="@string/log_notes_dialog_note_hint" android:hint="@string/log_notes_dialog_note_hint"
android:background="@drawable/textview_background"/> android:background="@drawable/textview_background"/>
<TextView
android:id="@+id/notes_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>
</LinearLayout> </LinearLayout>

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

@@ -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">
<NumberPicker <NumberPicker
android:id="@+id/dialog_number_picker" android:id="@+id/dialog_number_picker"
@@ -16,4 +22,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:text="ml"/> android:text="ml"/>
</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>

View File

@@ -15,6 +15,8 @@
<string name="log_puke_dialog_title">Puke</string> <string name="log_puke_dialog_title">Puke</string>
<string name="log_puke_dialog_description">Select the amount</string> <string name="log_puke_dialog_description">Select the amount</string>
<string name="dialog_event_detail_edit_button">Edit</string>
<string name="event_bottle_type" translatable="false">🍼</string> <string name="event_bottle_type" translatable="false">🍼</string>
<string name="event_food_type" translatable="false">🥣</string> <string name="event_food_type" translatable="false">🥣</string>
<string name="event_scale_type" translatable="false">⚖️</string> <string name="event_scale_type" translatable="false">⚖️</string>