forked from penguin86/luna-tracker
event: add support for height
This commit is contained in:
@@ -344,6 +344,53 @@ class MainActivity : AppCompatActivity() {
|
|||||||
alertDialog.show()
|
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) {
|
fun addTemperatureEvent(event: LunaEvent) {
|
||||||
setToPreviousQuantity(event)
|
setToPreviousQuantity(event)
|
||||||
askTemperatureValue(event, true) { saveEvent(event) }
|
askTemperatureValue(event, true) { saveEvent(event) }
|
||||||
@@ -868,6 +915,7 @@ 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.HEIGHT -> askHeightValue(event, false, updateValues)
|
||||||
LunaEvent.Type.DIAPERCHANGE_POO,
|
LunaEvent.Type.DIAPERCHANGE_POO,
|
||||||
LunaEvent.Type.DIAPERCHANGE_PEE,
|
LunaEvent.Type.DIAPERCHANGE_PEE,
|
||||||
LunaEvent.Type.PUKE -> askAmountValue(event, false, updateValues)
|
LunaEvent.Type.PUKE -> askAmountValue(event, false, updateValues)
|
||||||
@@ -1289,6 +1337,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
when (type) {
|
when (type) {
|
||||||
LunaEvent.Type.BABY_BOTTLE -> addBabyBottleEvent(event)
|
LunaEvent.Type.BABY_BOTTLE -> addBabyBottleEvent(event)
|
||||||
LunaEvent.Type.WEIGHT -> addWeightEvent(event)
|
LunaEvent.Type.WEIGHT -> addWeightEvent(event)
|
||||||
|
LunaEvent.Type.HEIGHT -> addHeightEvent(event)
|
||||||
LunaEvent.Type.BREASTFEEDING_LEFT_NIPPLE -> addPlainEvent(event)
|
LunaEvent.Type.BREASTFEEDING_LEFT_NIPPLE -> addPlainEvent(event)
|
||||||
LunaEvent.Type.BREASTFEEDING_BOTH_NIPPLE -> addPlainEvent(event)
|
LunaEvent.Type.BREASTFEEDING_BOTH_NIPPLE -> addPlainEvent(event)
|
||||||
LunaEvent.Type.BREASTFEEDING_RIGHT_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 the event is weight, show difference with the last one
|
||||||
if (item.type == LunaEvent.Type.WEIGHT) {
|
if (item.type == LunaEvent.Type.WEIGHT) {
|
||||||
val lastWeight = getPreviousWeightEvent(position)
|
val lastWeight = getPreviousEvent(position, LunaEvent.Type.WEIGHT)
|
||||||
if (lastWeight != null) {
|
if (lastWeight != null) {
|
||||||
val differenceInWeight = item.quantity - lastWeight.quantity
|
val differenceInWeight = item.quantity - lastWeight.quantity
|
||||||
val sign = if (differenceInWeight > 0) "+" else ""
|
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
|
holder.quantity.text = quantityText
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
@@ -88,12 +101,12 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
|||||||
return items.size
|
return items.size
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPreviousWeightEvent(startFromPosition: Int): LunaEvent? {
|
private fun getPreviousEvent(startFromPosition: Int, type: LunaEvent.Type): LunaEvent? {
|
||||||
if (startFromPosition == items.size - 1)
|
if (startFromPosition == items.size - 1)
|
||||||
return null
|
return null
|
||||||
for (pos in startFromPosition + 1 until items.size) {
|
for (pos in startFromPosition + 1 until items.size) {
|
||||||
val item = items.get(pos)
|
val item = items.get(pos)
|
||||||
if (item.type != LunaEvent.Type.WEIGHT)
|
if (item.type != type)
|
||||||
continue
|
continue
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
DIAPERCHANGE_PEE,
|
DIAPERCHANGE_PEE,
|
||||||
SLEEP,
|
SLEEP,
|
||||||
WEIGHT,
|
WEIGHT,
|
||||||
|
HEIGHT,
|
||||||
MEDICINE,
|
MEDICINE,
|
||||||
ENEMA,
|
ENEMA,
|
||||||
NOTE,
|
NOTE,
|
||||||
@@ -145,6 +146,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
when (type) {
|
when (type) {
|
||||||
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
||||||
Type.WEIGHT -> R.string.event_weight_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_LEFT_NIPPLE -> R.string.event_breastfeeding_left_type
|
||||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_type
|
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_type
|
||||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_type
|
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_type
|
||||||
@@ -174,6 +176,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
Type.DIAPERCHANGE_PEE,
|
Type.DIAPERCHANGE_PEE,
|
||||||
Type.PUKE -> R.string.log_amount_dialog_description
|
Type.PUKE -> R.string.log_amount_dialog_description
|
||||||
Type.WEIGHT -> R.string.log_weight_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
|
Type.SLEEP -> R.string.log_duration_dialog_description
|
||||||
else -> R.string.log_unknown_dialog_description
|
else -> R.string.log_unknown_dialog_description
|
||||||
}
|
}
|
||||||
@@ -185,6 +188,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
when (type) {
|
when (type) {
|
||||||
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
||||||
Type.WEIGHT -> R.string.event_weight_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_LEFT_NIPPLE -> R.string.event_breastfeeding_left_desc
|
||||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_desc
|
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_desc
|
||||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_desc
|
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_desc
|
||||||
@@ -210,6 +214,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
when (type) {
|
when (type) {
|
||||||
Type.BABY_BOTTLE -> R.string.event_type_item_bottle
|
Type.BABY_BOTTLE -> R.string.event_type_item_bottle
|
||||||
Type.WEIGHT -> R.string.event_type_item_weight
|
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_LEFT_NIPPLE -> R.string.event_type_item_breastfeeding_left
|
||||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_type_item_breastfeeding_both
|
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_type_item_breastfeeding_both
|
||||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_type_item_breastfeeding_right
|
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_type_item_breastfeeding_right
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class NumericUtils (val context: Context) {
|
|||||||
val measurement_unit_liquid_base: String
|
val measurement_unit_liquid_base: String
|
||||||
val measurement_unit_weight_base: String
|
val measurement_unit_weight_base: String
|
||||||
val measurement_unit_weight_tiny: String
|
val measurement_unit_weight_tiny: String
|
||||||
|
val measurement_unit_height_base: String
|
||||||
val measurement_unit_temperature_base: String
|
val measurement_unit_temperature_base: String
|
||||||
|
|
||||||
private fun isMetricSystem(): Boolean {
|
private fun isMetricSystem(): Boolean {
|
||||||
@@ -52,6 +53,12 @@ class NumericUtils (val context: Context) {
|
|||||||
else
|
else
|
||||||
R.string.measurement_unit_weight_tiny_imperial
|
R.string.measurement_unit_weight_tiny_imperial
|
||||||
)
|
)
|
||||||
|
this.measurement_unit_height_base = context.getString(
|
||||||
|
if (isMetricSystem())
|
||||||
|
R.string.measurement_unit_height_base_metric
|
||||||
|
else
|
||||||
|
R.string.measurement_unit_height_base_imperial
|
||||||
|
)
|
||||||
this.measurement_unit_temperature_base = context.getString(
|
this.measurement_unit_temperature_base = context.getString(
|
||||||
if (isMetricSystem())
|
if (isMetricSystem())
|
||||||
R.string.measurement_unit_temperature_base_metric
|
R.string.measurement_unit_temperature_base_metric
|
||||||
@@ -88,6 +95,7 @@ class NumericUtils (val context: Context) {
|
|||||||
when (type) {
|
when (type) {
|
||||||
LunaEvent.Type.BABY_BOTTLE -> measurement_unit_liquid_base
|
LunaEvent.Type.BABY_BOTTLE -> measurement_unit_liquid_base
|
||||||
LunaEvent.Type.WEIGHT -> measurement_unit_weight_base
|
LunaEvent.Type.WEIGHT -> measurement_unit_weight_base
|
||||||
|
LunaEvent.Type.HEIGHT -> measurement_unit_height_base
|
||||||
LunaEvent.Type.MEDICINE -> measurement_unit_weight_tiny
|
LunaEvent.Type.MEDICINE -> measurement_unit_weight_tiny
|
||||||
LunaEvent.Type.TEMPERATURE -> measurement_unit_temperature_base
|
LunaEvent.Type.TEMPERATURE -> measurement_unit_temperature_base
|
||||||
else -> ""
|
else -> ""
|
||||||
|
|||||||
39
app/src/main/res/layout/dialog_edit_height.xml
Normal file
39
app/src/main/res/layout/dialog_edit_height.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?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:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/dialog_number_edittext"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="number"
|
||||||
|
android:hint="0"
|
||||||
|
android:background="@drawable/textview_background"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dialog_number_unit"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:text="cm"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dialog_date_picker"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="20dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
<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>
|
||||||
|
<string name="event_height_type" translatable="false">📏</string>
|
||||||
<string name="event_breastfeeding_left_type" translatable="false">🤱⬅️</string>
|
<string name="event_breastfeeding_left_type" translatable="false">🤱⬅️</string>
|
||||||
<string name="event_breastfeeding_both_type" translatable="false">🤱↔️</string>
|
<string name="event_breastfeeding_both_type" translatable="false">🤱↔️</string>
|
||||||
<string name="event_breastfeeding_right_type" translatable="false">🤱➡️️</string>
|
<string name="event_breastfeeding_right_type" translatable="false">🤱➡️️</string>
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
<string name="event_type_item_bottle">🍼 Bottle</string>
|
<string name="event_type_item_bottle">🍼 Bottle</string>
|
||||||
<string name="event_type_item_food">🥣 Food</string>
|
<string name="event_type_item_food">🥣 Food</string>
|
||||||
<string name="event_type_item_weight">⚖️ Weight</string>
|
<string name="event_type_item_weight">⚖️ Weight</string>
|
||||||
|
<string name="event_type_item_height">📏 Height</string>
|
||||||
<string name="event_type_item_breastfeeding_left">🤱⬅️ Nursing</string>
|
<string name="event_type_item_breastfeeding_left">🤱⬅️ Nursing</string>
|
||||||
<string name="event_type_item_breastfeeding_both">🤱↔️ Nursing</string>
|
<string name="event_type_item_breastfeeding_both">🤱↔️ Nursing</string>
|
||||||
<string name="event_type_item_breastfeeding_right">🤱➡️️ Nursing</string>
|
<string name="event_type_item_breastfeeding_right">🤱➡️️ Nursing</string>
|
||||||
@@ -45,6 +47,7 @@
|
|||||||
<string name="event_bottle_desc">Milk Bottle</string>
|
<string name="event_bottle_desc">Milk Bottle</string>
|
||||||
<string name="event_food_desc">Food</string>
|
<string name="event_food_desc">Food</string>
|
||||||
<string name="event_weight_desc">Weight</string>
|
<string name="event_weight_desc">Weight</string>
|
||||||
|
<string name="event_height_desc">Height</string>
|
||||||
<string name="event_breastfeeding_left_desc">Nursing (left)</string>
|
<string name="event_breastfeeding_left_desc">Nursing (left)</string>
|
||||||
<string name="event_breastfeeding_both_desc">Nursing (both)</string>
|
<string name="event_breastfeeding_both_desc">Nursing (both)</string>
|
||||||
<string name="event_breastfeeding_right_desc">Nursing (right)</string>
|
<string name="event_breastfeeding_right_desc">Nursing (right)</string>
|
||||||
@@ -130,14 +133,17 @@
|
|||||||
<string name="log_temperature_dialog_description">Select the temperature:</string>
|
<string name="log_temperature_dialog_description">Select the temperature:</string>
|
||||||
<string name="log_unknown_dialog_description"></string>
|
<string name="log_unknown_dialog_description"></string>
|
||||||
<string name="log_weight_dialog_description">Insert the weight:</string>
|
<string name="log_weight_dialog_description">Insert the weight:</string>
|
||||||
|
<string name="log_height_dialog_description">Insert the height:</string>
|
||||||
<string name="log_duration_dialog_description">Set duration:</string>
|
<string name="log_duration_dialog_description">Set duration:</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>
|
||||||
<string name="measurement_unit_weight_tiny_metric" translatable="false">mg</string>
|
<string name="measurement_unit_weight_tiny_metric" translatable="false">mg</string>
|
||||||
|
<string name="measurement_unit_height_base_metric" translatable="false">cm</string>
|
||||||
<string name="measurement_unit_liquid_base_imperial" translatable="false">fl oz.</string>
|
<string name="measurement_unit_liquid_base_imperial" translatable="false">fl oz.</string>
|
||||||
<string name="measurement_unit_weight_base_imperial" translatable="false">oz</string>
|
<string name="measurement_unit_weight_base_imperial" translatable="false">oz</string>
|
||||||
<string name="measurement_unit_weight_tiny_imperial" translatable="false">gr</string>
|
<string name="measurement_unit_weight_tiny_imperial" translatable="false">gr</string>
|
||||||
|
<string name="measurement_unit_height_base_imperial" translatable="false">in</string>
|
||||||
<string name="measurement_unit_temperature_base_imperial" translatable="false">°F</string>
|
<string name="measurement_unit_temperature_base_imperial" translatable="false">°F</string>
|
||||||
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user