forked from penguin86/luna-tracker
MainActivity: sort events before saving
This commit is contained in:
@@ -420,17 +420,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return dateTime
|
return dateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveEvent(event: LunaEvent) {
|
|
||||||
if (!allEvents.contains(event)) {
|
|
||||||
// new event
|
|
||||||
logEvent(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
logbook?.sort()
|
|
||||||
recyclerView.adapter?.notifyDataSetChanged()
|
|
||||||
saveLogbook()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addSleepEvent(event: LunaEvent) {
|
fun addSleepEvent(event: LunaEvent) {
|
||||||
askSleepValue(event) { saveEvent(event) }
|
askSleepValue(event) { saveEvent(event) }
|
||||||
}
|
}
|
||||||
@@ -1116,23 +1105,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logEvent(event: LunaEvent) {
|
|
||||||
savingEvent(true)
|
|
||||||
|
|
||||||
event.signature = signature
|
|
||||||
|
|
||||||
setLoading(true)
|
|
||||||
logbook?.logs?.add(0, event)
|
|
||||||
recyclerView.adapter?.notifyItemInserted(0)
|
|
||||||
recyclerView.smoothScrollToPosition(0)
|
|
||||||
saveLogbook(event)
|
|
||||||
|
|
||||||
// Check logbook size to avoid OOM errors
|
|
||||||
if (logbook?.isTooBig() == true) {
|
|
||||||
askToTrimLogbook()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteEvent(event: LunaEvent) {
|
fun deleteEvent(event: LunaEvent) {
|
||||||
// Update view
|
// Update view
|
||||||
savingEvent(true)
|
savingEvent(true)
|
||||||
@@ -1144,6 +1116,32 @@ class MainActivity : AppCompatActivity() {
|
|||||||
saveLogbook()
|
saveLogbook()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveEvent(event: LunaEvent) {
|
||||||
|
if (allEvents.contains(event)) {
|
||||||
|
// event was modified
|
||||||
|
logbook?.sort()
|
||||||
|
recyclerView.adapter?.notifyDataSetChanged()
|
||||||
|
saveLogbook()
|
||||||
|
} else {
|
||||||
|
// add new event
|
||||||
|
savingEvent(true)
|
||||||
|
setLoading(true)
|
||||||
|
if (signature.isNotEmpty()) {
|
||||||
|
event.signature = signature
|
||||||
|
}
|
||||||
|
logbook?.logs?.add(0, event)
|
||||||
|
logbook?.sort()
|
||||||
|
recyclerView.adapter?.notifyItemInserted(0)
|
||||||
|
recyclerView.smoothScrollToPosition(0)
|
||||||
|
saveLogbook(event)
|
||||||
|
|
||||||
|
// Check logbook size to avoid OOM errors
|
||||||
|
if (logbook?.isTooBig() == true) {
|
||||||
|
askToTrimLogbook()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the logbook. If saving while adding an event, please specify the event so in case
|
* Saves the logbook. If saving while adding an event, please specify the event so in case
|
||||||
* of error can be removed from the list.
|
* of error can be removed from the list.
|
||||||
|
|||||||
Reference in New Issue
Block a user