Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab51dd87 authored by tibbi's avatar tibbi
Browse files

allow pressing the currently selected radio item

parent d34b0fb9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.9.7'
        propVersionName = '3.9.9'
        kotlin_version = '1.2.21'
        support_libs = '27.0.2'
    }
+9 −9
Original line number Diff line number Diff line
@@ -14,26 +14,26 @@ import kotlinx.android.synthetic.main.dialog_radio_group.view.*
import java.util.*

class RadioGroupDialog(val activity: Activity, val items: ArrayList<RadioItem>, val checkedItemId: Int = -1, val titleId: Int = 0,
                       showOKButton: Boolean = false, val cancelCallback: (() -> Unit)? = null, val callback: (newValue: Any) -> Unit)
    : RadioGroup.OnCheckedChangeListener {
    val dialog: AlertDialog
    var wasInit = false
    var selectedItemId = -1
                       showOKButton: Boolean = false, val cancelCallback: (() -> Unit)? = null, val callback: (newValue: Any) -> Unit) {
    private val dialog: AlertDialog
    private var wasInit = false
    private var selectedItemId = -1

    init {
        val view = activity.layoutInflater.inflate(R.layout.dialog_radio_group, null)
        view.dialog_radio_group.apply {
            setOnCheckedChangeListener(this@RadioGroupDialog)

            for (i in 0 until items.size) {
                val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
                    text = items[i].title
                    isChecked = items[i].id == checkedItemId
                    id = i
                    setOnClickListener { itemSelected(i) }
                }

                if (items[i].id == checkedItemId) {
                    selectedItemId = i
                }

                addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
            }
        }
@@ -42,7 +42,7 @@ class RadioGroupDialog(val activity: Activity, val items: ArrayList<RadioItem>,
                .setOnCancelListener { cancelCallback?.invoke() }

        if (selectedItemId != -1 && showOKButton) {
            builder.setPositiveButton(R.string.ok, { dialog, which -> onCheckedChanged(view.dialog_radio_group, selectedItemId) })
            builder.setPositiveButton(R.string.ok, { dialog, which -> itemSelected(selectedItemId) })
        }

        dialog = builder.create().apply {
@@ -60,7 +60,7 @@ class RadioGroupDialog(val activity: Activity, val items: ArrayList<RadioItem>,
        wasInit = true
    }

    override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
    private fun itemSelected(checkedId: Int) {
        if (wasInit) {
            callback(items[checkedId].value)
            dialog.dismiss()