mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-19 05:00:49 +01:00
delete events from the google calendar when appropriate
This commit is contained in:
parent
7eca2a7d65
commit
79e6e94c6d
@ -21,7 +21,6 @@ import java.util.*
|
|||||||
// more info about event fields at https://developers.google.com/google-apps/calendar/v3/reference/events/insert
|
// more info about event fields at https://developers.google.com/google-apps/calendar/v3/reference/events/insert
|
||||||
class FetchGoogleEventsTask(val activity: Activity) : AsyncTask<Void, Void, List<Event>>() {
|
class FetchGoogleEventsTask(val activity: Activity) : AsyncTask<Void, Void, List<Event>>() {
|
||||||
private val CONFIRMED = "confirmed"
|
private val CONFIRMED = "confirmed"
|
||||||
private val PRIMARY = "primary"
|
|
||||||
private val ITEMS = "items"
|
private val ITEMS = "items"
|
||||||
private val OVERRIDES = "overrides"
|
private val OVERRIDES = "overrides"
|
||||||
private val POPUP = "popup"
|
private val POPUP = "popup"
|
||||||
|
@ -12,6 +12,7 @@ val EVENT_OCCURRENCE_TS = "event_occurrence_ts"
|
|||||||
val NEW_EVENT_START_TS = "new_event_start_ts"
|
val NEW_EVENT_START_TS = "new_event_start_ts"
|
||||||
val WEEK_START_TIMESTAMP = "week_start_timestamp"
|
val WEEK_START_TIMESTAMP = "week_start_timestamp"
|
||||||
val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
|
val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
|
||||||
|
val PRIMARY = "primary"
|
||||||
|
|
||||||
val MONTHLY_VIEW = 1
|
val MONTHLY_VIEW = 1
|
||||||
val YEARLY_VIEW = 2
|
val YEARLY_VIEW = 2
|
||||||
|
@ -323,9 +323,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteEvents(ids: Array<String>) {
|
fun deleteEvents(ids: Array<String>, deleteFromGoogle: Boolean = true) {
|
||||||
val args = TextUtils.join(", ", ids)
|
val args = TextUtils.join(", ", ids)
|
||||||
val selection = "$COL_ID IN ($args)"
|
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
|
||||||
|
val cursor = getEventsCursor(selection)
|
||||||
|
val events = fillEvents(cursor)
|
||||||
|
val importIDs = Array(events.size, { i -> (events[i].importId) })
|
||||||
|
|
||||||
mDb.delete(MAIN_TABLE_NAME, selection, null)
|
mDb.delete(MAIN_TABLE_NAME, selection, null)
|
||||||
|
|
||||||
val metaSelection = "$COL_EVENT_ID IN ($args)"
|
val metaSelection = "$COL_EVENT_ID IN ($args)"
|
||||||
@ -342,6 +346,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteChildEvents(args)
|
deleteChildEvents(args)
|
||||||
|
if (deleteFromGoogle) {
|
||||||
|
importIDs.forEach {
|
||||||
|
Thread({
|
||||||
|
if (context.isOnline()) {
|
||||||
|
context.getGoogleSyncService().events().delete(PRIMARY, it).execute()
|
||||||
|
}
|
||||||
|
}).start()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteChildEvents(ids: String) {
|
private fun deleteChildEvents(ids: String) {
|
||||||
@ -370,7 +383,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val cursor = getEventsCursor(selection)
|
val cursor = getEventsCursor(selection)
|
||||||
val events = fillEvents(cursor)
|
val events = fillEvents(cursor)
|
||||||
val eventIDs = Array(events.size, { i -> (events[i].id.toString()) })
|
val eventIDs = Array(events.size, { i -> (events[i].id.toString()) })
|
||||||
deleteEvents(eventIDs)
|
deleteEvents(eventIDs, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int) {
|
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user