mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-31 02:44:57 +01:00
moving another check in Room
This commit is contained in:
parent
85d614f690
commit
361e1204bb
@ -6,7 +6,7 @@ import android.view.ViewGroup
|
|||||||
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.config
|
import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||||
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
||||||
import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
@ -71,9 +71,9 @@ class ManageEventTypesAdapter(activity: SimpleActivity, val eventTypes: ArrayLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun askConfirmDelete() {
|
private fun askConfirmDelete() {
|
||||||
val eventTypes = eventTypes.filter { selectedKeys.contains(it.id?.toInt()) } as ArrayList<EventType>
|
val eventTypes = eventTypes.filter { selectedKeys.contains(it.id?.toInt()) }.map { it.id } as ArrayList<Long>
|
||||||
|
|
||||||
activity.dbHelper.doEventTypesContainEvents(eventTypes) {
|
EventsHelper(activity).doEventTypesContainEvents(eventTypes) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
if (it) {
|
if (it) {
|
||||||
val MOVE_EVENTS = 0
|
val MOVE_EVENTS = 0
|
||||||
|
@ -9,7 +9,6 @@ import androidx.collection.LongSparseArray
|
|||||||
import com.simplemobiletools.calendar.pro.extensions.*
|
import com.simplemobiletools.calendar.pro.extensions.*
|
||||||
import com.simplemobiletools.calendar.pro.models.Event
|
import com.simplemobiletools.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.calendar.pro.models.EventRepetitionException
|
import com.simplemobiletools.calendar.pro.models.EventRepetitionException
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
|
||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
import com.simplemobiletools.commons.extensions.getIntValue
|
||||||
import com.simplemobiletools.commons.extensions.getLongValue
|
import com.simplemobiletools.commons.extensions.getLongValue
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
@ -102,7 +101,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
fun getEventsWithSearchQuery(text: String, callback: (searchedText: String, events: List<Event>) -> Unit) {
|
fun getEventsWithSearchQuery(text: String, callback: (searchedText: String, events: List<Event>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val searchQuery = "%$text%"
|
val searchQuery = "%$text%"
|
||||||
val selection = "$MAIN_TABLE_NAME.$COL_TITLE LIKE ? OR $MAIN_TABLE_NAME.$COL_LOCATION LIKE ? OR $MAIN_TABLE_NAME.$COL_DESCRIPTION LIKE ?"
|
val selection = "$COL_TITLE LIKE ? OR $COL_LOCATION LIKE ? OR $COL_DESCRIPTION LIKE ?"
|
||||||
val selectionArgs = arrayOf(searchQuery, searchQuery, searchQuery)
|
val selectionArgs = arrayOf(searchQuery, searchQuery, searchQuery)
|
||||||
val cursor = getEventsCursor(selection, selectionArgs)
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
val events = fillEvents(cursor)
|
val events = fillEvents(cursor)
|
||||||
@ -366,7 +365,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getEventsFromCalDAVCalendar(calendarId: Int): List<Event> {
|
fun getEventsFromCalDAVCalendar(calendarId: Int): List<Event> {
|
||||||
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?"
|
val selection = "$COL_EVENT_SOURCE = ?"
|
||||||
val selectionArgs = arrayOf("$CALDAV-$calendarId")
|
val selectionArgs = arrayOf("$CALDAV-$calendarId")
|
||||||
val cursor = getEventsCursor(selection, selectionArgs)
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
return fillEvents(cursor)
|
return fillEvents(cursor)
|
||||||
@ -423,21 +422,4 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doEventTypesContainEvents(types: ArrayList<EventType>, callback: (contain: Boolean) -> Unit) {
|
|
||||||
Thread {
|
|
||||||
val args = TextUtils.join(", ", types.map { it.id })
|
|
||||||
val columns = arrayOf(COL_ID)
|
|
||||||
val selection = "$COL_EVENT_TYPE IN ($args)"
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
cursor = mDb.query(MAIN_TABLE_NAME, columns, selection, null, null, null, null)
|
|
||||||
callback(cursor?.moveToFirst() == true)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
callback(false)
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class EventsHelper(val context: Context) {
|
|||||||
|
|
||||||
for (eventTypeId in deleteIds) {
|
for (eventTypeId in deleteIds) {
|
||||||
if (deleteEvents) {
|
if (deleteEvents) {
|
||||||
EventsHelper(context).deleteEventsWithType(eventTypeId!!)
|
deleteEventsWithType(eventTypeId!!)
|
||||||
} else {
|
} else {
|
||||||
context.eventsDB.resetEventsWithType(eventTypeId!!)
|
context.eventsDB.resetEventsWithType(eventTypeId!!)
|
||||||
}
|
}
|
||||||
@ -184,4 +184,11 @@ class EventsHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun doEventTypesContainEvents(eventTypeIds: ArrayList<Long>, callback: (contain: Boolean) -> Unit) {
|
||||||
|
Thread {
|
||||||
|
val eventIds = context.eventsDB.getEventIdsByEventType(eventTypeIds)
|
||||||
|
callback(eventIds.isNotEmpty())
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ interface EventsDao {
|
|||||||
@Query("SELECT id FROM events WHERE event_type = :eventTypeId")
|
@Query("SELECT id FROM events WHERE event_type = :eventTypeId")
|
||||||
fun getEventIdsByEventType(eventTypeId: Long): List<Long>
|
fun getEventIdsByEventType(eventTypeId: Long): List<Long>
|
||||||
|
|
||||||
|
@Query("SELECT id FROM events WHERE event_type IN (:eventTypeIds)")
|
||||||
|
fun getEventIdsByEventType(eventTypeIds: List<Long>): List<Long>
|
||||||
|
|
||||||
@Query("SELECT * 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>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user