From 7304d74e76e828ac72f6f46f288dfda6cb15aa85 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 11 Feb 2017 21:29:54 +0100 Subject: [PATCH] add a radio button for creating new event type --- .../calendar/dialogs/SelectEventTypeDialog.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt index e015dab42..d0d8faac9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt @@ -13,6 +13,8 @@ import kotlinx.android.synthetic.main.dialog_radio_group.view.* import java.util.* class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener { + val NEW_TYPE_ID = -2 + val dialog: AlertDialog? var wasInit = false var eventTypes = ArrayList() @@ -27,8 +29,9 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val eventTypes = it activity.runOnUiThread { eventTypes.forEach { - addRadioButton(it) + addRadioButton(it.title, it.id) } + addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID) wasInit = true } } @@ -39,17 +42,22 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val } } - private fun addRadioButton(type: EventType) { + private fun addRadioButton(title: String, typeId: Int) { val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { - text = type.title - isChecked = type.id == currEventType - id = type.id + text = title + isChecked = typeId == currEventType + id = typeId } radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) } override fun onCheckedChanged(group: RadioGroup, checkedId: Int) { - if (wasInit) { + if (!wasInit) + return + + if (checkedId == NEW_TYPE_ID) { + + } else { callback.invoke(checkedId) dialog?.dismiss() }