Last active
April 17, 2018 13:31
-
-
Save Audhil/e70492fa4ee0b471c3d1aba77a82ce1b to your computer and use it in GitHub Desktop.
AlertDialogs with Extn funcs blog_3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotesDialogHelper(context: Context) : BaseDialogHelper() { | |
// dialog view | |
override val dialogView: View by lazy { | |
LayoutInflater.from(context).inflate(R.layout.notes_dialog, null) | |
} | |
override val builder: AlertDialog.Builder = AlertDialog.Builder(context).setView(dialogView) | |
// notes edit text | |
val eText: TextInputEditText by lazy { | |
dialogView.findViewById<TextInputEditText>(R.id.notes_etxt_view) | |
} | |
// done icon | |
private val doneIcon: ImageView by lazy { | |
dialogView.findViewById<ImageView>(R.id.done_icon) | |
} | |
// close icon | |
private val closeIcon: ImageView by lazy { | |
dialogView.findViewById<ImageView>(R.id.close_icon) | |
} | |
// closeIconClickListener with listener | |
fun closeIconClickListener(func: (() -> Unit)? = null) = | |
with(closeIcon) { | |
setClickListenerToDialogIcon(func) | |
} | |
// doneIconClickListener with listener | |
fun doneIconClickListener(func: (() -> Unit)? = null) = | |
with(doneIcon) { | |
setClickListenerToDialogIcon(func) | |
} | |
// view click listener as extension function | |
private fun View.setClickListenerToDialogIcon(func: (() -> Unit)?) = | |
setOnClickListener { | |
func?.invoke() | |
dialog?.dismiss() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment