mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
allow fetching birthdays and anniversaries in Room
This commit is contained in:
@@ -481,7 +481,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
val dateFormats = getDateFormats()
|
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 importIDs = existingEvents.map { it.importId }
|
||||||
val eventTypeId = if (birthdays) getBirthdaysEventTypeId() else getAnniversariesEventTypeId()
|
val eventTypeId = if (birthdays) getBirthdaysEventTypeId() else getAnniversariesEventTypeId()
|
||||||
|
|
||||||
|
@@ -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() {
|
fun deleteAllEvents() {
|
||||||
val cursor = getEventsCursor()
|
val cursor = getEventsCursor()
|
||||||
val events = fillEvents(cursor).map { it.id.toString() }.toTypedArray()
|
val events = fillEvents(cursor).map { it.id.toString() }.toTypedArray()
|
||||||
|
@@ -4,13 +4,21 @@ 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 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
|
import com.simplemobiletools.calendar.pro.models.Event
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface EventsDao {
|
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>
|
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)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insertOrUpdate(event: Event): Long
|
fun insertOrUpdate(event: Event): Long
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user