allow fetching birthdays and anniversaries in Room

This commit is contained in:
tibbi 2018-11-14 20:03:53 +01:00
parent b4d84e8960
commit a5e809b4c9
3 changed files with 10 additions and 16 deletions

View file

@ -481,7 +481,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
if (cursor?.moveToFirst() == true) {
val dateFormats = getDateFormats()
val existingEvents = if (birthdays) dbHelper.getBirthdays() else dbHelper.getAnniversaries()
val existingEvents = if (birthdays) eventsDB.getBirthdays() else eventsDB.getAnniversaries()
val importIDs = existingEvents.map { it.importId }
val eventTypeId = if (birthdays) getBirthdaysEventTypeId() else getAnniversariesEventTypeId()

View file

@ -90,20 +90,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
fun getBirthdays(): List<Event> {
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?"
val selectionArgs = arrayOf(SOURCE_CONTACT_BIRTHDAY)
val cursor = getEventsCursor(selection, selectionArgs)
return fillEvents(cursor)
}
fun getAnniversaries(): List<Event> {
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?"
val selectionArgs = arrayOf(SOURCE_CONTACT_ANNIVERSARY)
val cursor = getEventsCursor(selection, selectionArgs)
return fillEvents(cursor)
}
fun deleteAllEvents() {
val cursor = getEventsCursor()
val events = fillEvents(cursor).map { it.id.toString() }.toTypedArray()

View file

@ -4,13 +4,21 @@ import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.simplemobiletools.calendar.pro.helpers.SOURCE_CONTACT_ANNIVERSARY
import com.simplemobiletools.calendar.pro.helpers.SOURCE_CONTACT_BIRTHDAY
import com.simplemobiletools.calendar.pro.models.Event
@Dao
interface EventsDao {
@Query("DELETE FROM events WHERE id IN (:ids)")
@Query("SELECT * FROM events WHERE id IN (:ids)")
fun getEventsWithIds(ids: List<Long>): List<Event>
@Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_BIRTHDAY\'")
fun getBirthdays(): List<Event>
@Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_ANNIVERSARY\'")
fun getAnniversaries(): List<Event>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(event: Event): Long
}