Skip to content

Instantly share code, notes, and snippets.

@Audhil
Last active April 17, 2018 12:33
Show Gist options
  • Save Audhil/fe6eebc9a3ecc8528b549c9fc347919c to your computer and use it in GitHub Desktop.
Save Audhil/fe6eebc9a3ecc8528b549c9fc347919c to your computer and use it in GitHub Desktop.
AlertDialogs with Extn funcs blog_2
abstract class BaseDialogHelper {
abstract val dialogView: View
abstract val builder: AlertDialog.Builder
// required bools
open var cancelable: Boolean = true
open var isBackGroundTransparent: Boolean = true
// dialog
open var dialog: AlertDialog? = null
// dialog create
open fun create(): AlertDialog {
dialog = builder
.setCancelable(cancelable)
.create()
// very much needed for customised dialogs
if (isBackGroundTransparent)
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
return dialog!!
}
// cancel listener
open fun onCancelListener(func: () -> Unit): AlertDialog.Builder? =
builder.setOnCancelListener {
func()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment