MainActivity: allow amount for poo and pee events

An unspecified amount has also been added
to have the same semantics as before.

During these actions, the strings for title
and description of dialogs have been cleaned up.
This commit is contained in:
2025-11-12 22:47:09 +01:00
parent 80a70dfbf3
commit 8493d2822f
9 changed files with 68 additions and 96 deletions

View File

@@ -100,10 +100,10 @@ class MainActivity : AppCompatActivity() {
addPlainEvent(LunaEvent(LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE)) addPlainEvent(LunaEvent(LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE))
} }
findViewById<View>(R.id.button_change_poo).setOnClickListener { findViewById<View>(R.id.button_change_poo).setOnClickListener {
addPlainEvent(LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_POO)) addAmountEvent(LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_POO))
} }
findViewById<View>(R.id.button_change_pee).setOnClickListener { findViewById<View>(R.id.button_change_pee).setOnClickListener {
addPlainEvent(LunaEvent(LunaEvent.TYPE_DIAPERCHANGE_PEE)) addAmountEvent(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 {
@@ -205,8 +205,8 @@ class MainActivity : AppCompatActivity() {
fun askBabyBottleContent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) { fun askBabyBottleContent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_bottle, null) val dialogView = layoutInflater.inflate(R.layout.dialog_edit_bottle, null)
d.setTitle(R.string.log_bottle_dialog_title) d.setTitle(event.getTypeDescription(this))
d.setMessage(R.string.log_bottle_dialog_description) d.setMessage(event.getDialogMessage(this))
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)
@@ -246,8 +246,8 @@ class MainActivity : AppCompatActivity() {
// Show number picker dialog // Show number picker dialog
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_weight, null) val dialogView = layoutInflater.inflate(R.layout.dialog_edit_weight, null)
d.setTitle(R.string.log_weight_dialog_title) d.setTitle(event.getTypeDescription(this))
d.setMessage(R.string.log_weight_dialog_description) d.setMessage(event.getDialogMessage(this))
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)
@@ -289,8 +289,8 @@ class MainActivity : AppCompatActivity() {
// Show number picker dialog // Show number picker dialog
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_temperature, null) val dialogView = layoutInflater.inflate(R.layout.dialog_edit_temperature, null)
d.setTitle(R.string.log_temperature_dialog_title) d.setTitle(event.getTypeDescription(this))
d.setMessage(R.string.log_temperature_dialog_description) d.setMessage(event.getDialogMessage(this))
d.setView(dialogView) d.setView(dialogView)
val tempSlider = dialogView.findViewById<Slider>(R.id.dialog_temperature_value) val tempSlider = dialogView.findViewById<Slider>(R.id.dialog_temperature_value)
@@ -369,24 +369,25 @@ class MainActivity : AppCompatActivity() {
saveLogbook() saveLogbook()
} }
fun addPukeEvent(event: LunaEvent) { fun addAmountEvent(event: LunaEvent) {
askPukeValue(event, true) { saveEvent(event) } askAmountValue(event, true) { saveEvent(event) }
} }
fun askPukeValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) { fun askAmountValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
val d = AlertDialog.Builder(this) val d = AlertDialog.Builder(this)
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_puke, null) val dialogView = layoutInflater.inflate(R.layout.dialog_edit_amount, null)
d.setTitle(R.string.log_puke_dialog_title) d.setTitle(event.getTypeDescription(this))
d.setMessage(R.string.log_puke_dialog_description) d.setMessage(event.getDialogMessage(this))
d.setView(dialogView) d.setView(dialogView)
val spinner = dialogView.findViewById<Spinner>(R.id.dialog_puke_value) val spinner = dialogView.findViewById<Spinner>(R.id.dialog_amount_value)
spinner.adapter = ArrayAdapter.createFromResource( spinner.adapter = ArrayAdapter.createFromResource(
this, this,
R.array.AmountLabels, R.array.AmountLabels,
android.R.layout.simple_spinner_dropdown_item android.R.layout.simple_spinner_dropdown_item
) )
spinner.setSelection(event.quantity - 1) // set pre-selected item and ensure the quantity to index is in bounds
spinner.setSelection(event.quantity.coerceIn(0, spinner.count - 1))
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker) val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
val pickedTime = datePickerHelper(event.time, dateTV) val pickedTime = datePickerHelper(event.time, dateTV)
@@ -396,7 +397,7 @@ class MainActivity : AppCompatActivity() {
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
event.time = pickedTime.time.time / 1000 event.time = pickedTime.time.time / 1000
event.quantity = spinner.selectedItemPosition + 1 event.quantity = spinner.selectedItemPosition
onPositive() onPositive()
dialogInterface.dismiss() dialogInterface.dismiss()
} }
@@ -580,7 +581,9 @@ class MainActivity : AppCompatActivity() {
when (event.type) { when (event.type) {
LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, false, updateValues) LunaEvent.TYPE_BABY_BOTTLE -> askBabyBottleContent(event, false, updateValues)
LunaEvent.TYPE_WEIGHT -> askWeightValue(event, false, updateValues) LunaEvent.TYPE_WEIGHT -> askWeightValue(event, false, updateValues)
LunaEvent.TYPE_PUKE -> askPukeValue(event, false, updateValues) LunaEvent.TYPE_DIAPERCHANGE_POO,
LunaEvent.TYPE_DIAPERCHANGE_PEE,
LunaEvent.TYPE_PUKE -> askAmountValue(event, false, updateValues)
LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, false, updateValues) LunaEvent.TYPE_TEMPERATURE -> askTemperatureValue(event, false, updateValues)
LunaEvent.TYPE_NOTE -> askNotes(event, false, updateValues) LunaEvent.TYPE_NOTE -> askNotes(event, false, updateValues)
} }
@@ -1037,7 +1040,7 @@ class MainActivity : AppCompatActivity() {
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_puke).setOnClickListener { contentView.findViewById<View>(R.id.button_puke).setOnClickListener {
addPukeEvent(LunaEvent(LunaEvent.TYPE_PUKE, 1)) addAmountEvent(LunaEvent(LunaEvent.TYPE_PUKE))
dismiss() dismiss()
} }
contentView.findViewById<View>(R.id.button_colic).setOnClickListener { contentView.findViewById<View>(R.id.button_colic).setOnClickListener {

View File

@@ -138,10 +138,18 @@ class LunaEvent: Comparable<LunaEvent> {
} }
fun getDialogMessage(context: Context): String? { fun getDialogMessage(context: Context): String? {
return when(type) { return context.getString(
TYPE_MEDICINE -> context.getString(R.string.log_medicine_dialog_description) when(type) {
else -> null TYPE_BABY_BOTTLE -> R.string.log_bottle_dialog_description
} TYPE_MEDICINE -> R.string.log_medicine_dialog_description
TYPE_TEMPERATURE -> R.string.log_temperature_dialog_description
TYPE_DIAPERCHANGE_POO,
TYPE_DIAPERCHANGE_PEE,
TYPE_PUKE -> R.string.log_amount_dialog_description
TYPE_WEIGHT -> R.string.log_weight_dialog_description
else -> R.string.log_unknown_dialog_description
}
)
} }
fun toJson(): JSONObject { fun toJson(): JSONObject {

View File

@@ -4,6 +4,7 @@ import android.content.Context
import android.icu.util.LocaleData import android.icu.util.LocaleData
import android.icu.util.ULocale import android.icu.util.ULocale
import android.os.Build import android.os.Build
import android.util.Log
import it.danieleverducci.lunatracker.R import it.danieleverducci.lunatracker.R
import it.danieleverducci.lunatracker.entities.LunaEvent import it.danieleverducci.lunatracker.entities.LunaEvent
import java.text.NumberFormat import java.text.NumberFormat
@@ -66,8 +67,15 @@ class NumericUtils (val context: Context) {
formatted.append(when (event.type) { formatted.append(when (event.type) {
LunaEvent.TYPE_TEMPERATURE -> LunaEvent.TYPE_TEMPERATURE ->
(event.quantity / 10.0f).toString() (event.quantity / 10.0f).toString()
LunaEvent.TYPE_PUKE -> LunaEvent.TYPE_DIAPERCHANGE_POO,
context.resources.getStringArray(R.array.AmountLabels)[event.quantity - 1] LunaEvent.TYPE_DIAPERCHANGE_PEE,
LunaEvent.TYPE_PUKE -> {
val array = context.resources.getStringArray(R.array.AmountLabels)
return array.getOrElse(event.quantity) {
Log.e("NumericUtils", "Invalid index ${event.quantity}")
return ""
}
}
else -> else ->
event.quantity event.quantity
}) })

View File

@@ -1,24 +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:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<Spinner
android:id="@+id/dialog_puke_value"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
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>

View File

@@ -3,15 +3,6 @@
<string name="title">🌜 LunaTracker 🌛</string> <string name="title">🌜 LunaTracker 🌛</string>
<string name="logbook">Ereignisprotokoll</string> <string name="logbook">Ereignisprotokoll</string>
<string name="log_bottle_dialog_title">Fläschchen</string>
<string name="log_bottle_dialog_description">Trinkmenge eingeben</string>
<string name="log_weight_dialog_title">Gewicht</string>
<string name="log_weight_dialog_description">Gewicht eingeben</string>
<string name="log_temperature_dialog_title">Temperatur</string>
<string name="log_temperature_dialog_description">Temperatur eingeben</string>
<string name="event_bottle_desc">Fläschchen</string> <string name="event_bottle_desc">Fläschchen</string>
<string name="event_food_desc">Essen</string> <string name="event_food_desc">Essen</string>
<string name="event_weight_desc">Gewicht</string> <string name="event_weight_desc">Gewicht</string>
@@ -77,10 +68,13 @@
<string name="trim_logbook_dialog_button_ok">Jetzt bereinigen</string> <string name="trim_logbook_dialog_button_ok">Jetzt bereinigen</string>
<string name="trim_logbook_dialog_button_cancel">Später erinnern</string> <string name="trim_logbook_dialog_button_cancel">Später erinnern</string>
<string name="log_notes_dialog_description">Notizen:</string> <string name="log_bottle_dialog_description">Trinkmenge eingeben</string>
<string name="log_medicine_dialog_description">Medikamentenname, Menge, Art, Notizen, …:</string> <string name="log_medicine_dialog_description">Medikamentenname, Menge, Art, Notizen, …:</string>
<string name="log_notes_dialog_qty_hint">Menge (optional)</string> <string name="log_notes_dialog_description">Notizen:</string>
<string name="log_notes_dialog_note_hint">Notiz eingeben</string> <string name="log_notes_dialog_note_hint">Notiz eingeben</string>
<string name="log_notes_dialog_qty_hint">Menge (optional)</string>
<string name="log_temperature_dialog_description">Temperatur eingeben</string>
<string name="log_weight_dialog_description">Gewicht eingeben</string>
<string name="dialog_event_detail_title">Ereignisdetails</string> <string name="dialog_event_detail_title">Ereignisdetails</string>
<string name="dialog_event_detail_close_button">OK</string> <string name="dialog_event_detail_close_button">OK</string>

View File

@@ -3,15 +3,6 @@
<string name="title">🌜 LunaTracker 🌛</string> <string name="title">🌜 LunaTracker 🌛</string>
<string name="logbook">Entrées enregistrées</string> <string name="logbook">Entrées enregistrées</string>
<string name="log_bottle_dialog_title">Biberon</string>
<string name="log_bottle_dialog_description">Renseignez la quantité contenue dans le biberon</string>
<string name="log_weight_dialog_title">Poids</string>
<string name="log_weight_dialog_description">Renseignez le poids</string>
<string name="log_temperature_dialog_title">Température</string>
<string name="log_temperature_dialog_description">Renseignez la Température</string>
<string name="event_bottle_desc">Biberon</string> <string name="event_bottle_desc">Biberon</string>
<string name="event_food_desc">Nourriture</string> <string name="event_food_desc">Nourriture</string>
<string name="event_weight_desc">Poids</string> <string name="event_weight_desc">Poids</string>
@@ -76,10 +67,13 @@
<string name="trim_logbook_dialog_button_ok">Supprimer les vieilles entrées maintenant</string> <string name="trim_logbook_dialog_button_ok">Supprimer les vieilles entrées maintenant</string>
<string name="trim_logbook_dialog_button_cancel">Me rappeller plus tard</string> <string name="trim_logbook_dialog_button_cancel">Me rappeller plus tard</string>
<string name="log_notes_dialog_description">Notes:</string> <string name="log_bottle_dialog_description">Renseignez la quantité contenue dans le biberon</string>
<string name="log_medicine_dialog_description">nom du médicament, quantité, type, notes …:</string> <string name="log_medicine_dialog_description">nom du médicament, quantité, type, notes …:</string>
<string name="log_notes_dialog_qty_hint">Quantité (ou vide)</string> <string name="log_notes_dialog_description">Notes:</string>
<string name="log_notes_dialog_note_hint">Notes ...</string> <string name="log_notes_dialog_note_hint">Notes ...</string>
<string name="log_notes_dialog_qty_hint">Quantité (ou vide)</string>
<string name="log_temperature_dialog_description">Renseignez la Température</string>
<string name="log_weight_dialog_description">Renseignez le poids</string>
<string name="dialog_event_detail_title">Détails de l\'entrée</string> <string name="dialog_event_detail_title">Détails de l\'entrée</string>
<string name="dialog_event_detail_close_button">OK</string> <string name="dialog_event_detail_close_button">OK</string>

View File

@@ -3,15 +3,6 @@
<string name="title">🌜 LunaTracker 🌛</string> <string name="title">🌜 LunaTracker 🌛</string>
<string name="logbook">Diario di bordo</string> <string name="logbook">Diario di bordo</string>
<string name="log_bottle_dialog_title">Biberon</string>
<string name="log_bottle_dialog_description">Inserisci la quantità contenuta nel biberon</string>
<string name="log_weight_dialog_title">Pesata</string>
<string name="log_weight_dialog_description">Inserisci il peso rilevato</string>
<string name="log_temperature_dialog_title">Temperatura</string>
<string name="log_temperature_dialog_description">Inserisci la temperatura</string>
<string name="overflow_event_weight">⚖️ Peso</string> <string name="overflow_event_weight">⚖️ Peso</string>
<string name="overflow_event_medicine">💊 Medicina</string> <string name="overflow_event_medicine">💊 Medicina</string>
<string name="overflow_event_enema">🪠 Clistere</string> <string name="overflow_event_enema">🪠 Clistere</string>
@@ -76,10 +67,13 @@
<string name="trim_logbook_dialog_button_ok">Cancella i più vecchi</string> <string name="trim_logbook_dialog_button_ok">Cancella i più vecchi</string>
<string name="trim_logbook_dialog_button_cancel">Ricordamelo dopo</string> <string name="trim_logbook_dialog_button_cancel">Ricordamelo dopo</string>
<string name="log_notes_dialog_description">Note:</string> <string name="log_bottle_dialog_description">Inserisci la quantità contenuta nel biberon</string>
<string name="log_medicine_dialog_description">Nome della medicina, quantità, formato, note…:</string> <string name="log_medicine_dialog_description">Nome della medicina, quantità, formato, note…:</string>
<string name="log_notes_dialog_qty_hint">Quantità, o vuoto</string> <string name="log_notes_dialog_description">Note:</string>
<string name="log_notes_dialog_note_hint">Inserisci le note</string> <string name="log_notes_dialog_note_hint">Inserisci le note</string>
<string name="log_notes_dialog_qty_hint">Quantità, o vuoto</string>
<string name="log_temperature_dialog_description">Inserisci la temperatura</string>
<string name="log_weight_dialog_description">Inserisci il peso rilevato</string>
<string name="dialog_event_detail_title">Dettaglio evento</string> <string name="dialog_event_detail_title">Dettaglio evento</string>
<string name="dialog_event_detail_close_button">OK</string> <string name="dialog_event_detail_close_button">OK</string>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string-array name="AmountLabels"> <string-array name="AmountLabels">
<item>@string/amount_unspecified</item>
<item>@string/amount_little</item> <item>@string/amount_little</item>
<item>@string/amount_normal</item> <item>@string/amount_normal</item>
<item>@string/amount_plenty</item> <item>@string/amount_plenty</item>

View File

@@ -3,18 +3,6 @@
<string name="title">🌜 LunaTracker 🌛</string> <string name="title">🌜 LunaTracker 🌛</string>
<string name="logbook">Logged events</string> <string name="logbook">Logged events</string>
<string name="log_bottle_dialog_title">Baby bottle</string>
<string name="log_bottle_dialog_description">Insert the quantity contained in the baby bottle</string>
<string name="log_weight_dialog_title">Weight</string>
<string name="log_weight_dialog_description">Insert the weight</string>
<string name="log_temperature_dialog_title">Temperature</string>
<string name="log_temperature_dialog_description">Insert the temperature</string>
<string name="log_puke_dialog_title">Puke</string>
<string name="log_puke_dialog_description">Select the amount</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_weight_type" translatable="false">⚖️</string> <string name="event_weight_type" translatable="false">⚖️</string>
@@ -75,6 +63,7 @@
<string name="year_ago">year</string> <string name="year_ago">year</string>
<string name="years_ago">years</string> <string name="years_ago">years</string>
<string name="amount_unspecified"></string>
<string name="amount_little">Little</string> <string name="amount_little">Little</string>
<string name="amount_normal">Normal</string> <string name="amount_normal">Normal</string>
<string name="amount_plenty">Plenty</string> <string name="amount_plenty">Plenty</string>
@@ -114,10 +103,15 @@
<string name="trim_logbook_dialog_button_ok">Trim it now</string> <string name="trim_logbook_dialog_button_ok">Trim it now</string>
<string name="trim_logbook_dialog_button_cancel">Remind me later</string> <string name="trim_logbook_dialog_button_cancel">Remind me later</string>
<string name="log_notes_dialog_description">Notes:</string> <string name="log_amount_dialog_description">Select the amount:</string>
<string name="log_bottle_dialog_description">Insert the quantity contained in the baby bottle:</string>
<string name="log_medicine_dialog_description">Medicine name, quantity, type, notes…:</string> <string name="log_medicine_dialog_description">Medicine name, quantity, type, notes…:</string>
<string name="log_notes_dialog_qty_hint">Quantity (or empty)</string> <string name="log_notes_dialog_description">Notes:</string>
<string name="log_notes_dialog_note_hint">Write some notes</string> <string name="log_notes_dialog_note_hint">Write some notes</string>
<string name="log_notes_dialog_qty_hint">Quantity (or empty)</string>
<string name="log_temperature_dialog_description">Select the temperature:</string>
<string name="log_unknown_dialog_description"></string>
<string name="log_weight_dialog_description">Insert the weight:</string>
<string name="measurement_unit_liquid_base_metric" translatable="false">ml</string> <string name="measurement_unit_liquid_base_metric" translatable="false">ml</string>
<string name="measurement_unit_weight_base_metric" translatable="false">g</string> <string name="measurement_unit_weight_base_metric" translatable="false">g</string>