Skip to content

Interaction

This codebase define global method for interacting with user using notification, dialog, toast, and even snackbar.

Notification

To display notification, call this method anywhere you have Context:

displayNotification(
    Variables.Main_CHANNEL,  // Channel Id when you're using it
    "Useful title",  // Title for your notification
    "Is this working?",  // Message body of your notification
    R.mipmap.ic_launcher,  // Override the icon for your notification
    notificationIntent  // Pending intent when your notification clicked!
)

Dialog

To display dialog, call this method anywhere you have Context:

displayDialog(
    "Warning!",  // title for your dialog
    "The latest star wars trilogy is trash!",  // message of your dialog
    Pair("Okay?"){ startOver() },  // Pair of positive button text and action
    Pair("Not Okay!"){ cryAllNight() }, // Pair of negative button text and action, nullable if not needed
    false,  // Does your dialog autoDismissable?
)

Snackbar

To display snackBar, call this method anywhere you have CoordinatorLayout:

binding.CLMain.displaySnackBar(
    "Do you want to close the app?",  // message inside your snackBar
    true,  // does your snackBar for a long time?
    Pair("yes") { closeApp() } // action for your snackBar, nullable if not needed
)

Toast

To display toast, call this method anywhere you have Context:

displayToast(
    "Alert! intruder inside",   // message inside your toast
    false  // does your toast for a long time?
)