event: add support for height
This commit is contained in:
@@ -344,6 +344,53 @@ class MainActivity : AppCompatActivity() {
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
fun addHeightEvent(event: LunaEvent) {
|
||||
setToPreviousQuantity(event)
|
||||
askHeightValue(event, true) { saveEvent(event) }
|
||||
}
|
||||
|
||||
fun askHeightValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
// Show number picker dialog
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_height, null)
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
val heightET = dialogView.findViewById<EditText>(R.id.dialog_number_edittext)
|
||||
heightET.setText(event.quantity.toString())
|
||||
|
||||
val unitTV = dialogView.findViewById<TextView>(R.id.dialog_number_unit)
|
||||
unitTV.text = NumericUtils(this).measurement_unit_height_base
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
}
|
||||
|
||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||
val height = heightET.text.toString().toIntOrNull()
|
||||
if (height != null) {
|
||||
event.time = pickedTime.time.time / 1000
|
||||
event.quantity = height
|
||||
onPositive()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
val alertDialog = d.create()
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
fun addTemperatureEvent(event: LunaEvent) {
|
||||
setToPreviousQuantity(event)
|
||||
askTemperatureValue(event, true) { saveEvent(event) }
|
||||
@@ -868,6 +915,7 @@ class MainActivity : AppCompatActivity() {
|
||||
when (event.type) {
|
||||
LunaEvent.Type.BABY_BOTTLE -> askBabyBottleContent(event, false, updateValues)
|
||||
LunaEvent.Type.WEIGHT -> askWeightValue(event, false, updateValues)
|
||||
LunaEvent.Type.HEIGHT -> askHeightValue(event, false, updateValues)
|
||||
LunaEvent.Type.DIAPERCHANGE_POO,
|
||||
LunaEvent.Type.DIAPERCHANGE_PEE,
|
||||
LunaEvent.Type.PUKE -> askAmountValue(event, false, updateValues)
|
||||
@@ -1289,6 +1337,7 @@ class MainActivity : AppCompatActivity() {
|
||||
when (type) {
|
||||
LunaEvent.Type.BABY_BOTTLE -> addBabyBottleEvent(event)
|
||||
LunaEvent.Type.WEIGHT -> addWeightEvent(event)
|
||||
LunaEvent.Type.HEIGHT -> addHeightEvent(event)
|
||||
LunaEvent.Type.BREASTFEEDING_LEFT_NIPPLE -> addPlainEvent(event)
|
||||
LunaEvent.Type.BREASTFEEDING_BOTH_NIPPLE -> addPlainEvent(event)
|
||||
LunaEvent.Type.BREASTFEEDING_RIGHT_NIPPLE -> addPlainEvent(event)
|
||||
|
||||
@@ -63,7 +63,7 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
|
||||
// if the event is weight, show difference with the last one
|
||||
if (item.type == LunaEvent.Type.WEIGHT) {
|
||||
val lastWeight = getPreviousWeightEvent(position)
|
||||
val lastWeight = getPreviousEvent(position, LunaEvent.Type.WEIGHT)
|
||||
if (lastWeight != null) {
|
||||
val differenceInWeight = item.quantity - lastWeight.quantity
|
||||
val sign = if (differenceInWeight > 0) "+" else ""
|
||||
@@ -74,6 +74,19 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
}
|
||||
}
|
||||
|
||||
// if the event is height, show difference with the last one
|
||||
if (item.type == LunaEvent.Type.HEIGHT) {
|
||||
val lastHeight = getPreviousEvent(position, LunaEvent.Type.HEIGHT)
|
||||
if (lastHeight != null) {
|
||||
val differenceInHeight = item.quantity - lastHeight.quantity
|
||||
val sign = if (differenceInHeight > 0) "+" else ""
|
||||
quantityText += "\n($sign$differenceInHeight)"
|
||||
if (differenceInHeight < 0) {
|
||||
holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.danger))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.quantity.text = quantityText
|
||||
|
||||
// Listeners
|
||||
@@ -88,12 +101,12 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
return items.size
|
||||
}
|
||||
|
||||
private fun getPreviousWeightEvent(startFromPosition: Int): LunaEvent? {
|
||||
private fun getPreviousEvent(startFromPosition: Int, type: LunaEvent.Type): LunaEvent? {
|
||||
if (startFromPosition == items.size - 1)
|
||||
return null
|
||||
for (pos in startFromPosition + 1 until items.size) {
|
||||
val item = items.get(pos)
|
||||
if (item.type != LunaEvent.Type.WEIGHT)
|
||||
if (item.type != type)
|
||||
continue
|
||||
return item
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
DIAPERCHANGE_PEE,
|
||||
SLEEP,
|
||||
WEIGHT,
|
||||
HEIGHT,
|
||||
MEDICINE,
|
||||
ENEMA,
|
||||
NOTE,
|
||||
@@ -145,6 +146,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
||||
Type.WEIGHT -> R.string.event_weight_type
|
||||
Type.HEIGHT -> R.string.event_height_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
|
||||
@@ -174,6 +176,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
Type.DIAPERCHANGE_PEE,
|
||||
Type.PUKE -> R.string.log_amount_dialog_description
|
||||
Type.WEIGHT -> R.string.log_weight_dialog_description
|
||||
Type.HEIGHT -> R.string.log_height_dialog_description
|
||||
Type.SLEEP -> R.string.log_duration_dialog_description
|
||||
else -> R.string.log_unknown_dialog_description
|
||||
}
|
||||
@@ -185,6 +188,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
||||
Type.WEIGHT -> R.string.event_weight_desc
|
||||
Type.HEIGHT -> R.string.event_height_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
|
||||
@@ -210,6 +214,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_type_item_bottle
|
||||
Type.WEIGHT -> R.string.event_type_item_weight
|
||||
Type.HEIGHT -> R.string.event_type_item_height
|
||||
Type.BREASTFEEDING_LEFT_NIPPLE -> R.string.event_type_item_breastfeeding_left
|
||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_type_item_breastfeeding_both
|
||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_type_item_breastfeeding_right
|
||||
|
||||
Reference in New Issue
Block a user