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,12 +582,16 @@ class EventActivity : SimpleActivity() {
} }
private fun updateEventType() { private fun updateEventType() {
Thread {
val eventType = dbHelper.getEventType(mEventTypeId) val eventType = dbHelper.getEventType(mEventTypeId)
if (eventType != null) { if (eventType != null) {
runOnUiThread {
event_type.text = eventType.title event_type.text = eventType.title
event_type_color.setFillWithStroke(eventType.color, config.backgroundColor) event_type_color.setFillWithStroke(eventType.color, config.backgroundColor)
} }
} }
}.start()
}
private fun updateCalDAVCalendar() { private fun updateCalDAVCalendar() {
if (config.caldavSync) { if (config.caldavSync) {