Added Medicine and Enema types, overflow menu
This commit is contained in:
@ -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<View>(R.id.button_more)
|
||||
moreButton.setOnClickListener {
|
||||
showOverflowPopupWindow(moreButton)
|
||||
}
|
||||
findViewById<View>(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<TextView>(R.id.dialog_number_edittext)
|
||||
val weightET = dialogView.findViewById<EditText>(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<EditText>(R.id.notes_edittext)
|
||||
val qtyET = dialogView.findViewById<EditText>(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<View>(R.id.button_medicine).setOnClickListener({
|
||||
askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE))
|
||||
dismiss()
|
||||
})
|
||||
contentView.findViewById<View>(R.id.button_enema).setOnClickListener({
|
||||
logEvent(LunaEvent(LunaEvent.TYPE_ENEMA))
|
||||
dismiss()
|
||||
})
|
||||
contentView.findViewById<View>(R.id.button_custom).setOnClickListener({
|
||||
Toast.makeText(anchor.context, "TODO: Implement custom events", Toast.LENGTH_SHORT).show()
|
||||
dismiss()
|
||||
})
|
||||
}.also { popupWindow ->
|
||||
popupWindow.showAsDropDown(anchor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,30 +33,8 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
position: Int
|
||||
) {
|
||||
val item = items.get(position)
|
||||
holder.type.text = context.getString(
|
||||
when (item.type) {
|
||||
LunaEvent.TYPE_BABY_BOTTLE -> 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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user