mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2024-12-27 08:42:42 +01:00
add a function for getting event types from db
This commit is contained in:
parent
b77d71771c
commit
4d49c14f44
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -338,6 +338,33 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
return events
|
||||
}
|
||||
|
||||
fun getEventTypes(callback: (types: List<EventType>) -> Unit) {
|
||||
Thread({
|
||||
fetchEventTypes(callback)
|
||||
}).start()
|
||||
}
|
||||
|
||||
fun fetchEventTypes(callback: (types: List<EventType>) -> Unit) {
|
||||
val eventTypes = ArrayList<EventType>(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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user