mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-13 09:13:56 +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?
|
val dialog: AlertDialog?
|
||||||
var wasInit = false
|
var wasInit = false
|
||||||
var eventTypes = ArrayList<EventType>()
|
var eventTypes = ArrayList<EventType>()
|
||||||
|
var radioGroup: RadioGroup
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
|
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)
|
radioGroup.setOnCheckedChangeListener(this)
|
||||||
|
|
||||||
DBHelper.newInstance(activity).getEventTypes {
|
DBHelper.newInstance(activity).getEventTypes {
|
||||||
|
eventTypes = it
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
eventTypes = it
|
|
||||||
eventTypes.forEach {
|
eventTypes.forEach {
|
||||||
val radioButton = activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton
|
addRadioButton(it)
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
wasInit = true
|
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) {
|
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
|
||||||
if (wasInit) {
|
if (wasInit) {
|
||||||
callback.invoke(checkedId)
|
callback.invoke(checkedId)
|
||||||
|
Loading…
Reference in New Issue
Block a user