diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt index 31748e448..e82dc6940 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.activities import android.os.Bundle import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.commons.extensions.updateTextColors import kotlinx.android.synthetic.main.activity_manage_event_types.* @@ -9,6 +10,11 @@ class ManageEventTypesActivity : SimpleActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_manage_event_types) + + DBHelper.newInstance(applicationContext).getEventTypes { + + } + updateTextColors(manage_event_types_scrollview) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index ae78fe767..54db362e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -338,6 +338,33 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return events } + fun getEventTypes(callback: (types: List) -> Unit) { + Thread({ + fetchEventTypes(callback) + }).start() + } + + fun fetchEventTypes(callback: (types: List) -> Unit) { + val eventTypes = ArrayList(3) + val cols = arrayOf(COL_TYPE_ID, COL_TYPE_TITLE, COL_TYPE_COLOR) + var cursor: Cursor? = null + try { + cursor = mDb.query(TYPES_TABLE_NAME, cols, null, null, null, null, COL_TYPE_ID) + if (cursor?.moveToFirst() == true) { + do { + val id = cursor.getIntValue(COL_TYPE_ID) + val title = cursor.getStringValue(COL_TYPE_TITLE) + val color = cursor.getIntValue(COL_TYPE_COLOR) + val eventType = EventType(id, title, color) + eventTypes.add(eventType) + } while (cursor.moveToNext()) + } + } finally { + cursor?.close() + } + callback.invoke(eventTypes) + } + interface EventUpdateListener { fun eventInserted(event: Event)