delete the redundant event types after disabling a calendar sync

This commit is contained in:
tibbi 2017-08-24 14:09:12 +02:00
parent aa9adaa236
commit c1f8d981b5
2 changed files with 11 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.ActivityCompat
import android.text.TextUtils
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog
import com.simplemobiletools.calendar.dialogs.SelectCalendarsDialog
@ -128,6 +129,7 @@ class SettingsActivity : SimpleActivity() {
config.getSyncedCalendarIdsAsList().forEach {
CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
}
dbHelper.deleteEventTypesWithCalendarId(config.caldavSyncedCalendarIDs)
}
}
@ -154,12 +156,14 @@ class SettingsActivity : SimpleActivity() {
CalDAVHandler(applicationContext).refreshCalendars {}
}
oldCalendarIds.filter { !newCalendarIds.contains(it) }.forEach {
val removedCalendarIds = oldCalendarIds.filter { !newCalendarIds.contains(it) }
removedCalendarIds.forEach {
CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
dbHelper.getEventTypeWithCalDAVCalendarId(it.toInt())?.apply {
dbHelper.deleteEventTypes(arrayListOf(this), true) {}
}
}
dbHelper.deleteEventTypesWithCalendarId(TextUtils.join(",", removedCalendarIds))
}).start()
}
}

View file

@ -466,7 +466,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val args = TextUtils.join(", ", deleteIds)
val selection = "$COL_TYPE_ID IN ($args)"
callback.invoke(mDb.delete(TYPES_TABLE_NAME, selection, null))
callback(mDb.delete(TYPES_TABLE_NAME, selection, null))
}
fun deleteEventTypesWithCalendarId(calendarIds: String) {
val selection = "$COL_TYPE_CALDAV_CALENDAR_ID IN ($calendarIds)"
mDb.delete(TYPES_TABLE_NAME, selection, null)
}
private fun deleteEventsWithType(eventTypeId: Int) {