delete events belonging to a particular event type if selected so
This commit is contained in:
parent
67135b0122
commit
c5070b8bc4
|
@ -58,7 +58,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
||||||
toast(R.string.cannot_delete_default_type)
|
toast(R.string.cannot_delete_default_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbHelper.deleteEventTypes(ids) {
|
dbHelper.deleteEventTypes(ids, deleteEvents) {
|
||||||
if (it > 0) {
|
if (it > 0) {
|
||||||
getEventTypes()
|
getEventTypes()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -311,7 +311,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
mDb.insert(EXCEPTIONS_TABLE_NAME, null, values)
|
mDb.insert(EXCEPTIONS_TABLE_NAME, null, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteEventTypes(ids: ArrayList<Int>, callback: (deletedCnt: Int) -> Unit) {
|
fun deleteEventTypes(ids: ArrayList<Int>, deleteEvents: Boolean, callback: (deletedCnt: Int) -> Unit) {
|
||||||
var deleteIds = ids
|
var deleteIds = ids
|
||||||
if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID))
|
if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID))
|
||||||
deleteIds = ids.filter { it != DBHelper.REGULAR_EVENT_TYPE_ID } as ArrayList<Int>
|
deleteIds = ids.filter { it != DBHelper.REGULAR_EVENT_TYPE_ID } as ArrayList<Int>
|
||||||
|
@ -323,7 +323,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
return
|
return
|
||||||
|
|
||||||
for (eventTypeId in deleteIds) {
|
for (eventTypeId in deleteIds) {
|
||||||
resetEventsWithType(eventTypeId)
|
if (deleteEvents) {
|
||||||
|
deleteEventsWithType(eventTypeId)
|
||||||
|
} else {
|
||||||
|
resetEventsWithType(eventTypeId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val args = TextUtils.join(", ", deleteIds)
|
val args = TextUtils.join(", ", deleteIds)
|
||||||
|
@ -331,6 +335,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
callback.invoke(mDb.delete(TYPES_TABLE_NAME, selection, null))
|
callback.invoke(mDb.delete(TYPES_TABLE_NAME, selection, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun deleteEventsWithType(eventTypeId: Int) {
|
||||||
|
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_TYPE = ?"
|
||||||
|
val selectionArgs = arrayOf(eventTypeId.toString())
|
||||||
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
|
val events = fillEvents(cursor)
|
||||||
|
val eventIDs = Array(events.size, { i -> (events[i].id.toString()) })
|
||||||
|
deleteEvents(eventIDs)
|
||||||
|
}
|
||||||
|
|
||||||
private fun resetEventsWithType(eventTypeId: Int) {
|
private fun resetEventsWithType(eventTypeId: Int) {
|
||||||
val values = ContentValues()
|
val values = ContentValues()
|
||||||
values.put(COL_EVENT_TYPE, REGULAR_EVENT_TYPE_ID)
|
values.put(COL_EVENT_TYPE, REGULAR_EVENT_TYPE_ID)
|
||||||
|
|
Loading…
Reference in New Issue