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 a557aabe3..282de5541 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -327,8 +327,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val args = TextUtils.join(", ", ids) 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) }).filter { it?.isNotEmpty() == true } + val events = fillEvents(cursor).filter { it.importId.isNotEmpty() } mDb.delete(MAIN_TABLE_NAME, selection, null) @@ -347,13 +346,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont deleteChildEvents(args, deleteFromGoogle) if (deleteFromGoogle) { - importIDs.forEach { + events.forEach { Thread({ if (context.isOnline()) { try { - context.getGoogleSyncService().events().delete(PRIMARY, it).execute() + context.getGoogleSyncService().events().delete(PRIMARY, it.importId).execute() } catch (ignored: Exception) { } + } else { + context.googleSyncQueue.insert(it.id, OPERATION_DELETE) } }).start() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncQueueDB.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncQueueDB.kt index f60d100c3..5142f545e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncQueueDB.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncQueueDB.kt @@ -38,10 +38,12 @@ class GoogleSyncQueueDB private constructor(val context: Context) : SQLiteOpenHe } - fun insert(operation: Int, eventId: Int) { + fun insert(eventId: Int, operation: Int) { + delete(eventId) + val contentValues = ContentValues().apply { - put(COL_OPERATION, operation) put(COL_EVENT_ID, eventId) + put(COL_OPERATION, operation) } mDb.insert(OPERATIONS_TABLE_NAME, null, contentValues) }