Skip to content

Instantly share code, notes, and snippets.

@Audhil
Last active April 17, 2018 10:49
Show Gist options
  • Save Audhil/31e7165d4428490f42e00263454f35c3 to your computer and use it in GitHub Desktop.
Save Audhil/31e7165d4428490f42e00263454f35c3 to your computer and use it in GitHub Desktop.
Making custom alert dialogs with Kotlin extension functions
/*
* Notes Dialog
*/
inline fun Activity.showNotesAlertDialog(func: NotesDialogHelper.() -> Unit): AlertDialog =
NotesDialogHelper(this).apply {
func()
}.create()
inline fun Fragment.showNotesAlertDialog(func: NotesDialogHelper.() -> Unit): AlertDialog =
NotesDialogHelper(this.context!!).apply {
func()
}.create()
/*
* TimeChooser Dialog
*/
inline fun Activity.showTimeChooserAlertDialog(func: TimeChooserDialogHelper.() -> Unit): AlertDialog =
TimeChooserDialogHelper(this).apply {
func()
}.create()
inline fun Fragment.showTimeChooserAlertDialog(func: TimeChooserDialogHelper.() -> Unit): AlertDialog =
TimeChooserDialogHelper(this.context!!).apply {
func()
}.create()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment