Skip to content

Instantly share code, notes, and snippets.

@nadar71
Created October 21, 2020 09:41
Show Gist options
  • Save nadar71/eab4e4903b9e98635b7d57aa47e6b019 to your computer and use it in GitHub Desktop.
Save nadar71/eab4e4903b9e98635b7d57aa47e6b019 to your computer and use it in GitHub Desktop.
Show blocking alert
// generic alert
fun showGenericBlockingAlert(title: String, msg: String, activity: Activity) {
val dialogBuilder = AlertDialog.Builder(activity)
dialogBuilder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("OK") { dialog, id ->
}
val alert = dialogBuilder.create()
alert.setCancelable(false)
alert.setTitle(title)
alert.show()
}
// generic show error alert with function as a parameterof type : ()->Unit
fun showErrorAlert(errorMsg: String, activity: Activity, passedFun: () -> Unit) {
val dialogBuilder = AlertDialog.Builder(activity)
dialogBuilder.setMessage(
activity.getString(R.string.error_happened)
+ "${errorMsg} \n"
+ activity.getString(R.string.retry_later)
)
.setCancelable(false)
.setPositiveButton("OK") { dialog, id ->
passedFun()
}
val alert = dialogBuilder.create()
alert.setCancelable(false)
alert.setTitle(activity.getString(R.string.error_title))
alert.show()
}
fun showGenericBlockingAlertWithFunc(
title: String, msg: String, activity: Activity
, passedFun: () -> Unit
) {
val dialogBuilder = AlertDialog.Builder(activity)
dialogBuilder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("OK") { dialog, id ->
passedFun()
}
val alert = dialogBuilder.create()
alert.setCancelable(false)
alert.setTitle(title)
alert.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment