Created
October 21, 2020 09:41
-
-
Save nadar71/eab4e4903b9e98635b7d57aa47e6b019 to your computer and use it in GitHub Desktop.
Show blocking alert
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
// 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