diff --git a/androidboilerplate/src/main/java/com/androidboilerplate/AlertDialogBuilder.java b/androidboilerplate/src/main/java/com/androidboilerplate/AlertDialogBuilder.java index 70b2b86..2071179 100755 --- a/androidboilerplate/src/main/java/com/androidboilerplate/AlertDialogBuilder.java +++ b/androidboilerplate/src/main/java/com/androidboilerplate/AlertDialogBuilder.java @@ -6,6 +6,7 @@ import android.os.Build; import com.androidboilerplate.interfaces.OnDialogListner; +import com.androidboilerplate.interfaces.OnSingleBtnDialogListener; /** @@ -15,6 +16,7 @@ public class AlertDialogBuilder { private static AlertDialogBuilder sInstance; AlertDialog mAlertDialog; + private AlertDialogBuilder() { } @@ -52,6 +54,7 @@ public void onClick(DialogInterface dialog, int which) { mAlertDialog = builder.create(); mAlertDialog.show(); } + public void showTwoButtonDialog(String title, String message, String negativeButtonText, String positiveButtonText, final String whichDialog, Context context, final OnDialogListner mDialogListner) { AlertDialog.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -70,15 +73,106 @@ public void showTwoButtonDialog(String title, String message, String negativeBut builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mDialogListner.onNegativeButtonClick(dialog); + mDialogListner.onNegativeButtonClick(whichDialog, dialog); } }); builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mDialogListner.onPositiveButtonClick(whichDialog); + mDialogListner.onPositiveButtonClick(whichDialog, dialog); + + } + }); + + mAlertDialog = builder.create(); + mAlertDialog.show(); + mAlertDialog.setCancelable(false); + } + + + public void showErrorDialog(String title, String message, String buttonText, Context context) { + + AlertDialog.Builder builder; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert); + } else { + builder = new AlertDialog.Builder(context); + } + builder.setMessage(message); + + if (title != null && title.length() > 0) { + // We can show an alert dialog with an empty title. Hence this check. + builder.setTitle(title); + } + + // Generic error dialogs are used for information only. User only clicks on OK to dismiss it. + builder.setNegativeButton(buttonText, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + + mAlertDialog = builder.create(); + mAlertDialog.show(); + } + + public void showErrorDialog(String title, String message, String buttonText, Context context, final OnSingleBtnDialogListener onSingleBtnDialogListener) { + + AlertDialog.Builder builder; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert); + } else { + builder = new AlertDialog.Builder(context); + } + builder.setMessage(message); + + if (title != null && title.length() > 0) { + // We can show an alert dialog with an empty title. Hence this check. + builder.setTitle(title); + } + + // Generic error dialogs are used for information only. User only clicks on OK to dismiss it. + builder.setNegativeButton(buttonText, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + if (onSingleBtnDialogListener != null) + onSingleBtnDialogListener.onSingleButtonClicked(); + } + }); + mAlertDialog = builder.create(); + mAlertDialog.show(); + } + + public void showErrorDialog(String title, String message, String negativeButtonText, String positiveButtonText, final String whichDialog, Context context, final OnDialogListner mDialogListener) { + AlertDialog.Builder builder; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert); + } else { + builder = new AlertDialog.Builder(context); + } + builder.setMessage(message); + + if (title != null && title.length() > 0) { + // We can show an alert dialog with an empty title. Hence this check. + builder.setTitle(title); + } + + // Generic error dialogs are used for information only. User only clicks on OK to dismiss it. + builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mDialogListener.onNegativeButtonClick(whichDialog, dialog); + } + }); + + builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mDialogListener.onPositiveButtonClick(whichDialog, dialog); } }); diff --git a/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnDialogListner.java b/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnDialogListner.java index 564b5f2..2d8a689 100755 --- a/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnDialogListner.java +++ b/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnDialogListner.java @@ -7,7 +7,7 @@ */ public interface OnDialogListner { - public void onPositiveButtonClick(String whichDialog); - public void onNegativeButtonClick(DialogInterface dialog); + public void onPositiveButtonClick(String whichDialog,DialogInterface dialog); + public void onNegativeButtonClick(String whichDialog,DialogInterface dialog); } diff --git a/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnSingleBtnDialogListener.kt b/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnSingleBtnDialogListener.kt new file mode 100644 index 0000000..bf1e073 --- /dev/null +++ b/androidboilerplate/src/main/java/com/androidboilerplate/interfaces/OnSingleBtnDialogListener.kt @@ -0,0 +1,6 @@ +package com.androidboilerplate.interfaces + +interface OnSingleBtnDialogListener { + + fun onSingleButtonClicked() +} \ No newline at end of file