forked from penguin86/luna-tracker
Compare commits
2 Commits
143713cd9b
...
016dbf330b
| Author | SHA1 | Date | |
|---|---|---|---|
| 016dbf330b | |||
| 9b0b489f99 |
@@ -447,8 +447,8 @@ class MainActivity : AppCompatActivity() {
|
||||
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
||||
|
||||
// in seconds
|
||||
var sleepStart = event.getStartTime()
|
||||
var sleepEnd = event.getEndTime()
|
||||
var sleepBegin = event.time
|
||||
var sleepEnd = event.time + event.quantity
|
||||
|
||||
fun isValidTime(timeUnix: Long): Boolean {
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
@@ -465,31 +465,27 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun updateFields() {
|
||||
datePickerBegin.text = DateUtils.formatDateTime(sleepStart)
|
||||
datePickerBegin.text = DateUtils.formatDateTime(sleepBegin)
|
||||
datePickerEnd.text = DateUtils.formatDateTime(sleepEnd)
|
||||
|
||||
durationTextView.setTextColor(currentDurationTextColor)
|
||||
val duration = sleepEnd - sleepStart
|
||||
val duration = sleepEnd - sleepBegin
|
||||
if (duration == 0L) {
|
||||
// baby is sleeping
|
||||
durationTextView.text = "💤"
|
||||
dateDelimiter.visibility = View.GONE
|
||||
datePickerEnd.visibility = View.GONE
|
||||
} else {
|
||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
||||
if (!isValidTimeSpan(sleepStart, sleepEnd)) {
|
||||
if (!isValidTimeSpan(sleepBegin, sleepEnd)) {
|
||||
durationTextView.setTextColor(invalidDurationTextColor)
|
||||
}
|
||||
dateDelimiter.visibility = View.VISIBLE
|
||||
datePickerEnd.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
datePickerBegin.setTextColor(if (isValidTime(sleepStart)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
datePickerBegin.setTextColor(if (isValidTime(sleepBegin)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
datePickerEnd.setTextColor(if (isValidTime(sleepEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
}
|
||||
|
||||
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { time: Long ->
|
||||
sleepStart = adjustToMinute(time)
|
||||
sleepBegin = adjustToMinute(time)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
@@ -498,7 +494,7 @@ class MainActivity : AppCompatActivity() {
|
||||
updateFields()
|
||||
}
|
||||
|
||||
sleepStart = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
||||
sleepBegin = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
||||
sleepEnd = adjustToMinute(pickedDateTimeEnd.time.time / 1000)
|
||||
|
||||
updateFields()
|
||||
@@ -518,17 +514,17 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
durationMinus5Button.setOnClickListener {
|
||||
sleepEnd = (sleepEnd - 300).coerceAtLeast(sleepStart)
|
||||
sleepEnd = (sleepEnd - 300).coerceAtLeast(sleepBegin)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationPlus5Button.setOnClickListener {
|
||||
sleepEnd = (sleepEnd + 300).coerceAtLeast(sleepStart)
|
||||
sleepEnd = (sleepEnd + 300).coerceAtLeast(sleepBegin)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationAsleepButton.setOnClickListener {
|
||||
sleepEnd = sleepStart
|
||||
sleepEnd = sleepBegin
|
||||
updateFields()
|
||||
}
|
||||
|
||||
@@ -539,9 +535,9 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||
if (isValidTime(sleepStart) && isValidTime(sleepEnd) && isValidTimeSpan(sleepStart, sleepEnd)) {
|
||||
event.time = sleepStart
|
||||
event.quantity = (sleepEnd - sleepStart).toInt()
|
||||
if (isValidTime(sleepBegin) && isValidTime(sleepEnd) && isValidTimeSpan(sleepBegin, sleepEnd)) {
|
||||
event.time = sleepBegin
|
||||
event.quantity = (sleepEnd - sleepBegin).toInt()
|
||||
onPositive()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
||||
|
||||
Reference in New Issue
Block a user