var icon: Int? = null var title: String? = null var message: String? = null var positiveButtonText: String? = null var negativeButtonText: String? = null var checkBoxText: String? = null
title = bundle.getString(TITLE_KEY, "") if (title != "") alertDialog.setTitle(title)
message = bundle.getString(MESSAGE_KEY, "") if (message != "") alertDialog.setMessage(Html.fromHtml(message))
positiveButtonText = bundle.getString(POSITIVE_BUTTON_TEXT_KEY) if (positiveButtonText != "") { alertDialog.setPositiveButton(positiveButtonText) { dialog, which -> listener.onDialogPositiveClick(this) } }
negativeButtonText = bundle.getString(NEGATIVE_BUTTON_TEXT_KEY) if (negativeButtonText != "") { alertDialog.setNegativeButton(negativeButtonText) { dialog, which -> listener.onDialogNegativeClick(this) } }
checkBoxText = bundle.getString(CHECK_BOX_TEXT_KEY) checkBoxText?.let { val inflater = requireActivity().layoutInflater val root = inflater.inflate(R.layout.dialog_alert_custom, null) val checkBox = root.findViewById<CheckBox>(R.id.checkbox) checkBox.text = it checkBox.setOnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean -> listener.onDialogCheckBoxChange(isChecked) } alertDialog.setView(root) } }
return alertDialog.create() }
overridefunonStart() { super.onStart() val alertDialog = dialog as AlertDialog? if (alertDialog != null) (alertDialog.findViewById<View>(android.R.id.message) as TextView).movementMethod = LinkMovementMethod.getInstance() } }