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() {
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
when (it) {
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
}
finish()
Thread {
when (it) {
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
}
runOnUiThread {
finish()
}
}.start()
}
}

View File

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

View File

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