mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fix "Delete all events" for cases when there is a huge amount of events
This commit is contained in:
@ -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 CALDAV = "Caldav"
|
||||||
const val VIEW_TO_OPEN = "view_to_open"
|
const val VIEW_TO_OPEN = "view_to_open"
|
||||||
const val REGULAR_EVENT_TYPE_ID = 1L
|
const val REGULAR_EVENT_TYPE_ID = 1L
|
||||||
|
const val CHOPPED_LIST_DEFAULT_SIZE = 100
|
||||||
|
|
||||||
const val MONTHLY_VIEW = 1
|
const val MONTHLY_VIEW = 1
|
||||||
const val YEARLY_VIEW = 2
|
const val YEARLY_VIEW = 2
|
||||||
|
@ -132,21 +132,23 @@ class EventsHelper(val context: Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val eventsWithImportId = eventsDB.getEventsByIdsWithImportIds(ids)
|
ids.getChoppedList().forEach {
|
||||||
eventsDB.deleteEvents(ids)
|
val eventsWithImportId = eventsDB.getEventsByIdsWithImportIds(it)
|
||||||
|
eventsDB.deleteEvents(it)
|
||||||
|
|
||||||
ids.forEach {
|
it.forEach {
|
||||||
context.cancelNotification(it)
|
context.cancelNotification(it)
|
||||||
}
|
|
||||||
|
|
||||||
if (deleteFromCalDAV && config.caldavSync) {
|
|
||||||
eventsWithImportId.forEach {
|
|
||||||
context.calDAVHelper.deleteCalDAVEvent(it)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
deleteChildEvents(ids, deleteFromCalDAV)
|
if (deleteFromCalDAV && config.caldavSync) {
|
||||||
context.updateWidgets()
|
eventsWithImportId.forEach {
|
||||||
|
context.calDAVHelper.deleteCalDAVEvent(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteChildEvents(it, deleteFromCalDAV)
|
||||||
|
context.updateWidgets()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteChildEvents(ids: MutableList<Long>, deleteFromCalDAV: Boolean) {
|
private fun deleteChildEvents(ids: MutableList<Long>, deleteFromCalDAV: Boolean) {
|
||||||
|
Reference in New Issue
Block a user