Last active
December 25, 2021 08:24
-
-
Save abircse/2a6bbb762a90598f9c3f67f3c650d87e to your computer and use it in GitHub Desktop.
A Custom Wrapper class for handle dialog & bottom sheet dialog including viewbinding.
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
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