Skip to content

Instantly share code, notes, and snippets.

@abircse
Last active December 25, 2021 08:24
Show Gist options
  • Save abircse/2a6bbb762a90598f9c3f67f3c650d87e to your computer and use it in GitHub Desktop.
Save abircse/2a6bbb762a90598f9c3f67f3c650d87e to your computer and use it in GitHub Desktop.
A Custom Wrapper class for handle dialog & bottom sheet dialog including viewbinding.
object MyCustomDialog {
fun <V : ViewDataBinding> showCustomBottomSheetDialog(
activity: Activity,
@LayoutRes layoutId: Int,
setCancelable: Boolean = false,
onSuccess: (Dialog, V) -> Unit
) {
val layout =
DataBindingUtil.inflate<V>(LayoutInflater.from(activity), layoutId, null, false)
val dialog = BottomSheetDialog(activity, R.style.BottomDialog)
dialog.setContentView(layout.root)
dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.setCanceledOnTouchOutside(setCancelable)
dialog.setCancelable(false)
dialog.show()
onSuccess.invoke(dialog, layout)
}
fun <V : ViewDataBinding> showCustomDialog(
activity: Activity,
@LayoutRes layoutId: Int,
setCancelable: Boolean = false,
onSuccess: (Dialog, V) -> Unit
) {
val layout =
DataBindingUtil.inflate<V>(LayoutInflater.from(activity), layoutId, null, false)
val dialog = Dialog(activity)
dialog.setContentView(layout.root)
//dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.setCanceledOnTouchOutside(setCancelable)
dialog.setCancelable(false)
dialog.show()
onSuccess.invoke(dialog, layout)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment