fully removing the old DBHelper
This commit is contained in:
parent
6a36e4e1fd
commit
bd4687bfb3
|
@ -51,7 +51,6 @@ val Context.eventTypesDB: EventTypesDao get() = EventsDatabase.getInstance(appli
|
|||
val Context.eventRepetitionExceptionsDB: EventRepetitionExceptionsDao get() = EventsDatabase.getInstance(applicationContext).EventRepetitionExceptionsDao()
|
||||
val Context.eventsHelper: EventsHelper get() = EventsHelper(this)
|
||||
val Context.calDAVHelper: CalDAVHelper get() = CalDAVHelper(this)
|
||||
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
||||
|
||||
fun Context.updateWidgets() {
|
||||
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java))
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
package com.simplemobiletools.calendar.pro.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import androidx.collection.LongSparseArray
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventTypesDB
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getLongValue
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
|
||||
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
||||
private val MAIN_TABLE_NAME = "events"
|
||||
private val COL_ID = "id"
|
||||
private val COL_START_TS = "start_ts"
|
||||
private val COL_END_TS = "end_ts"
|
||||
private val COL_TITLE = "title"
|
||||
private val COL_LOCATION = "location"
|
||||
private val COL_DESCRIPTION = "description"
|
||||
private val COL_REMINDER_MINUTES = "reminder_minutes"
|
||||
private val COL_REMINDER_MINUTES_2 = "reminder_minutes_2"
|
||||
private val COL_REMINDER_MINUTES_3 = "reminder_minutes_3"
|
||||
private val COL_IMPORT_ID = "import_id"
|
||||
private val COL_FLAGS = "flags"
|
||||
private val COL_EVENT_TYPE = "event_type"
|
||||
private val COL_LAST_UPDATED = "last_updated"
|
||||
private val COL_EVENT_SOURCE = "event_source"
|
||||
private val COL_PARENT_EVENT_ID = "event_parent_id"
|
||||
|
||||
private val mDb = writableDatabase
|
||||
|
||||
companion object {
|
||||
private const val DB_VERSION = 1
|
||||
const val DB_NAME = "events_old.db"
|
||||
var dbInstance: DBHelper? = null
|
||||
|
||||
fun newInstance(context: Context): DBHelper {
|
||||
if (dbInstance == null)
|
||||
dbInstance = DBHelper(context)
|
||||
|
||||
return dbInstance!!
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_START_TS INTEGER, $COL_END_TS INTEGER, " +
|
||||
"$COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER, $COL_REMINDER_MINUTES_2 INTEGER, $COL_REMINDER_MINUTES_3 INTEGER, " +
|
||||
"$COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER, $COL_EVENT_TYPE INTEGER NOT NULL DEFAULT $REGULAR_EVENT_TYPE_ID, " +
|
||||
"$COL_PARENT_EVENT_ID INTEGER, $COL_LAST_UPDATED INTEGER, $COL_EVENT_SOURCE TEXT, $COL_LOCATION TEXT)")
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
||||
|
||||
private fun getEventsCursor(selection: String = "", selectionArgs: Array<String>? = null): Cursor? {
|
||||
return mDb.query(MAIN_TABLE_NAME, allColumns, selection, selectionArgs, null, null, COL_START_TS)
|
||||
}
|
||||
|
||||
private val allColumns: Array<String>
|
||||
get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REMINDER_MINUTES_2,
|
||||
COL_REMINDER_MINUTES_3, COL_IMPORT_ID, COL_FLAGS, COL_EVENT_TYPE, COL_LAST_UPDATED, COL_EVENT_SOURCE, COL_LOCATION)
|
||||
|
||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||
val eventTypeColors = LongSparseArray<Int>()
|
||||
context.eventTypesDB.getEventTypes().forEach {
|
||||
eventTypeColors.put(it.id!!, it.color)
|
||||
}
|
||||
|
||||
val events = ArrayList<Event>()
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
val id = cursor.getLongValue(COL_ID)
|
||||
val startTS = cursor.getLongValue(COL_START_TS)
|
||||
val endTS = cursor.getLongValue(COL_END_TS)
|
||||
val reminder1Minutes = cursor.getIntValue(COL_REMINDER_MINUTES)
|
||||
val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2)
|
||||
val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3)
|
||||
val repeatInterval = 0
|
||||
val repeatRule = 0
|
||||
val repeatLimit = 0L
|
||||
val title = cursor.getStringValue(COL_TITLE)
|
||||
val location = cursor.getStringValue(COL_LOCATION)
|
||||
val description = cursor.getStringValue(COL_DESCRIPTION)
|
||||
val importId = cursor.getStringValue(COL_IMPORT_ID) ?: ""
|
||||
val flags = cursor.getIntValue(COL_FLAGS)
|
||||
val eventType = cursor.getLongValue(COL_EVENT_TYPE)
|
||||
val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED)
|
||||
val source = cursor.getStringValue(COL_EVENT_SOURCE)
|
||||
|
||||
val event = Event(id, startTS, endTS, title, location, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
||||
repeatInterval, repeatRule, repeatLimit, importId, flags, eventType, 0, lastUpdated, source)
|
||||
|
||||
events.add(event)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
return events
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue