mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
removing some redundant db columns
This commit is contained in:
@@ -45,7 +45,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val COL_REPEAT_LIMIT = "repeat_limit"
|
private val COL_REPEAT_LIMIT = "repeat_limit"
|
||||||
|
|
||||||
private val TYPES_TABLE_NAME = "event_types"
|
private val TYPES_TABLE_NAME = "event_types"
|
||||||
private val COL_TYPE_ID = "event_type_id"
|
|
||||||
private val COL_TYPE_TITLE = "event_type_title"
|
private val COL_TYPE_TITLE = "event_type_title"
|
||||||
private val COL_TYPE_COLOR = "event_type_color"
|
private val COL_TYPE_COLOR = "event_type_color"
|
||||||
private val COL_TYPE_CALDAV_CALENDAR_ID = "event_caldav_calendar_id"
|
private val COL_TYPE_CALDAV_CALENDAR_ID = "event_caldav_calendar_id"
|
||||||
@@ -53,7 +52,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
private val COL_TYPE_CALDAV_EMAIL = "event_caldav_email"
|
private val COL_TYPE_CALDAV_EMAIL = "event_caldav_email"
|
||||||
|
|
||||||
private val REPEAT_EXCEPTIONS_TABLE_NAME = "event_repeat_exceptions"
|
private val REPEAT_EXCEPTIONS_TABLE_NAME = "event_repeat_exceptions"
|
||||||
private val COL_EXCEPTION_ID = "event_exception_id"
|
|
||||||
private val COL_OCCURRENCE_TIMESTAMP = "event_occurrence_timestamp"
|
private val COL_OCCURRENCE_TIMESTAMP = "event_occurrence_timestamp"
|
||||||
private val COL_OCCURRENCE_DAYCODE = "event_occurrence_daycode"
|
private val COL_OCCURRENCE_DAYCODE = "event_occurrence_daycode"
|
||||||
private val COL_PARENT_EVENT_ID = "event_parent_id"
|
private val COL_PARENT_EVENT_ID = "event_parent_id"
|
||||||
@@ -94,13 +92,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createTypesTable(db: SQLiteDatabase) {
|
private fun createTypesTable(db: SQLiteDatabase) {
|
||||||
db.execSQL("CREATE TABLE $TYPES_TABLE_NAME ($COL_TYPE_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TYPE_TITLE TEXT, $COL_TYPE_COLOR INTEGER, " +
|
db.execSQL("CREATE TABLE $TYPES_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TYPE_TITLE TEXT, $COL_TYPE_COLOR INTEGER, " +
|
||||||
"$COL_TYPE_CALDAV_CALENDAR_ID INTEGER, $COL_TYPE_CALDAV_DISPLAY_NAME TEXT, $COL_TYPE_CALDAV_EMAIL TEXT)")
|
"$COL_TYPE_CALDAV_CALENDAR_ID INTEGER, $COL_TYPE_CALDAV_DISPLAY_NAME TEXT, $COL_TYPE_CALDAV_EMAIL TEXT)")
|
||||||
addRegularEventType(db)
|
addRegularEventType(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createExceptionsTable(db: SQLiteDatabase) {
|
private fun createExceptionsTable(db: SQLiteDatabase) {
|
||||||
db.execSQL("CREATE TABLE $REPEAT_EXCEPTIONS_TABLE_NAME ($COL_EXCEPTION_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_PARENT_EVENT_ID INTEGER, " +
|
db.execSQL("CREATE TABLE $REPEAT_EXCEPTIONS_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_PARENT_EVENT_ID INTEGER, " +
|
||||||
"$COL_OCCURRENCE_TIMESTAMP INTEGER, $COL_OCCURRENCE_DAYCODE INTEGER, $COL_CHILD_EVENT_ID INTEGER)")
|
"$COL_OCCURRENCE_TIMESTAMP INTEGER, $COL_OCCURRENCE_DAYCODE INTEGER, $COL_CHILD_EVENT_ID INTEGER)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,9 +215,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addEventType(eventType: EventType, db: SQLiteDatabase) {
|
private fun addEventType(eventType: EventType, db: SQLiteDatabase) = insertEventType(eventType, db)
|
||||||
insertEventType(eventType, db)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Long {
|
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Long {
|
||||||
val values = fillEventTypeValues(eventType)
|
val values = fillEventTypeValues(eventType)
|
||||||
@@ -239,7 +235,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
fun updateLocalEventType(eventType: EventType): Long {
|
fun updateLocalEventType(eventType: EventType): Long {
|
||||||
val selectionArgs = arrayOf(eventType.id.toString())
|
val selectionArgs = arrayOf(eventType.id.toString())
|
||||||
val values = fillEventTypeValues(eventType)
|
val values = fillEventTypeValues(eventType)
|
||||||
val selection = "$COL_TYPE_ID = ?"
|
val selection = "$COL_ID = ?"
|
||||||
val updated = mDb.update(TYPES_TABLE_NAME, values, selection, selectionArgs)
|
val updated = mDb.update(TYPES_TABLE_NAME, values, selection, selectionArgs)
|
||||||
return if (updated > 0) {
|
return if (updated > 0) {
|
||||||
eventType.id!!
|
eventType.id!!
|
||||||
@@ -299,14 +295,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getEventTypeIdWithTitle(title: String): Long {
|
fun getEventTypeIdWithTitle(title: String): Long {
|
||||||
val cols = arrayOf(COL_TYPE_ID)
|
val cols = arrayOf(COL_ID)
|
||||||
val selection = "$COL_TYPE_TITLE = ? COLLATE NOCASE"
|
val selection = "$COL_TYPE_TITLE = ? COLLATE NOCASE"
|
||||||
val selectionArgs = arrayOf(title)
|
val selectionArgs = arrayOf(title)
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
return cursor.getIntValue(COL_TYPE_ID).toLong()
|
return cursor.getIntValue(COL_ID).toLong()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
@@ -315,14 +311,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getEventTypeWithCalDAVCalendarId(calendarId: Int): EventType? {
|
fun getEventTypeWithCalDAVCalendarId(calendarId: Int): EventType? {
|
||||||
val cols = arrayOf(COL_TYPE_ID)
|
val cols = arrayOf(COL_ID)
|
||||||
val selection = "$COL_TYPE_CALDAV_CALENDAR_ID = ?"
|
val selection = "$COL_TYPE_CALDAV_CALENDAR_ID = ?"
|
||||||
val selectionArgs = arrayOf(calendarId.toString())
|
val selectionArgs = arrayOf(calendarId.toString())
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
return getEventType(cursor.getLongValue(COL_TYPE_ID))
|
return getEventType(cursor.getLongValue(COL_ID))
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
@@ -332,7 +328,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
fun getEventType(id: Long): EventType? {
|
fun getEventType(id: Long): EventType? {
|
||||||
val cols = arrayOf(COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
val cols = arrayOf(COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
||||||
val selection = "$COL_TYPE_ID = ?"
|
val selection = "$COL_ID = ?"
|
||||||
val selectionArgs = arrayOf(id.toString())
|
val selectionArgs = arrayOf(id.toString())
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
@@ -477,7 +473,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
val args = TextUtils.join(", ", deleteIds)
|
val args = TextUtils.join(", ", deleteIds)
|
||||||
val selection = "$COL_TYPE_ID IN ($args)"
|
val selection = "$COL_ID IN ($args)"
|
||||||
callback(mDb.delete(TYPES_TABLE_NAME, selection, null))
|
callback(mDb.delete(TYPES_TABLE_NAME, selection, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,11 +604,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
|
fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Long = -1L, applyTypeFilter: Boolean = false): List<Event> {
|
||||||
if (isOnMainThread()) {
|
|
||||||
Log.e("DEBUG", "dbhelper getRepeatableEventsFor")
|
|
||||||
}
|
|
||||||
val newEvents = ArrayList<Event>()
|
val newEvents = ArrayList<Event>()
|
||||||
|
|
||||||
var selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS <= $toTS AND $COL_START_TS != 0"
|
var selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS <= $toTS AND $COL_START_TS != 0"
|
||||||
if (eventId != -1L)
|
if (eventId != -1L)
|
||||||
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
|
selection += " AND $MAIN_TABLE_NAME.$COL_ID = $eventId"
|
||||||
@@ -659,7 +651,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
} else {
|
} else {
|
||||||
event.copy().apply {
|
event.copy().apply {
|
||||||
updateIsPastEvent()
|
updateIsPastEvent()
|
||||||
color = event.color
|
|
||||||
events.add(this)
|
events.add(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -767,7 +758,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
fun getRunningEvents(): List<Event> {
|
fun getRunningEvents(): List<Event> {
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
val ts = getNowSeconds()
|
val ts = getNowSeconds()
|
||||||
|
|
||||||
val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0"
|
val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0"
|
||||||
val selectionArgs = arrayOf(ts.toString(), ts.toString())
|
val selectionArgs = arrayOf(ts.toString(), ts.toString())
|
||||||
val cursor = getEventsCursor(selection, selectionArgs)
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
@@ -903,13 +893,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
fun getEventTypesSync(): ArrayList<EventType> {
|
fun getEventTypesSync(): ArrayList<EventType> {
|
||||||
val eventTypes = ArrayList<EventType>()
|
val eventTypes = ArrayList<EventType>()
|
||||||
val cols = arrayOf(COL_TYPE_ID, COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
val cols = arrayOf(COL_ID, COL_TYPE_TITLE, COL_TYPE_COLOR, COL_TYPE_CALDAV_CALENDAR_ID, COL_TYPE_CALDAV_DISPLAY_NAME, COL_TYPE_CALDAV_EMAIL)
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, "$COL_TYPE_TITLE ASC")
|
cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, "$COL_TYPE_TITLE ASC")
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getLongValue(COL_TYPE_ID)
|
val id = cursor.getLongValue(COL_ID)
|
||||||
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
val title = cursor.getStringValue(COL_TYPE_TITLE)
|
||||||
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
val color = cursor.getIntValue(COL_TYPE_COLOR)
|
||||||
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
val calendarId = cursor.getIntValue(COL_TYPE_CALDAV_CALENDAR_ID)
|
||||||
|
Reference in New Issue
Block a user