kkkk

 class ApplicationObserver : LifecycleEventObserver {

  fun showAlertDialog(
    pTitle: String?,
pMessage: String?,
pContext: Context?,
pOkListener: DialogInterface.OnClickListener? = null,
pCancelListener: DialogInterface.OnClickListener? = null,
pPositiveButton: String? = "",
pNegativeButton: String? = "",
) {
if (pContext != null) {
if (mAlertDialog == null || !mAlertDialog!!.isShowing) {
mAlertDialog =
AlertDialog.Builder(
ContextThemeWrapper(
pContext,
R.style.AlertDialogCustom
)
)
.create()
if (pTitle == null) {
with(mAlertDialog) { this?.setTitle(pContext.getString(R.string.app_name)) }
} else {
with(mAlertDialog) { this?.setTitle(pTitle) }
}
mAlertDialog!!.setMessage(pMessage)
mAlertDialog!!.setCancelable(false)
var positiveText: String? = pContext.getString(R.string.lms_ok_message)
mAlertDialog.run {
if (pPositiveButton != null && pPositiveButton.isNotEmpty()) {
positiveText = pPositiveButton
}
this!!.setButton(DialogInterface.BUTTON_POSITIVE, positiveText, pOkListener)
if ((pNegativeButton != null && pNegativeButton.isNotEmpty()) || pCancelListener != null) {
this.setButton(
DialogInterface.BUTTON_NEGATIVE,
pNegativeButton ?: pContext.getString(R.string.lms_cancel_message),
pCancelListener
)
}
show()
}
}
}
}

Rajeshbhatt12

My name is Rajesh Bhatt. I am working as a senior android developer . I have created this blog for kotlin ,java and Android Development interview questions etc..

Previous Post Next Post