|
|
|
|
@@ -162,60 +162,55 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
|
|
|
|
).filter { it != LunaEvent.Type.UNKNOWN }
|
|
|
|
|
|
|
|
|
|
fun setupMenu(maxButtonCount: Int, sortedEventTypes: List<LunaEvent.Type>): Int {
|
|
|
|
|
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
|
|
|
|
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
|
|
|
|
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
|
|
|
|
|
|
|
|
|
val row2 = findViewById<View>(R.id.linear_layout_row2)
|
|
|
|
|
val row2Button1 = findViewById<TextView>(R.id.button1_row2)
|
|
|
|
|
val row2Button2 = findViewById<TextView>(R.id.button2_row2)
|
|
|
|
|
val row2Button3 = findViewById<TextView>(R.id.button3_row2)
|
|
|
|
|
|
|
|
|
|
val row3 = findViewById<View>(R.id.linear_layout_row3)
|
|
|
|
|
val row3Button1 = findViewById<TextView>(R.id.button1_row3)
|
|
|
|
|
val row3Button2 = findViewById<TextView>(R.id.button2_row3)
|
|
|
|
|
|
|
|
|
|
// hide all rows/buttons (except row 3)
|
|
|
|
|
for (view in listOf(row1, row1Button1, row1Button2,
|
|
|
|
|
row2, row2Button1, row2Button2, row2Button3,
|
|
|
|
|
row3, row3Button1, row3Button2)) {
|
|
|
|
|
view.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
row3.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
|
|
var showCounter = 0
|
|
|
|
|
|
|
|
|
|
fun show(vararg tvs: TextView) {
|
|
|
|
|
for (tv in tvs) {
|
|
|
|
|
val type = sortedEventTypes[showCounter]
|
|
|
|
|
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
|
|
|
|
tv.setOnClickListener { showCreateDialog(type) }
|
|
|
|
|
tv.visibility = View.VISIBLE
|
|
|
|
|
// show parent row
|
|
|
|
|
(tv.parent as View).visibility = View.VISIBLE
|
|
|
|
|
showCounter += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when (maxButtonCount) {
|
|
|
|
|
0 -> { } // ignore - show empty row3
|
|
|
|
|
1 -> show(row3Button1)
|
|
|
|
|
2 -> show(row3Button1, row3Button2)
|
|
|
|
|
3 -> show(row1Button1, row3Button1)
|
|
|
|
|
4, 5, 6 -> show(row1Button1, row1Button2, row3Button1, row3Button2)
|
|
|
|
|
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, row3Button1, row3Button2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return showCounter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val usedEventCount = eventTypeStats.count { it.value > 0 }
|
|
|
|
|
val maxButtonCount = if (dynamicMenu) { usedEventCount } else { 7 }
|
|
|
|
|
val eventsShown = setupMenu(maxButtonCount, eventTypesSorted)
|
|
|
|
|
|
|
|
|
|
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
|
|
|
|
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
|
|
|
|
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
|
|
|
|
|
|
|
|
|
val row2 = findViewById<View>(R.id.linear_layout_row2)
|
|
|
|
|
val row2Button1 = findViewById<TextView>(R.id.button1_row2)
|
|
|
|
|
val row2Button2 = findViewById<TextView>(R.id.button2_row2)
|
|
|
|
|
val row2Button3 = findViewById<TextView>(R.id.button3_row2)
|
|
|
|
|
|
|
|
|
|
val row3 = findViewById<View>(R.id.linear_layout_row3)
|
|
|
|
|
val row3Button1 = findViewById<TextView>(R.id.button1_row3)
|
|
|
|
|
val row3Button2 = findViewById<TextView>(R.id.button2_row3)
|
|
|
|
|
|
|
|
|
|
// hide all rows/buttons (except row 3)
|
|
|
|
|
for (view in listOf(row1, row1Button1, row1Button2,
|
|
|
|
|
row2, row2Button1, row2Button2, row2Button3,
|
|
|
|
|
row3, row3Button1, row3Button2)) {
|
|
|
|
|
view.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
row3.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
|
|
var showCounter = 0
|
|
|
|
|
|
|
|
|
|
fun show(vararg tvs: TextView) {
|
|
|
|
|
for (tv in tvs) {
|
|
|
|
|
val type = eventTypesSorted[showCounter]
|
|
|
|
|
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
|
|
|
|
tv.setOnClickListener { showCreateDialog(type) }
|
|
|
|
|
tv.visibility = View.VISIBLE
|
|
|
|
|
// show parent row
|
|
|
|
|
(tv.parent as View).visibility = View.VISIBLE
|
|
|
|
|
showCounter += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when (maxButtonCount) {
|
|
|
|
|
0 -> { } // ignore - show empty row3
|
|
|
|
|
1 -> show(row3Button1)
|
|
|
|
|
2 -> show(row3Button1, row3Button2)
|
|
|
|
|
3 -> show(row1Button1, row3Button1)
|
|
|
|
|
4, 5, 6 -> show(row1Button1, row1Button2, row3Button1, row3Button2)
|
|
|
|
|
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, row3Button1, row3Button2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// store left over events for popup menu
|
|
|
|
|
currentPopupItems = eventTypesSorted.subList(eventsShown, eventTypesSorted.size)
|
|
|
|
|
currentPopupItems = eventTypesSorted.subList(showCounter, eventTypesSorted.size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onStart() {
|
|
|
|
|
@@ -277,6 +272,9 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
numberPicker.wrapSelectorWheel = false
|
|
|
|
|
numberPicker.value = event.quantity / 10
|
|
|
|
|
|
|
|
|
|
val numberPickerUnit = dialogView.findViewById<TextView>(R.id.dialog_number_picker_unit)
|
|
|
|
|
numberPickerUnit.text = NumericUtils(this).measurement_unit_liquid_base
|
|
|
|
|
|
|
|
|
|
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
|
|
|
val pickedTime = dateTimePicker(event.time, dateTV)
|
|
|
|
|
|
|
|
|
|
@@ -423,11 +421,11 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
return dateTime
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun addSleepEvent(event: LunaEvent) {
|
|
|
|
|
askSleepValue(event, true) { saveEvent(event) }
|
|
|
|
|
fun addDurationEvent(event: LunaEvent) {
|
|
|
|
|
askDurationEvent(event, true) { saveEvent(event) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun askSleepValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
|
|
|
|
fun askDurationEvent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
|
|
|
|
val d = AlertDialog.Builder(this)
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_duration, null)
|
|
|
|
|
d.setTitle(event.getDialogTitle(this))
|
|
|
|
|
@@ -439,7 +437,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
val dateDelimiter = dialogView.findViewById<TextView>(R.id.dialog_date_range_delimiter)
|
|
|
|
|
val durationButtons = dialogView.findViewById<LinearLayout>(R.id.duration_buttons)
|
|
|
|
|
val durationNowButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_now)
|
|
|
|
|
val durationAsleepButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_asleep)
|
|
|
|
|
val durationClearButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_clear)
|
|
|
|
|
val durationMinus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_minus5)
|
|
|
|
|
val durationPlus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_plus5)
|
|
|
|
|
|
|
|
|
|
@@ -447,8 +445,8 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
|
|
|
|
|
|
|
|
|
// in seconds
|
|
|
|
|
var sleepBegin = event.time
|
|
|
|
|
var sleepEnd = event.time + event.quantity
|
|
|
|
|
var durationStart = event.getStartTime()
|
|
|
|
|
var durationEnd = event.getEndTime()
|
|
|
|
|
|
|
|
|
|
fun isValidTime(timeUnix: Long): Boolean {
|
|
|
|
|
val now = System.currentTimeMillis() / 1000
|
|
|
|
|
@@ -459,46 +457,43 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
return (timeBeginUnix <= timeEndUnix) && (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prevent printing of seconds
|
|
|
|
|
fun adjustToMinute(unixTime: Long): Long {
|
|
|
|
|
return unixTime - (unixTime % 60)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun updateFields() {
|
|
|
|
|
datePickerBegin.text = DateUtils.formatDateTime(sleepBegin)
|
|
|
|
|
datePickerEnd.text = DateUtils.formatDateTime(sleepEnd)
|
|
|
|
|
datePickerBegin.text = DateUtils.formatDateTime(durationStart)
|
|
|
|
|
datePickerEnd.text = DateUtils.formatDateTime(durationEnd)
|
|
|
|
|
|
|
|
|
|
durationTextView.setTextColor(currentDurationTextColor)
|
|
|
|
|
val duration = sleepEnd - sleepBegin
|
|
|
|
|
val duration = durationEnd - durationStart
|
|
|
|
|
if (duration == 0L) {
|
|
|
|
|
// baby is sleeping
|
|
|
|
|
// event is ongoing
|
|
|
|
|
durationTextView.text = "💤"
|
|
|
|
|
dateDelimiter.visibility = View.GONE
|
|
|
|
|
datePickerEnd.visibility = View.GONE
|
|
|
|
|
} else {
|
|
|
|
|
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
|
|
|
|
if (!isValidTimeSpan(sleepBegin, sleepEnd)) {
|
|
|
|
|
if (!isValidTimeSpan(durationStart, durationEnd)) {
|
|
|
|
|
durationTextView.setTextColor(invalidDurationTextColor)
|
|
|
|
|
}
|
|
|
|
|
dateDelimiter.visibility = View.VISIBLE
|
|
|
|
|
datePickerEnd.visibility = View.VISIBLE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datePickerBegin.setTextColor(if (isValidTime(sleepBegin)) { currentDurationTextColor } else { invalidDurationTextColor })
|
|
|
|
|
datePickerEnd.setTextColor(if (isValidTime(sleepEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
|
|
|
|
|
datePickerBegin.setTextColor(if (isValidTime(durationStart)) { currentDurationTextColor } else { invalidDurationTextColor })
|
|
|
|
|
datePickerEnd.setTextColor(if (isValidTime(durationEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { time: Long ->
|
|
|
|
|
sleepBegin = adjustToMinute(time)
|
|
|
|
|
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { pickedTime: Long ->
|
|
|
|
|
durationStart = pickedTime
|
|
|
|
|
if (datePickerEnd.visibility == View.GONE) {
|
|
|
|
|
durationEnd = pickedTime
|
|
|
|
|
}
|
|
|
|
|
updateFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { time: Long ->
|
|
|
|
|
sleepEnd = adjustToMinute(time)
|
|
|
|
|
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { pickedTime: Long ->
|
|
|
|
|
durationEnd = pickedTime
|
|
|
|
|
updateFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sleepBegin = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
|
|
|
|
sleepEnd = adjustToMinute(pickedDateTimeEnd.time.time / 1000)
|
|
|
|
|
|
|
|
|
|
updateFields()
|
|
|
|
|
|
|
|
|
|
if (showTime) {
|
|
|
|
|
dateDelimiter.visibility = View.GONE
|
|
|
|
|
datePickerEnd.visibility = View.GONE
|
|
|
|
|
@@ -513,31 +508,35 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
d.setMessage(event.getDialogMessage(this))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
durationStart = pickedDateTimeBegin.time.time / 1000
|
|
|
|
|
durationEnd = pickedDateTimeEnd.time.time / 1000
|
|
|
|
|
|
|
|
|
|
updateFields()
|
|
|
|
|
|
|
|
|
|
durationMinus5Button.setOnClickListener {
|
|
|
|
|
sleepEnd = (sleepEnd - 300).coerceAtLeast(sleepBegin)
|
|
|
|
|
durationEnd = (durationEnd - 300).coerceAtLeast(durationStart)
|
|
|
|
|
updateFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
durationPlus5Button.setOnClickListener {
|
|
|
|
|
sleepEnd = (sleepEnd + 300).coerceAtLeast(sleepBegin)
|
|
|
|
|
durationEnd = (durationEnd + 300).coerceAtLeast(durationStart)
|
|
|
|
|
updateFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
durationAsleepButton.setOnClickListener {
|
|
|
|
|
sleepEnd = sleepBegin
|
|
|
|
|
durationClearButton.setOnClickListener {
|
|
|
|
|
durationEnd = durationStart
|
|
|
|
|
updateFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
durationNowButton.setOnClickListener {
|
|
|
|
|
val now = System.currentTimeMillis() / 1000
|
|
|
|
|
sleepEnd = adjustToMinute(now)
|
|
|
|
|
durationEnd = System.currentTimeMillis() / 1000
|
|
|
|
|
updateFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
|
|
|
|
if (isValidTime(sleepBegin) && isValidTime(sleepEnd) && isValidTimeSpan(sleepBegin, sleepEnd)) {
|
|
|
|
|
event.time = sleepBegin
|
|
|
|
|
event.quantity = (sleepEnd - sleepBegin).toInt()
|
|
|
|
|
if (isValidTime(durationStart) && isValidTime(durationEnd) && isValidTimeSpan(durationStart, durationEnd)) {
|
|
|
|
|
event.time = durationStart
|
|
|
|
|
event.quantity = (durationEnd - durationStart).toInt()
|
|
|
|
|
onPositive()
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
|
|
|
|
@@ -883,7 +882,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
LunaEvent.Type.PUKE -> askAmountValue(event, false, updateValues)
|
|
|
|
|
LunaEvent.Type.TEMPERATURE -> askTemperatureValue(event, false, updateValues)
|
|
|
|
|
LunaEvent.Type.NOTE -> askNotes(event, false, updateValues)
|
|
|
|
|
LunaEvent.Type.SLEEP -> askSleepValue(event, false, updateValues)
|
|
|
|
|
LunaEvent.Type.SLEEP -> askDurationEvent(event, false, updateValues)
|
|
|
|
|
else -> {
|
|
|
|
|
Log.w(TAG, "Unexpected type: ${event.type}")
|
|
|
|
|
}
|
|
|
|
|
@@ -1310,7 +1309,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
LunaEvent.Type.FOOD -> addNoteEvent(event)
|
|
|
|
|
LunaEvent.Type.PUKE -> addAmountEvent(event)
|
|
|
|
|
LunaEvent.Type.BATH -> addPlainEvent(event)
|
|
|
|
|
LunaEvent.Type.SLEEP -> addSleepEvent(event)
|
|
|
|
|
LunaEvent.Type.SLEEP -> addDurationEvent(event)
|
|
|
|
|
LunaEvent.Type.UNKNOWN -> {} // ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|