forked from penguin86/luna-tracker
Compare commits
2 Commits
19774016e1
...
f8f5d68bb6
| Author | SHA1 | Date | |
|---|---|---|---|
| f8f5d68bb6 | |||
| 280d4558ad |
@@ -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 }.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) {
|
||||||
@@ -612,7 +612,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
updateContent(event)
|
updateContent(event)
|
||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
val notes = notesET.text.toString()
|
val notes = notesET.text.toString().trim()
|
||||||
|
|
||||||
if (useQuantity) {
|
if (useQuantity) {
|
||||||
val quantity = qtyET.text.toString().toIntOrNull()
|
val quantity = qtyET.text.toString().toIntOrNull()
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -132,7 +132,8 @@
|
|||||||
<string name="row_luna_event_time">Time</string>
|
<string name="row_luna_event_time">Time</string>
|
||||||
|
|
||||||
<string name="dialog_event_detail_title">Event detail</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_delete_button">Delete</string>
|
||||||
<string name="dialog_event_detail_quantity">Quantity</string>
|
<string name="dialog_event_detail_quantity">Quantity</string>
|
||||||
<string name="dialog_event_detail_notes">Notes</string>
|
<string name="dialog_event_detail_notes">Notes</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user