mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-04 12:37:45 +01:00
fix "Delete all events" for cases when there is a huge amount of events
This commit is contained in:
parent
365c400505
commit
bf8283985f
@ -0,0 +1,16 @@
|
||||
package com.simplemobiletools.calendar.pro.extensions
|
||||
|
||||
import com.simplemobiletools.calendar.pro.helpers.CHOPPED_LIST_DEFAULT_SIZE
|
||||
|
||||
// inspired by https://stackoverflow.com/questions/2895342/java-how-can-i-split-an-arraylist-in-multiple-small-arraylists/2895365#2895365
|
||||
fun MutableList<Long>.getChoppedList(chunkSize: Int = CHOPPED_LIST_DEFAULT_SIZE): ArrayList<ArrayList<Long>> {
|
||||
val parts = ArrayList<ArrayList<Long>>()
|
||||
val listSize = this.size
|
||||
var i = 0
|
||||
while (i < listSize) {
|
||||
val newList = subList(i, Math.min(listSize, i + chunkSize)).toMutableList() as ArrayList<Long>
|
||||
parts.add(newList)
|
||||
i += chunkSize
|
||||
}
|
||||
return parts
|
||||
}
|
@ -16,6 +16,7 @@ const val WEEK_START_DATE_TIME = "week_start_date_time"
|
||||
const val CALDAV = "Caldav"
|
||||
const val VIEW_TO_OPEN = "view_to_open"
|
||||
const val REGULAR_EVENT_TYPE_ID = 1L
|
||||
const val CHOPPED_LIST_DEFAULT_SIZE = 100
|
||||
|
||||
const val MONTHLY_VIEW = 1
|
||||
const val YEARLY_VIEW = 2
|
||||
|
@ -132,21 +132,23 @@ class EventsHelper(val context: Context) {
|
||||
return
|
||||
}
|
||||
|
||||
val eventsWithImportId = eventsDB.getEventsByIdsWithImportIds(ids)
|
||||
eventsDB.deleteEvents(ids)
|
||||
ids.getChoppedList().forEach {
|
||||
val eventsWithImportId = eventsDB.getEventsByIdsWithImportIds(it)
|
||||
eventsDB.deleteEvents(it)
|
||||
|
||||
ids.forEach {
|
||||
context.cancelNotification(it)
|
||||
}
|
||||
|
||||
if (deleteFromCalDAV && config.caldavSync) {
|
||||
eventsWithImportId.forEach {
|
||||
context.calDAVHelper.deleteCalDAVEvent(it)
|
||||
it.forEach {
|
||||
context.cancelNotification(it)
|
||||
}
|
||||
}
|
||||
|
||||
deleteChildEvents(ids, deleteFromCalDAV)
|
||||
context.updateWidgets()
|
||||
if (deleteFromCalDAV && config.caldavSync) {
|
||||
eventsWithImportId.forEach {
|
||||
context.calDAVHelper.deleteCalDAVEvent(it)
|
||||
}
|
||||
}
|
||||
|
||||
deleteChildEvents(it, deleteFromCalDAV)
|
||||
context.updateWidgets()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteChildEvents(ids: MutableList<Long>, deleteFromCalDAV: Boolean) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user