Last active
October 18, 2024 15:26
-
-
Save Williamrai/68574cf5959bd0ab537aa5f0f57bda78 to your computer and use it in GitHub Desktop.
This file contains 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
// we would be writing this reptitive code multiple times for similar dialogs | |
MaterialAlertDialogBuilder(context) | |
.setTitle(R.string.confirmation_dialog_title) | |
.setMessage(R.string.confirmation_dialog_message) | |
.setIcon(R.drawable.ic_feedback) | |
.setPositiveButton("Okay") { _, _ -> | |
deleteItem() | |
} | |
.setNegativeButton("Cancel", null) | |
.setCancelable(false) | |
.show() | |
// and for the dialog with delay we would also have to do this or create this in a function with delay logic, but if we | |
// add this in function then we would have another function to maintain which we may forget later | |
MaterialAlertDialogBuilder(context) | |
.setTitle(R.string.confirmation_survey_dialog_title) | |
.setMessage(R.string.confirmation_survey_dialog_message) | |
.setIcon(R.drawable.ic_feedback) | |
.setPositiveButton("Okay") { _, _ -> | |
deleteItem() | |
} | |
.setNegativeButton("Cancel", null) | |
.setCancelable(false) | |
.show() | |
// much cleaner and also provides simple manageable functionality like delay | |
showSimpleAlertDialog { | |
title = R.string.confirmation_dialog_title | |
message = R.string.confirmation_dialog_message | |
icon = R.drawable.feedback | |
isCancellable = false | |
delayMillis = 1000 | |
positiveButton("Okay") { | |
deleteItem() | |
} | |
negativeButton("Cancel") { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment