delete the synced events from the device at disabling google sync

This commit is contained in:
tibbi 2017-07-21 22:46:18 +02:00
parent 9357ab7bca
commit f726e8c00e
2 changed files with 14 additions and 3 deletions

View File

@ -115,12 +115,15 @@ class SettingsActivity : SimpleActivity() {
private fun setupGoogleSync() {
settings_google_sync.isChecked = config.googleSync
settings_google_sync_holder.setOnClickListener {
if (!config.googleSync) {
ConfirmationDialog(this, getString(R.string.google_sync_testing), positive = R.string.ok, negative = 0) {
if (config.googleSync) {
ConfirmationDialog(this, getString(R.string.google_sync_disabling), positive = R.string.ok, negative = R.string.cancel) {
dbHelper.deleteGoogleSyncEvents()
toggleGoogleSync()
}
} else {
toggleGoogleSync()
ConfirmationDialog(this, getString(R.string.google_sync_testing), positive = R.string.ok, negative = 0) {
toggleGoogleSync()
}
}
}
}

View File

@ -365,6 +365,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
deleteEvents(childIds.toTypedArray())
}
fun deleteGoogleSyncEvents() {
val selection = "$COL_SOURCE = $SOURCE_GOOGLE_SYNC"
val cursor = getEventsCursor(selection)
val events = fillEvents(cursor)
val eventIDs = Array(events.size, { i -> (events[i].id.toString()) })
deleteEvents(eventIDs)
}
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int) {
fillExceptionValues(parentEventId, occurrenceTS) {
mDb.insert(EXCEPTIONS_TABLE_NAME, null, it)