forked from penguin86/luna-tracker
Compare commits
3 Commits
9cce54c05e
...
11a4f12fbe
| Author | SHA1 | Date | |
|---|---|---|---|
| 11a4f12fbe | |||
| 9398e5c406 | |||
| 5a9488fdb9 |
@@ -387,9 +387,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
||||
val durationNowButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_now)
|
||||
val datePicker = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val durationMinus15Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_minus15)
|
||||
val durationMinus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_minus5)
|
||||
val durationPlus15Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_plus15)
|
||||
val durationPlus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_plus5)
|
||||
|
||||
val currentDurationTextColor = durationTextView.currentTextColor
|
||||
@@ -428,10 +426,8 @@ class MainActivity : AppCompatActivity() {
|
||||
onDateChange(pickedDateTime.time.time / 1000)
|
||||
}
|
||||
|
||||
durationMinus15Button.setOnClickListener { adjust(-15) }
|
||||
durationMinus5Button.setOnClickListener { adjust(-5) }
|
||||
durationPlus5Button.setOnClickListener { adjust(5) }
|
||||
durationPlus15Button.setOnClickListener { adjust(15) }
|
||||
|
||||
durationNowButton.setOnClickListener {
|
||||
val now = Calendar.getInstance().time.time / 1000
|
||||
@@ -704,6 +700,12 @@ class MainActivity : AppCompatActivity() {
|
||||
fun showEventDetailDialog(originalEvent: LunaEvent) {
|
||||
val event = LunaEvent(originalEvent)
|
||||
|
||||
fun eventValuesChanged(): Boolean {
|
||||
return (event.time != originalEvent.time
|
||||
|| event.quantity != originalEvent.quantity
|
||||
|| event.notes != originalEvent.notes)
|
||||
}
|
||||
|
||||
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
|
||||
pauseLogbookUpdate = true
|
||||
|
||||
@@ -721,17 +723,59 @@ class MainActivity : AppCompatActivity() {
|
||||
emojiTextView.text = event.getTypeEmoji(this)
|
||||
descriptionTextView.text = event.getTypeDescription(this)
|
||||
|
||||
d.setView(dialogView)
|
||||
|
||||
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i ->
|
||||
deleteEvent(originalEvent)
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
d.setNegativeButton(R.string.dialog_event_detail_save_button) { dialogInterface, i ->
|
||||
if (eventValuesChanged()) {
|
||||
originalEvent.time = event.time
|
||||
originalEvent.quantity = event.quantity
|
||||
originalEvent.notes = event.notes
|
||||
saveEvent(originalEvent)
|
||||
}
|
||||
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i ->
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
val alertDialog = d.create()
|
||||
alertDialog.show()
|
||||
|
||||
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(
|
||||
ContextCompat.getColor(this, R.color.danger)
|
||||
)
|
||||
|
||||
alertDialog.setOnDismissListener {
|
||||
// Resume logbook update
|
||||
pauseLogbookUpdate = false
|
||||
}
|
||||
|
||||
val updateValues = {
|
||||
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
|
||||
notesTextView.text = event.notes
|
||||
if (event.type == LunaEvent.TYPE_SLEEP) {
|
||||
if (event.type == LunaEvent.TYPE_SLEEP && event.quantity > 0) {
|
||||
dateEndTextView.text = DateUtils.formatDateTime(event.time + event.quantity)
|
||||
dateEndTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
dateEndTextView.visibility = View.GONE
|
||||
}
|
||||
|
||||
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).visibility = if (eventValuesChanged()) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
updateValues()
|
||||
|
||||
val pickedTime = datePickerHelper(event.time, dateTextView, { newTime: Long ->
|
||||
datePickerHelper(event.time, dateTextView, { newTime: Long ->
|
||||
event.time = newTime
|
||||
updateValues()
|
||||
})
|
||||
@@ -757,40 +801,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
d.setView(dialogView)
|
||||
|
||||
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i ->
|
||||
deleteEvent(originalEvent)
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i ->
|
||||
event.time = pickedTime.time.time / 1000
|
||||
|
||||
if (event.time != originalEvent.time
|
||||
|| event.quantity != originalEvent.quantity
|
||||
|| event.notes != originalEvent.notes) {
|
||||
originalEvent.time = event.time
|
||||
originalEvent.quantity = event.quantity
|
||||
originalEvent.notes = event.notes
|
||||
saveEvent(originalEvent)
|
||||
}
|
||||
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
val alertDialog = d.create()
|
||||
alertDialog.show()
|
||||
|
||||
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(
|
||||
ContextCompat.getColor(this, R.color.danger)
|
||||
)
|
||||
|
||||
alertDialog.setOnDismissListener {
|
||||
// Resume logbook update
|
||||
pauseLogbookUpdate = false
|
||||
}
|
||||
|
||||
// show optional signature
|
||||
if (event.signature.isNotEmpty()) {
|
||||
val signatureTextEdit = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_signature)
|
||||
|
||||
@@ -22,13 +22,6 @@
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_minus15"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="-15"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_minus5"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -50,13 +43,6 @@
|
||||
android:layout_weight="1"
|
||||
android:text="+5"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_plus15"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="+15"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -132,7 +132,8 @@
|
||||
<string name="row_luna_event_time">Time</string>
|
||||
|
||||
<string name="dialog_event_detail_title">Event detail</string>
|
||||
<string name="dialog_event_detail_close_button">OK</string>
|
||||
<string name="dialog_event_detail_close_button">Close</string>
|
||||
<string name="dialog_event_detail_save_button">Save</string>
|
||||
<string name="dialog_event_detail_delete_button">Delete</string>
|
||||
<string name="dialog_event_detail_quantity">Quantity</string>
|
||||
<string name="dialog_event_detail_notes">Notes</string>
|
||||
|
||||
Reference in New Issue
Block a user