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 c42376107..68d5802b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventTypeDialog.kt @@ -1,39 +1,42 @@ package com.simplemobiletools.calendar.dialogs import android.app.Activity +import android.graphics.Color import android.support.v7.app.AlertDialog import android.view.ViewGroup import android.widget.RadioButton import android.widget.RadioGroup import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.extensions.hideKeyboard +import com.simplemobiletools.commons.extensions.setBackgroundWithStroke import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.updateTextColors import kotlinx.android.synthetic.main.dialog_radio_group.view.* +import kotlinx.android.synthetic.main.radio_button_with_color.view.* import java.util.* -class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener { +class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val callback: (checkedId: Int) -> Unit) { val NEW_TYPE_ID = -2 val dialog: AlertDialog? + val radioGroup: RadioGroup var wasInit = false var eventTypes = ArrayList() - var radioGroup: RadioGroup init { val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null) as ViewGroup radioGroup = view.dialog_radio_group - radioGroup.setOnCheckedChangeListener(this) DBHelper.newInstance(activity).getEventTypes { eventTypes = it activity.runOnUiThread { eventTypes.forEach { - addRadioButton(it.title, it.id) + addRadioButton(it.title, it.id, it.color) } - addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID) + addRadioButton(activity.getString(R.string.add_new_type), NEW_TYPE_ID, Color.TRANSPARENT) wasInit = true activity.updateTextColors(view.dialog_radio_holder) } @@ -45,27 +48,33 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val } } - private fun addRadioButton(title: String, typeId: Int) { - val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { + private fun addRadioButton(title: String, typeId: Int, color: Int) { + val view = activity.layoutInflater.inflate(R.layout.radio_button_with_color, null) + (view.dialog_radio_button as RadioButton).apply { text = title isChecked = typeId == currEventType id = typeId } - radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) + + if (color != Color.TRANSPARENT) + view.dialog_radio_color.setBackgroundWithStroke(color, activity.config.backgroundColor) + + view.setOnClickListener { viewClicked(typeId) } + radioGroup.addView(view, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) } - override fun onCheckedChanged(group: RadioGroup, checkedId: Int) { + fun viewClicked(typeId: Int) { if (!wasInit) return - if (checkedId == NEW_TYPE_ID) { + if (typeId == NEW_TYPE_ID) { NewEventTypeDialog(activity) { callback.invoke(it) activity.hideKeyboard() dialog?.dismiss() } } else { - callback.invoke(checkedId) + callback.invoke(typeId) dialog?.dismiss() } } diff --git a/app/src/main/res/layout/radio_button_with_color.xml b/app/src/main/res/layout/radio_button_with_color.xml new file mode 100644 index 000000000..7bdafd4da --- /dev/null +++ b/app/src/main/res/layout/radio_button_with_color.xml @@ -0,0 +1,27 @@ + + + + + + + +