moving event deleting on a background thread in some cases

This commit is contained in:
tibbi
2018-11-12 19:00:26 +01:00
parent ab10394122
commit fab72371d0
3 changed files with 29 additions and 17 deletions

View File

@@ -677,12 +677,16 @@ class EventActivity : SimpleActivity() {
private fun deleteEvent() { private fun deleteEvent() {
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) { DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
when (it) { Thread {
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true) when (it) {
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS) DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true) DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
} DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
finish() }
runOnUiThread {
finish()
}
}.start()
} }
} }

View File

@@ -142,12 +142,16 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) { it -> DeleteEventDialog(activity, eventIds, hasRepeatableEvent) { it ->
events.removeAll(eventsToDelete) events.removeAll(eventsToDelete)
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.map { it.id.toString() }.toList().toTypedArray() Thread {
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true) val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.map { it.id.toString() }.toList().toTypedArray()
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.map { it.id!! }.toList() val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.map { it.id!! }.toList()
activity.handleEventDeleting(repeatingEventIDs, timestamps, it) activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
removeSelectedItems(positions) activity.runOnUiThread {
removeSelectedItems(positions)
}
}.start()
} }
} }
} }

View File

@@ -206,13 +206,17 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) { DeleteEventDialog(activity, eventIds, hasRepeatableEvent) {
listItems.removeAll(eventsToDelete) listItems.removeAll(eventsToDelete)
val nonRepeatingEventIDs = eventsToDelete.filter { !it.isRepeatable }.map { it.id.toString() }.toTypedArray() Thread {
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true) val nonRepeatingEventIDs = eventsToDelete.filter { !it.isRepeatable }.map { it.id.toString() }.toTypedArray()
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
val repeatingEventIDs = eventsToDelete.filter { it.isRepeatable }.map { it.id } val repeatingEventIDs = eventsToDelete.filter { it.isRepeatable }.map { it.id }
activity.handleEventDeleting(repeatingEventIDs, timestamps, it) activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
listener?.refreshItems() activity.runOnUiThread {
finishActMode() listener?.refreshItems()
finishActMode()
}
}.start()
} }
} }
} }