add a Room function for getting events with filled import ids

This commit is contained in:
tibbi
2018-11-14 20:08:24 +01:00
parent a5e809b4c9
commit 22bb7595d5
3 changed files with 5 additions and 3 deletions

View File

@@ -199,8 +199,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs)
} }
fun getEventsWithImportIds() = getEvents("").filter { it.importId.trim().isNotEmpty() } as ArrayList<Event>
fun getEventWithId(id: Long): Event? { fun getEventWithId(id: Long): Event? {
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?" val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
val selectionArgs = arrayOf(id.toString()) val selectionArgs = arrayOf(id.toString())

View File

@@ -4,6 +4,7 @@ import android.widget.Toast
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.extensions.dbHelper 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.helpers.IcsImporter.ImportResult.*
import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.EventType 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 { fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
try { try {
val eventTypes = EventsHelper(activity).getEventTypesSync() val eventTypes = EventsHelper(activity).getEventTypesSync()
val existingEvents = activity.dbHelper.getEventsWithImportIds() val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList<Event>
val eventsToInsert = ArrayList<Event>() val eventsToInsert = ArrayList<Event>()
var prevLine = "" var prevLine = ""

View File

@@ -19,6 +19,9 @@ interface EventsDao {
@Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_ANNIVERSARY\'") @Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_ANNIVERSARY\'")
fun getAnniversaries(): List<Event> fun getAnniversaries(): List<Event>
@Query("SELECT * FROM events WHERE import_id != \"\"")
fun getEventsWithImportIds(): List<Event>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(event: Event): Long fun insertOrUpdate(event: Event): Long
} }