mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2024-12-26 00:03:38 +01:00
move the EditEventTypeDialog confirmation handling on a background thread
This commit is contained in:
parent
895c55d72e
commit
3e05501242
@ -45,18 +45,31 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
|||||||
activity.setupDialogStuff(view, this, if (isNewEvent) R.string.add_new_type else R.string.edit_type) {
|
activity.setupDialogStuff(view, this, if (isNewEvent) R.string.add_new_type else R.string.edit_type) {
|
||||||
showKeyboard(view.type_title)
|
showKeyboard(view.type_title)
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
val title = view.type_title.value
|
Thread {
|
||||||
|
eventTypeConfirmed(view.type_title.value, this)
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupColor(view: ImageView) {
|
||||||
|
view.setFillWithStroke(eventType!!.color, activity.config.backgroundColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun eventTypeConfirmed(title: String, dialog: AlertDialog) {
|
||||||
val eventIdWithTitle = activity.dbHelper.getEventTypeIdWithTitle(title)
|
val eventIdWithTitle = activity.dbHelper.getEventTypeIdWithTitle(title)
|
||||||
var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1L
|
var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1L
|
||||||
if (!isEventTypeTitleTaken)
|
if (!isEventTypeTitleTaken) {
|
||||||
isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1L
|
isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1L
|
||||||
|
}
|
||||||
|
|
||||||
if (title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
activity.toast(R.string.title_empty)
|
activity.toast(R.string.title_empty)
|
||||||
return@setOnClickListener
|
return
|
||||||
} else if (isEventTypeTitleTaken) {
|
} else if (isEventTypeTitleTaken) {
|
||||||
activity.toast(R.string.type_already_exists)
|
activity.toast(R.string.type_already_exists)
|
||||||
return@setOnClickListener
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
eventType!!.title = title
|
eventType!!.title = title
|
||||||
@ -70,17 +83,12 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (eventType!!.id != -1L) {
|
if (eventType!!.id != -1L) {
|
||||||
dismiss()
|
activity.runOnUiThread {
|
||||||
|
dialog.dismiss()
|
||||||
callback(eventType!!)
|
callback(eventType!!)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
activity.toast(R.string.editing_calendar_failed)
|
activity.toast(R.string.editing_calendar_failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupColor(view: ImageView) {
|
|
||||||
view.setFillWithStroke(eventType!!.color, activity.config.backgroundColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user