create a room function for fetching events by ids

This commit is contained in:
tibbi 2018-11-14 19:51:36 +01:00
parent ec40b5954c
commit b4d84e8960
3 changed files with 6 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import com.simplemobiletools.calendar.pro.BuildConfig
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.dialogs.CustomEventRepeatIntervalDialog import com.simplemobiletools.calendar.pro.dialogs.CustomEventRepeatIntervalDialog
import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.hideKeyboard
@ -23,7 +24,7 @@ fun BaseSimpleActivity.shareEvents(ids: List<Long>) {
return@Thread return@Thread
} }
val events = dbHelper.getEventsWithIds(ids) val events = eventsDB.getEventsWithIds(ids) as ArrayList<Event>
IcsExporter().exportEvents(this, file, events, false) { IcsExporter().exportEvents(this, file, events, false) {
if (it == IcsExporter.ExportResult.EXPORT_OK) { if (it == IcsExporter.ExportResult.EXPORT_OK) {
sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID) sharePathIntent(file.absolutePath, BuildConfig.APPLICATION_ID)

View File

@ -483,12 +483,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return events return events
} }
fun getEventsWithIds(ids: List<Long>): ArrayList<Event> {
val args = TextUtils.join(", ", ids)
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
return getEvents(selection) as ArrayList<Event>
}
fun getEventsAtReboot(): List<Event> { fun getEventsAtReboot(): List<Event> {
//val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0) AND $COL_START_TS != 0" //val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0) AND $COL_START_TS != 0"
val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ?) AND $COL_START_TS != 0" val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ?) AND $COL_START_TS != 0"

View File

@ -3,10 +3,14 @@ package com.simplemobiletools.calendar.pro.interfaces
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.Event
@Dao @Dao
interface EventsDao { interface EventsDao {
@Query("DELETE FROM events WHERE id IN (:ids)")
fun getEventsWithIds(ids: List<Long>): List<Event>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(event: Event): Long fun insertOrUpdate(event: Event): Long
} }