From b1e035d03e7a5b1058ad12b125822264ea777f5a Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Thu, 25 Sep 2025 23:52:10 +0200 Subject: [PATCH] add puke event --- .../lunatracker/MainActivity.kt | 23 +++++++++++++++++++ .../lunatracker/entities/LunaEvent.kt | 3 +++ app/src/main/java/utils/NumericUtils.kt | 20 +++++++++------- app/src/main/res/layout/more_events_popup.xml | 10 ++++++++ app/src/main/res/layout/puke_dialog.xml | 17 ++++++++++++++ app/src/main/res/values/arrays.xml | 8 +++++++ app/src/main/res/values/strings.xml | 10 ++++++++ 7 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/layout/puke_dialog.xml create mode 100644 app/src/main/res/values/arrays.xml diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 0d51fd0..b2f7f99 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -260,6 +260,25 @@ class MainActivity : AppCompatActivity() { alertDialog.show() } + fun askPukeValue() { + val d = AlertDialog.Builder(this) + val dialogView = layoutInflater.inflate(R.layout.puke_dialog, null) + d.setTitle(R.string.log_puke_dialog_title) + d.setMessage(R.string.log_puke_dialog_description) + d.setView(dialogView) + + val spinner = dialogView.findViewById(R.id.dialog_puke_value) + spinner.adapter = ArrayAdapter.createFromResource(this, R.array.AmountLabels, android.R.layout.simple_spinner_dropdown_item) + + d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> + val pos = spinner.selectedItemPosition + logEvent(LunaEvent(LunaEvent.TYPE_PUKE, pos)) + } + d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() } + val alertDialog = d.create() + alertDialog.show() + } + fun askNotes(lunaEvent: LunaEvent) { val d = AlertDialog.Builder(this) val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null) @@ -787,6 +806,10 @@ class MainActivity : AppCompatActivity() { askTemperatureValue() dismiss() }) + contentView.findViewById(R.id.button_puke).setOnClickListener({ + askPukeValue() + dismiss() + }) contentView.findViewById(R.id.button_colic).setOnClickListener({ logEvent( LunaEvent(LunaEvent.TYPE_COLIC) diff --git a/app/src/main/java/it/danieleverducci/lunatracker/entities/LunaEvent.kt b/app/src/main/java/it/danieleverducci/lunatracker/entities/LunaEvent.kt index 30444c9..c0ce7c1 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/entities/LunaEvent.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/entities/LunaEvent.kt @@ -28,6 +28,7 @@ class LunaEvent: Comparable { const val TYPE_COLIC = "COLIC" const val TYPE_TEMPERATURE = "TEMPERATURE" const val TYPE_FOOD = "FOOD" + const val TYPE_PUKE = "PUKE" } private val jo: JSONObject @@ -90,6 +91,7 @@ class LunaEvent: Comparable { TYPE_TEMPERATURE -> R.string.event_temperature_type TYPE_COLIC -> R.string.event_colic_type TYPE_FOOD -> R.string.event_food_type + TYPE_PUKE -> R.string.event_puke_type else -> R.string.event_unknown_type } ) @@ -111,6 +113,7 @@ class LunaEvent: Comparable { TYPE_TEMPERATURE -> R.string.event_temperature_desc TYPE_COLIC -> R.string.event_colic_desc TYPE_FOOD -> R.string.event_food_desc + TYPE_PUKE -> R.string.event_puke_desc else -> R.string.event_unknown_desc } ) diff --git a/app/src/main/java/utils/NumericUtils.kt b/app/src/main/java/utils/NumericUtils.kt index f847ef9..0e34e11 100644 --- a/app/src/main/java/utils/NumericUtils.kt +++ b/app/src/main/java/utils/NumericUtils.kt @@ -18,8 +18,8 @@ class NumericUtils (val context: Context) { private fun isMetricSystem(): Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { val measurementSystem = LocaleData.getMeasurementSystem(ULocale.getDefault()) - return (measurementSystem == LocaleData. MeasurementSystem.SI) - } else { + return (measurementSystem == LocaleData.MeasurementSystem.SI) + } else { val locale = context.resources.configuration.locale return when (locale.country) { // https://en.wikipedia.org/wiki/United_States_customary_units @@ -29,7 +29,7 @@ class NumericUtils (val context: Context) { "GB", "MM", "LR" -> false // IMPERIAL else -> true // UnitSystem.METRIC } - } + } } init { @@ -62,11 +62,15 @@ class NumericUtils (val context: Context) { fun formatEventQuantity(item: LunaEvent): String { val formatted = StringBuilder() - if ((item.quantity ?: 0) > 0) { - if (item.type == LunaEvent.TYPE_TEMPERATURE) - formatted.append((item.quantity / 10.0f).toString()) - else - formatted.append(item.quantity) + if (item.quantity > 0) { + formatted.append(when (item.type) { + LunaEvent.TYPE_TEMPERATURE -> + (item.quantity / 10.0f).toString() + LunaEvent.TYPE_PUKE -> + context.resources.getStringArray(R.array.AmountLabels)[item.quantity] + else -> + item.quantity + }) formatted.append(" ") formatted.append( diff --git a/app/src/main/res/layout/more_events_popup.xml b/app/src/main/res/layout/more_events_popup.xml index 596bc0c..05758d0 100644 --- a/app/src/main/res/layout/more_events_popup.xml +++ b/app/src/main/res/layout/more_events_popup.xml @@ -49,6 +49,16 @@ style="@style/OverflowMenuText" android:text="@string/overflow_event_temperature"/> + + + + + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..393837a --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,8 @@ + + + + @string/amount_low + @string/amount_medium + @string/amount_high + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be25ce8..e867813 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,6 +12,9 @@ Temperature Insert the temperature + Puke + Select the amount + 🍼 🥣 ⚖️ @@ -25,6 +28,7 @@ 📝 🌡️ 💨 + 🤮 \? Baby bottle @@ -40,6 +44,7 @@ Note Temperature Gaseous colic + Puke ⚖️ Weight @@ -48,6 +53,7 @@ 📝 Note 🌡️ Temperature 💨 Gaseous colic + 🤮 Puke Event logged Logbook saved @@ -66,6 +72,10 @@ year years + Low + Medium + High + No connection Unable to reach WebDAV service Settings