From 1ca2c2d195f384f12d3a7a516f9aab8fb02700b1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 11 Nov 2018 23:11:58 +0100 Subject: [PATCH] fetch event types at the EventActivity on background threads --- .../calendar/pro/activities/EventActivity.kt | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index 08653f6cb..dcb021226 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -17,6 +17,7 @@ import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.models.CalDAVCalendar import com.simplemobiletools.calendar.pro.models.Event +import com.simplemobiletools.calendar.pro.models.EventType import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* @@ -67,19 +68,19 @@ class EventActivity : SimpleActivity() { val eventId = intent.getLongExtra(EVENT_ID, 0L) Thread { val event = dbHelper.getEventWithId(eventId) + if (eventId != 0L && event == null) { + finish() + return@Thread + } + + val localEventType = dbHelper.getEventType(config.lastUsedLocalEventTypeId) runOnUiThread { - gotEvent(savedInstanceState, eventId, event) + gotEvent(savedInstanceState, localEventType, event) } }.start() } - private fun gotEvent(savedInstanceState: Bundle?, eventId: Long, event: Event?) { - if (eventId != 0L && event == null) { - finish() - return - } - - val localEventType = dbHelper.getEventType(config.lastUsedLocalEventTypeId) + private fun gotEvent(savedInstanceState: Bundle?, localEventType: EventType?, event: Event?) { if (localEventType == null || localEventType.caldavCalendarId != 0) { config.lastUsedLocalEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID } @@ -581,11 +582,15 @@ class EventActivity : SimpleActivity() { } private fun updateEventType() { - val eventType = dbHelper.getEventType(mEventTypeId) - if (eventType != null) { - event_type.text = eventType.title - event_type_color.setFillWithStroke(eventType.color, config.backgroundColor) - } + Thread { + val eventType = dbHelper.getEventType(mEventTypeId) + if (eventType != null) { + runOnUiThread { + event_type.text = eventType.title + event_type_color.setFillWithStroke(eventType.color, config.backgroundColor) + } + } + }.start() } private fun updateCalDAVCalendar() {