fetch event types at the EventActivity on background threads

This commit is contained in:
tibbi 2018-11-11 23:11:58 +01:00
parent 7a6d48d9db
commit 1ca2c2d195
1 changed files with 18 additions and 13 deletions

View File

@ -17,6 +17,7 @@ import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.models.CalDAVCalendar import com.simplemobiletools.calendar.pro.models.CalDAVCalendar
import com.simplemobiletools.calendar.pro.models.Event 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.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
@ -67,19 +68,19 @@ class EventActivity : SimpleActivity() {
val eventId = intent.getLongExtra(EVENT_ID, 0L) val eventId = intent.getLongExtra(EVENT_ID, 0L)
Thread { Thread {
val event = dbHelper.getEventWithId(eventId) val event = dbHelper.getEventWithId(eventId)
if (eventId != 0L && event == null) {
finish()
return@Thread
}
val localEventType = dbHelper.getEventType(config.lastUsedLocalEventTypeId)
runOnUiThread { runOnUiThread {
gotEvent(savedInstanceState, eventId, event) gotEvent(savedInstanceState, localEventType, event)
} }
}.start() }.start()
} }
private fun gotEvent(savedInstanceState: Bundle?, eventId: Long, event: Event?) { private fun gotEvent(savedInstanceState: Bundle?, localEventType: EventType?, event: Event?) {
if (eventId != 0L && event == null) {
finish()
return
}
val localEventType = dbHelper.getEventType(config.lastUsedLocalEventTypeId)
if (localEventType == null || localEventType.caldavCalendarId != 0) { if (localEventType == null || localEventType.caldavCalendarId != 0) {
config.lastUsedLocalEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID config.lastUsedLocalEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
} }
@ -581,11 +582,15 @@ class EventActivity : SimpleActivity() {
} }
private fun updateEventType() { private fun updateEventType() {
val eventType = dbHelper.getEventType(mEventTypeId) Thread {
if (eventType != null) { val eventType = dbHelper.getEventType(mEventTypeId)
event_type.text = eventType.title if (eventType != null) {
event_type_color.setFillWithStroke(eventType.color, config.backgroundColor) runOnUiThread {
} event_type.text = eventType.title
event_type_color.setFillWithStroke(eventType.color, config.backgroundColor)
}
}
}.start()
} }
private fun updateCalDAVCalendar() { private fun updateCalDAVCalendar() {