From d5cb30cdd7654e11e34df8a7387f3f3f4dffacdd Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Sun, 24 Nov 2024 08:26:39 +0100 Subject: [PATCH] Added Medicine and Enema types, overflow menu --- .../lunatracker/MainActivity.kt | 62 ++++++++++++++++++- .../adapters/LunaEventRecyclerAdapter.kt | 26 +------- .../lunatracker/entities/LunaEvent.kt | 44 +++++++++++++ .../drawable/button_background_released.xml | 2 + app/src/main/res/drawable/ic_more.xml | 5 ++ app/src/main/res/layout/activity_main.xml | 15 ++++- app/src/main/res/layout/dialog_notes.xml | 23 +++++++ app/src/main/res/layout/more_events_popup.xml | 49 +++++++++++++++ app/src/main/res/values-it/strings.xml | 12 ++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 16 ++++- 11 files changed, 226 insertions(+), 29 deletions(-) create mode 100644 app/src/main/res/drawable/ic_more.xml create mode 100644 app/src/main/res/layout/dialog_notes.xml create mode 100644 app/src/main/res/layout/more_events_popup.xml diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 88de4db..0e3f8df 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -4,9 +4,12 @@ import android.content.Intent import android.os.Bundle import android.os.Handler import android.util.Log +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.EditText import android.widget.NumberPicker +import android.widget.PopupWindow import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AlertDialog @@ -89,6 +92,10 @@ class MainActivity : AppCompatActivity() { LunaEvent.TYPE_DIAPERCHANGE_PEE ) ) } + val moreButton = findViewById(R.id.button_more) + moreButton.setOnClickListener { + showOverflowPopupWindow(moreButton) + } findViewById(R.id.button_no_connection_settings).setOnClickListener({ showSettings() }) @@ -177,7 +184,7 @@ class MainActivity : AppCompatActivity() { d.setTitle(R.string.log_weight_dialog_title) d.setMessage(R.string.log_weight_dialog_description) d.setView(dialogView) - val weightET = dialogView.findViewById(R.id.dialog_number_edittext) + val weightET = dialogView.findViewById(R.id.dialog_number_edittext) d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> val weight = weightET.text.toString().toIntOrNull() if (weight != null) @@ -190,6 +197,38 @@ class MainActivity : AppCompatActivity() { alertDialog.show() } + fun askNotes(lunaEvent: LunaEvent) { + val d = AlertDialog.Builder(this) + val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null) + d.setTitle(lunaEvent.getTypeDescription(this)) + d.setMessage( + when (lunaEvent.type){ + LunaEvent.TYPE_MEDICINE -> R.string.log_medicine_dialog_description + else -> R.string.log_notes_dialog_description + } + ) + d.setView(dialogView) + val notesET = dialogView.findViewById(R.id.notes_edittext) + val qtyET = dialogView.findViewById(R.id.notes_qty_edittext) + 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() + lunaEvent.notes = notes + logEvent(lunaEvent) + } + d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() } + val alertDialog = d.create() + alertDialog.show() + } + fun askToTrimLogbook() { val d = AlertDialog.Builder(this) d.setTitle(R.string.trim_logbook_dialog_title) @@ -384,4 +423,25 @@ class MainActivity : AppCompatActivity() { } } + private fun showOverflowPopupWindow(anchor: View) { + PopupWindow(anchor.context).apply { + isOutsideTouchable = true + val inflater = LayoutInflater.from(anchor.context) + contentView = inflater.inflate(R.layout.more_events_popup, null) + contentView.findViewById(R.id.button_medicine).setOnClickListener({ + askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE)) + dismiss() + }) + contentView.findViewById(R.id.button_enema).setOnClickListener({ + logEvent(LunaEvent(LunaEvent.TYPE_ENEMA)) + dismiss() + }) + contentView.findViewById(R.id.button_custom).setOnClickListener({ + Toast.makeText(anchor.context, "TODO: Implement custom events", Toast.LENGTH_SHORT).show() + dismiss() + }) + }.also { popupWindow -> + popupWindow.showAsDropDown(anchor) + } + } } diff --git a/app/src/main/java/it/danieleverducci/lunatracker/adapters/LunaEventRecyclerAdapter.kt b/app/src/main/java/it/danieleverducci/lunatracker/adapters/LunaEventRecyclerAdapter.kt index 6cd378e..a69bcf8 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/adapters/LunaEventRecyclerAdapter.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/adapters/LunaEventRecyclerAdapter.kt @@ -33,30 +33,8 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter R.string.event_bottle_type - LunaEvent.TYPE_WEIGHT -> R.string.event_scale_type - LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE -> R.string.event_breastfeeding_left_type - LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_type - LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_type - LunaEvent.TYPE_DIAPERCHANGE_POO -> R.string.event_diaperchange_poo_type - LunaEvent.TYPE_DIAPERCHANGE_PEE -> R.string.event_diaperchange_pee_type - else -> R.string.event_unknown_type - } - ) - holder.description.text = context.getString( - when (item.type) { - LunaEvent.TYPE_BABY_BOTTLE -> R.string.event_bottle_desc - LunaEvent.TYPE_WEIGHT -> R.string.event_scale_desc - LunaEvent.TYPE_BREASTFEEDING_LEFT_NIPPLE -> R.string.event_breastfeeding_left_desc - LunaEvent.TYPE_BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_desc - LunaEvent.TYPE_BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_desc - LunaEvent.TYPE_DIAPERCHANGE_POO -> R.string.event_diaperchange_poo_desc - LunaEvent.TYPE_DIAPERCHANGE_PEE -> R.string.event_diaperchange_pee_desc - else -> R.string.event_unknown_desc - } - ) + holder.type.text = item.getTypeEmoji(context) + holder.description.text = item.getTypeDescription(context) holder.quantity.text = if ((item.quantity ?: 0) > 0) item.quantity.toString() else "" holder.time.text = formatTimeAgo(context, item.time) } 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 73280ca..44b877c 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/entities/LunaEvent.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/entities/LunaEvent.kt @@ -1,5 +1,7 @@ package it.danieleverducci.lunatracker.entities +import android.content.Context +import it.danieleverducci.lunatracker.R import org.json.JSONObject import java.util.Date @@ -19,6 +21,9 @@ class LunaEvent { val TYPE_BREASTFEEDING_RIGHT_NIPPLE = "BREASTFEEDING_RIGHT_NIPPLE" val TYPE_DIAPERCHANGE_POO = "DIAPERCHANGE_POO" val TYPE_DIAPERCHANGE_PEE = "DIAPERCHANGE_PEE" + val TYPE_MEDICINE = "MEDICINE" + val TYPE_ENEMA = "ENEMA" + val TYPE_CUSTOM = "CUSTOM" } private val jo: JSONObject @@ -39,6 +44,11 @@ class LunaEvent { if (value > 0) jo.put("quantity", value) } + var notes: String + get(): String = jo.getString("notes") + set(value) { + jo.put("notes", value) + } constructor(jo: JSONObject) { this.jo = jo @@ -60,6 +70,40 @@ class LunaEvent { this.quantity = quantity } + fun getTypeEmoji(context: Context): String { + return context.getString( + when (type) { + TYPE_BABY_BOTTLE -> R.string.event_bottle_type + TYPE_WEIGHT -> R.string.event_scale_type + TYPE_BREASTFEEDING_LEFT_NIPPLE -> R.string.event_breastfeeding_left_type + TYPE_BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_type + TYPE_BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_type + TYPE_DIAPERCHANGE_POO -> R.string.event_diaperchange_poo_type + TYPE_DIAPERCHANGE_PEE -> R.string.event_diaperchange_pee_type + TYPE_MEDICINE -> R.string.event_medicine_type + TYPE_ENEMA -> R.string.event_enema_type + else -> R.string.event_unknown_type + } + ) + } + + fun getTypeDescription(context: Context): String { + return context.getString( + when (type) { + TYPE_BABY_BOTTLE -> R.string.event_bottle_desc + TYPE_WEIGHT -> R.string.event_scale_desc + TYPE_BREASTFEEDING_LEFT_NIPPLE -> R.string.event_breastfeeding_left_desc + TYPE_BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_desc + TYPE_BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_desc + TYPE_DIAPERCHANGE_POO -> R.string.event_diaperchange_poo_desc + TYPE_DIAPERCHANGE_PEE -> R.string.event_diaperchange_pee_desc + TYPE_MEDICINE -> R.string.event_medicine_desc + TYPE_ENEMA -> R.string.event_enema_desc + else -> R.string.event_unknown_desc + } + ) + } + fun toJson(): JSONObject { return jo } diff --git a/app/src/main/res/drawable/button_background_released.xml b/app/src/main/res/drawable/button_background_released.xml index 171757c..b1741dc 100644 --- a/app/src/main/res/drawable/button_background_released.xml +++ b/app/src/main/res/drawable/button_background_released.xml @@ -3,6 +3,8 @@ + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 33af1dd..16d684e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -108,7 +108,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="10dp" - android:layout_weight="1" + android:layout_weight="2" android:background="@drawable/button_background" android:gravity="center_horizontal" android:textSize="30dp" @@ -119,12 +119,23 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="10dp" - android:layout_weight="1" + android:layout_weight="2" android:background="@drawable/button_background" android:gravity="center_horizontal" android:textSize="30dp" android:text="🚼 💧"/> + + diff --git a/app/src/main/res/layout/dialog_notes.xml b/app/src/main/res/layout/dialog_notes.xml new file mode 100644 index 0000000..997050a --- /dev/null +++ b/app/src/main/res/layout/dialog_notes.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/more_events_popup.xml b/app/src/main/res/layout/more_events_popup.xml new file mode 100644 index 0000000..b507d7e --- /dev/null +++ b/app/src/main/res/layout/more_events_popup.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 995827a..96015b7 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -17,8 +17,14 @@ 🤱 → 🚼 💩 🚼 💧 + 💊 + 🪠 - + 💊 Medicina + 🪠 Clistere + ➕ Aggiungi evento personalizzato + Biberon Pesata Allatt. al seno (sx) @@ -26,6 +32,8 @@ Allatt. al seno (dx) Cambio (con cacca) Cambio (con pipì) + Medicina + Clistere Evento aggiunto @@ -68,4 +76,8 @@ Cancella i più vecchi Ricordamelo dopo + Note: + Nome della medicina, quantità, formato, note…: + Quantità (numero intero), o lascia vuoto + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 98fe0d2..7945f72 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,5 +4,6 @@ #FF000000 #FFFFFFFF #c000 + #0000 #ccc \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e55477f..8e320bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,7 +17,9 @@ 🤱 → 🚼 💩 🚼 💧 - - + 💊 + 🪠 + \? Baby bottle Weight @@ -26,8 +28,14 @@ Breastfeeding (right) Diaper chg (poo) Diaper chg (pee) + Medicine + Enema + 💊 Medicine + 🪠 Enema + ➕ Add custom event + Event logged Logbook saved Unable to log the event @@ -49,7 +57,7 @@ On device Most privacy-friendly solution: data doesn\'t leave your device On a WebDAV server - You can use any WebDAV service (i.e. Nextcloud, Owncloud, Dropbox, Box...) to save the data. In this way you can syncronize it between more devices, i.e. the dad\'s, the mom\'s, the grandma\'s... You will need the WebDAV url, you can find it in your provider\'s documentation (i.e. in Nextcloud web is in the Files app settings) + You can use any WebDAV service (i.e. Nextcloud, Owncloud, Dropbox, Box…) to save the data. In this way you can syncronize it between more devices, i.e. the dad\'s, the mom\'s, the grandma\'s… You will need the WebDAV url, you can find it in your provider\'s documentation (i.e. in Nextcloud web is in the Files app settings) WebDAV url https:// Username @@ -68,4 +76,8 @@ Trim it now Remind me later + Notes: + Medicine name, quantity, type, notes…: + Integer quantity, or leave blank + \ No newline at end of file