mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2024-12-26 08:13:07 +01:00
add a helper function for filling SelectEventTypeDialog
This commit is contained in:
parent
8783b674a7
commit
31cff330a6
@ -16,23 +16,18 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val
|
||||
val dialog: AlertDialog?
|
||||
var wasInit = false
|
||||
var eventTypes = ArrayList<EventType>()
|
||||
var radioGroup: RadioGroup
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
|
||||
val radioGroup = view.dialog_radio_group
|
||||
radioGroup = view.dialog_radio_group
|
||||
radioGroup.setOnCheckedChangeListener(this)
|
||||
|
||||
DBHelper.newInstance(activity).getEventTypes {
|
||||
activity.runOnUiThread {
|
||||
eventTypes = it
|
||||
activity.runOnUiThread {
|
||||
eventTypes.forEach {
|
||||
val radioButton = activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton
|
||||
radioButton.apply {
|
||||
text = it.title
|
||||
isChecked = it.id == currEventType
|
||||
id = it.id
|
||||
}
|
||||
radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
addRadioButton(it)
|
||||
}
|
||||
wasInit = true
|
||||
}
|
||||
@ -44,6 +39,15 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRadioButton(type: EventType) {
|
||||
val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
|
||||
text = type.title
|
||||
isChecked = type.id == currEventType
|
||||
id = type.id
|
||||
}
|
||||
radioGroup.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
}
|
||||
|
||||
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
|
||||
if (wasInit) {
|
||||
callback.invoke(checkedId)
|
||||
|
Loading…
Reference in New Issue
Block a user