Compare commits
1 Commits
ff48d1af59
...
43f0519487
| Author | SHA1 | Date | |
|---|---|---|---|
| 43f0519487 |
@@ -434,27 +434,22 @@ class MainActivity : AppCompatActivity() {
|
||||
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
||||
val datePickerBegin = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
|
||||
val datePickerEnd = dialogView.findViewById<TextView>(R.id.dialog_date_picker_end)
|
||||
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 durationMinus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_minus5)
|
||||
val durationPlus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_plus5)
|
||||
|
||||
val currentDurationTextColor = durationTextView.currentTextColor
|
||||
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
||||
|
||||
// in seconds
|
||||
var sleepBegin = event.time
|
||||
var sleepStart = event.time
|
||||
var sleepEnd = event.time + event.quantity
|
||||
|
||||
fun isValidTime(timeUnix: Long): Boolean {
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
return timeUnix in 1..now
|
||||
}
|
||||
|
||||
fun isValidTimeSpan(timeBeginUnix: Long, timeEndUnix: Long): Boolean {
|
||||
return (timeBeginUnix <= timeEndUnix) && (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
return (timeBeginUnix > 0)
|
||||
&& (timeEndUnix > 0)
|
||||
&& (timeBeginUnix <= timeEndUnix)
|
||||
&& (timeBeginUnix <= now)
|
||||
&& (timeEndUnix <= now)
|
||||
&& (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
||||
}
|
||||
|
||||
// prevent printing of seconds
|
||||
@@ -462,80 +457,47 @@ class MainActivity : AppCompatActivity() {
|
||||
return unixTime - (unixTime % 60)
|
||||
}
|
||||
|
||||
fun udpateFields() {
|
||||
datePickerBegin.text = DateUtils.formatDateTime(sleepBegin)
|
||||
datePickerEnd.text = DateUtils.formatDateTime(sleepEnd)
|
||||
|
||||
fun updateDuration() {
|
||||
durationTextView.setTextColor(currentDurationTextColor)
|
||||
val duration = sleepEnd - sleepBegin
|
||||
val duration = sleepEnd - sleepStart
|
||||
if (duration == 0L) {
|
||||
// baby is sleeping
|
||||
durationTextView.text = "💤"
|
||||
} else {
|
||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
||||
if (!isValidTimeSpan(sleepBegin, sleepEnd)) {
|
||||
if (!isValidTimeSpan(sleepStart, sleepEnd)) {
|
||||
durationTextView.setTextColor(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 ->
|
||||
sleepBegin = adjustToMinute(time)
|
||||
udpateFields()
|
||||
sleepStart = adjustToMinute(time)
|
||||
updateDuration()
|
||||
}
|
||||
|
||||
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { time: Long ->
|
||||
sleepEnd = adjustToMinute(time)
|
||||
udpateFields()
|
||||
updateDuration()
|
||||
}
|
||||
|
||||
sleepBegin = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
||||
sleepStart = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
||||
sleepEnd = adjustToMinute(pickedDateTimeEnd.time.time / 1000)
|
||||
|
||||
udpateFields()
|
||||
updateDuration()
|
||||
|
||||
if (showTime) {
|
||||
dateDelimiter.visibility = View.GONE
|
||||
datePickerEnd.visibility = View.GONE
|
||||
durationTextView.visibility = View.GONE
|
||||
durationButtons.visibility = View.GONE
|
||||
//d.setMessage("")
|
||||
} else {
|
||||
dateDelimiter.visibility = View.VISIBLE
|
||||
datePickerEnd.visibility = View.VISIBLE
|
||||
durationTextView.visibility = View.VISIBLE
|
||||
durationButtons.visibility = View.VISIBLE
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
}
|
||||
|
||||
durationMinus5Button.setOnClickListener {
|
||||
sleepEnd = (sleepEnd - 300).coerceAtLeast(sleepBegin)
|
||||
udpateFields()
|
||||
}
|
||||
|
||||
durationPlus5Button.setOnClickListener {
|
||||
sleepEnd = (sleepEnd + 300).coerceAtLeast(sleepBegin)
|
||||
udpateFields()
|
||||
}
|
||||
|
||||
durationAsleepButton.setOnClickListener {
|
||||
sleepEnd = sleepBegin
|
||||
udpateFields()
|
||||
}
|
||||
|
||||
durationNowButton.setOnClickListener {
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
sleepEnd = adjustToMinute(now)
|
||||
udpateFields()
|
||||
}
|
||||
|
||||
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 (isValidTimeSpan(sleepStart, sleepEnd)) {
|
||||
event.time = sleepStart
|
||||
event.quantity = (sleepEnd - sleepStart).toInt()
|
||||
onPositive()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
||||
|
||||
@@ -7,83 +7,26 @@
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker_begin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="10dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:textSize="20sp"
|
||||
android:text="💤"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/duration_buttons"
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker_end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_minus5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="-5 min"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_now"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_now"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_asleep"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_asleep"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_plus5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="+5 min"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker_begin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_range_delimiter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:text="-"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker_end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -160,9 +160,6 @@
|
||||
<string name="dialog_event_detail_notes">Notes</string>
|
||||
<string name="dialog_event_detail_signature">by %s</string>
|
||||
|
||||
<string name="dialog_duration_button_now">now</string>
|
||||
<string name="dialog_duration_button_asleep">asleep</string>
|
||||
|
||||
<string name="dialog_add_logbook_title">Add logbook</string>
|
||||
<string name="dialog_add_logbook_logbookname">👶 Logbook name</string>
|
||||
<string name="dialog_add_logbook_message">Write a name to identify this logbook. This name will appear on top of the screen and, if you use WebDAV, will be in the save file name as well.</string>
|
||||
|
||||
Reference in New Issue
Block a user