|
|
|
@@ -557,11 +557,11 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
|
|
val nextTextView = dialogView.findViewById<TextView>(R.id.notes_template_next)
|
|
|
|
val nextTextView = dialogView.findViewById<TextView>(R.id.notes_template_next)
|
|
|
|
val prevTextView = dialogView.findViewById<TextView>(R.id.notes_template_prev)
|
|
|
|
val prevTextView = dialogView.findViewById<TextView>(R.id.notes_template_prev)
|
|
|
|
|
|
|
|
val templates = getAllEvents().filter { it.type == event.type }.distinctBy { it.notes.trim() }.sortedBy { it.time }
|
|
|
|
|
|
|
|
|
|
|
|
fun updateContent(current: LunaEvent) {
|
|
|
|
fun updateContent(current: LunaEvent) {
|
|
|
|
val allEvents = getAllEvents()
|
|
|
|
val prevEvent = getPreviousSameEvent(current, templates)
|
|
|
|
val prevEvent = getPreviousSameEvent(current, allEvents)
|
|
|
|
var nextEvent = getNextSameEvent(current, templates)
|
|
|
|
var nextEvent = getNextSameEvent(current, allEvents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notesET.setText(current.notes)
|
|
|
|
notesET.setText(current.notes)
|
|
|
|
if (useQuantity) {
|
|
|
|
if (useQuantity) {
|
|
|
|
@@ -669,7 +669,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun getPreviousSameEvent(event: LunaEvent, items: ArrayList<LunaEvent>): LunaEvent? {
|
|
|
|
fun getPreviousSameEvent(event: LunaEvent, items: List<LunaEvent>): LunaEvent? {
|
|
|
|
var previousEvent: LunaEvent? = null
|
|
|
|
var previousEvent: LunaEvent? = null
|
|
|
|
for (item in items) {
|
|
|
|
for (item in items) {
|
|
|
|
if (item.type == event.type && item.time < event.time) {
|
|
|
|
if (item.type == event.type && item.time < event.time) {
|
|
|
|
@@ -683,7 +683,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
return previousEvent
|
|
|
|
return previousEvent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun getNextSameEvent(event: LunaEvent, items: ArrayList<LunaEvent>): LunaEvent? {
|
|
|
|
fun getNextSameEvent(event: LunaEvent, items: List<LunaEvent>): LunaEvent? {
|
|
|
|
var nextEvent: LunaEvent? = null
|
|
|
|
var nextEvent: LunaEvent? = null
|
|
|
|
for (item in items) {
|
|
|
|
for (item in items) {
|
|
|
|
if (item.type == event.type && item.time > event.time) {
|
|
|
|
if (item.type == event.type && item.time > event.time) {
|
|
|
|
@@ -700,6 +700,12 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
fun showEventDetailDialog(originalEvent: LunaEvent) {
|
|
|
|
fun showEventDetailDialog(originalEvent: LunaEvent) {
|
|
|
|
val event = LunaEvent(originalEvent)
|
|
|
|
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
|
|
|
|
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
|
|
|
|
pauseLogbookUpdate = true
|
|
|
|
pauseLogbookUpdate = true
|
|
|
|
|
|
|
|
|
|
|
|
@@ -717,6 +723,40 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
emojiTextView.text = event.getTypeEmoji(this)
|
|
|
|
emojiTextView.text = event.getTypeEmoji(this)
|
|
|
|
descriptionTextView.text = event.getTypeDescription(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 = {
|
|
|
|
val updateValues = {
|
|
|
|
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
|
|
|
|
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
|
|
|
|
notesTextView.text = event.notes
|
|
|
|
notesTextView.text = event.notes
|
|
|
|
@@ -726,10 +766,16 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
dateEndTextView.visibility = View.GONE
|
|
|
|
dateEndTextView.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).visibility = if (eventValuesChanged()) {
|
|
|
|
|
|
|
|
View.VISIBLE
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
View.GONE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateValues()
|
|
|
|
updateValues()
|
|
|
|
|
|
|
|
|
|
|
|
val pickedTime = datePickerHelper(event.time, dateTextView, { newTime: Long ->
|
|
|
|
datePickerHelper(event.time, dateTextView, { newTime: Long ->
|
|
|
|
event.time = newTime
|
|
|
|
event.time = newTime
|
|
|
|
updateValues()
|
|
|
|
updateValues()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@@ -755,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
|
|
|
|
// show optional signature
|
|
|
|
if (event.signature.isNotEmpty()) {
|
|
|
|
if (event.signature.isNotEmpty()) {
|
|
|
|
val signatureTextEdit = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_signature)
|
|
|
|
val signatureTextEdit = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_signature)
|
|
|
|
|