From 22bb7595d5d118c22e7e6828eb4c2bcfee950743 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 14 Nov 2018 20:08:24 +0100 Subject: [PATCH] add a Room function for getting events with filled import ids --- .../com/simplemobiletools/calendar/pro/helpers/DBHelper.kt | 2 -- .../com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt | 3 ++- .../com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt index 0f95fd795..3c26efe34 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt @@ -199,8 +199,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) } - fun getEventsWithImportIds() = getEvents("").filter { it.importId.trim().isNotEmpty() } as ArrayList - fun getEventWithId(id: Long): Event? { val selection = "$MAIN_TABLE_NAME.$COL_ID = ?" val selectionArgs = arrayOf(id.toString()) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt index 31043efc4..43916feac 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt @@ -4,6 +4,7 @@ import android.widget.Toast import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.extensions.dbHelper +import com.simplemobiletools.calendar.pro.extensions.eventsDB import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.* import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.EventType @@ -42,7 +43,7 @@ class IcsImporter(val activity: SimpleActivity) { fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult { try { val eventTypes = EventsHelper(activity).getEventTypesSync() - val existingEvents = activity.dbHelper.getEventsWithImportIds() + val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList val eventsToInsert = ArrayList() var prevLine = "" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt index d3745c9c0..fac8b7343 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt @@ -19,6 +19,9 @@ interface EventsDao { @Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_ANNIVERSARY\'") fun getAnniversaries(): List + @Query("SELECT * FROM events WHERE import_id != \"\"") + fun getEventsWithImportIds(): List + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertOrUpdate(event: Event): Long }