Advertisement
BlackZerg

Untitled

Oct 28th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.45 KB | None | 0 0
  1. class MessageDialog
  2. @Inject
  3. constructor(
  4.     private val onPositiveButtonClick: () -> Unit,
  5.     private val onNegativeButtonClick: () -> Unit,
  6.     val data: DialogModel,
  7. ) : BaseDialogFragment() {
  8.  
  9.     override val blackoutBackground: Boolean = true
  10.     override val dialogPositionBottom: Boolean = true
  11.  
  12.     override fun onCreateView(
  13.         inflater: LayoutInflater,
  14.         container: ViewGroup?,
  15.         savedInstanceState: Bundle?
  16.     ): View? {
  17.         dialog?.window?.setBackgroundDrawableResource(R.drawable.dialog_parent_background)
  18.         return inflater.inflate(R.layout.message_dialog, container, false).apply {
  19.             ok.setOnClickListener {
  20.                 onPositiveButtonClick
  21.                 dialog?.cancel()
  22.             }
  23.             cancel.setOnClickListener {
  24.                 onNegativeButtonClick
  25.                 dialog?.cancel()
  26.             }
  27.             title_dialog.text = data.title
  28.             subtitle_dialog.text = data.message
  29.             ok.text = data.okText
  30.             cancel.text = data.cancelText
  31.             ok.visibility = if ( data.enableOk ) View.VISIBLE else View.GONE
  32.             cancel.visibility = if ( data.enableCancel ) View.VISIBLE else View.GONE
  33.         }
  34.     }
  35. }
  36.  
  37.  
  38.  
  39. // In fragment
  40. private val messageDialog: MessageDialog by lazy {
  41.         MessageDialog({ onPositiveClick() }, { onNegativeClick() }, logoutDialog)
  42. }
  43.  
  44. private fun onPositiveClick() {  }
  45. private fun onNegativeClick() {  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement