do not allow inserting corrupt events in db

This commit is contained in:
tibbi 2017-01-26 21:52:59 +01:00
parent a7739dbbe2
commit 399cb84493
1 changed files with 5 additions and 1 deletions

View File

@ -71,7 +71,10 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
"$COL_REPEAT_INTERVAL INTEGER, $COL_REPEAT_MONTH INTEGER, $COL_REPEAT_DAY INTEGER)") "$COL_REPEAT_INTERVAL INTEGER, $COL_REPEAT_MONTH INTEGER, $COL_REPEAT_DAY INTEGER)")
} }
fun insert(event: Event) { fun insert(event: Event, insertListener: (event: Event) -> Unit) {
if (event.startTS > event.endTS || event.title.trim().isEmpty())
return
val eventValues = fillContentValues(event) val eventValues = fillContentValues(event)
val id = mDb.insert(MAIN_TABLE_NAME, null, eventValues) val id = mDb.insert(MAIN_TABLE_NAME, null, eventValues)
event.id = id.toInt() event.id = id.toInt()
@ -82,6 +85,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
context?.updateWidgets() context?.updateWidgets()
mEventsListener?.eventInserted(event) mEventsListener?.eventInserted(event)
insertListener.invoke(event)
} }
fun update(event: Event) { fun update(event: Event) {