MainActivity: preset quantity of bottle, weight and temperature
Use the quantity of previous events to initialize new events.
This commit is contained in:
@@ -85,7 +85,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
showAddLogbookDialog(true)
|
showAddLogbookDialog(true)
|
||||||
}
|
}
|
||||||
findViewById<View>(R.id.button_bottle).setOnClickListener {
|
findViewById<View>(R.id.button_bottle).setOnClickListener {
|
||||||
addBabyBottleEvent()
|
addBabyBottleEvent(LunaEvent(LunaEvent.TYPE_BABY_BOTTLE))
|
||||||
}
|
}
|
||||||
findViewById<View>(R.id.button_food).setOnClickListener {
|
findViewById<View>(R.id.button_food).setOnClickListener {
|
||||||
addNoteEvent(LunaEvent(LunaEvent.TYPE_FOOD))
|
addNoteEvent(LunaEvent(LunaEvent.TYPE_FOOD))
|
||||||
@@ -195,8 +195,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return logbook?.logs ?: arrayListOf()
|
return logbook?.logs ?: arrayListOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addBabyBottleEvent() {
|
fun addBabyBottleEvent(event: LunaEvent) {
|
||||||
val event = LunaEvent(LunaEvent.TYPE_BABY_BOTTLE)
|
setToPreviousQuantity(event)
|
||||||
askBabyBottleContent(event, true) {
|
askBabyBottleContent(event, true) {
|
||||||
saveEvent(event)
|
saveEvent(event)
|
||||||
}
|
}
|
||||||
@@ -239,6 +239,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addWeightEvent(event: LunaEvent) {
|
fun addWeightEvent(event: LunaEvent) {
|
||||||
|
setToPreviousQuantity(event)
|
||||||
askWeightValue(event, true) { saveEvent(event) }
|
askWeightValue(event, true) { saveEvent(event) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,6 +283,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addTemperatureEvent(event: LunaEvent) {
|
fun addTemperatureEvent(event: LunaEvent) {
|
||||||
|
setToPreviousQuantity(event)
|
||||||
askTemperatureValue(event, true) { saveEvent(event) }
|
askTemperatureValue(event, true) { saveEvent(event) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,6 +524,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setToPreviousQuantity(event: LunaEvent) {
|
||||||
|
val prev = getPreviousSameEvent(event, getAllEvents())
|
||||||
|
if (prev != null) {
|
||||||
|
event.quantity = prev.quantity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getPreviousSameEvent(event: LunaEvent, items: ArrayList<LunaEvent>): LunaEvent? {
|
fun getPreviousSameEvent(event: LunaEvent, items: ArrayList<LunaEvent>): LunaEvent? {
|
||||||
var previousEvent: LunaEvent? = null
|
var previousEvent: LunaEvent? = null
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
|
|||||||
Reference in New Issue
Block a user