diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt index 7afb940de..1c60733b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt @@ -21,7 +21,6 @@ import java.util.* // more info about event fields at https://developers.google.com/google-apps/calendar/v3/reference/events/insert class FetchGoogleEventsTask(val activity: Activity) : AsyncTask>() { private val CONFIRMED = "confirmed" - private val PRIMARY = "primary" private val ITEMS = "items" private val OVERRIDES = "overrides" private val POPUP = "popup" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index 7c6d03180..d661e7158 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -12,6 +12,7 @@ val EVENT_OCCURRENCE_TS = "event_occurrence_ts" val NEW_EVENT_START_TS = "new_event_start_ts" val WEEK_START_TIMESTAMP = "week_start_timestamp" val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration" +val PRIMARY = "primary" val MONTHLY_VIEW = 1 val YEARLY_VIEW = 2 diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 6ddb19f35..a7b44daee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -323,9 +323,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return null } - fun deleteEvents(ids: Array) { + fun deleteEvents(ids: Array, deleteFromGoogle: Boolean = true) { 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) val metaSelection = "$COL_EVENT_ID IN ($args)" @@ -342,6 +346,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } deleteChildEvents(args) + if (deleteFromGoogle) { + importIDs.forEach { + Thread({ + if (context.isOnline()) { + context.getGoogleSyncService().events().delete(PRIMARY, it).execute() + } + }).start() + } + } } private fun deleteChildEvents(ids: String) { @@ -370,7 +383,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val cursor = getEventsCursor(selection) val events = fillEvents(cursor) val eventIDs = Array(events.size, { i -> (events[i].id.toString()) }) - deleteEvents(eventIDs) + deleteEvents(eventIDs, false) } fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int) {