Skip to content

Commit

Permalink
Alert Dialog interfaces upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
britto committed Apr 15, 2020
1 parent 92452aa commit 66756b1
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Build;

import com.androidboilerplate.interfaces.OnDialogListner;
import com.androidboilerplate.interfaces.OnSingleBtnDialogListener;


/**
Expand All @@ -15,6 +16,7 @@
public class AlertDialogBuilder {
private static AlertDialogBuilder sInstance;
AlertDialog mAlertDialog;

private AlertDialogBuilder() {
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.androidboilerplate.interfaces

interface OnSingleBtnDialogListener {

fun onSingleButtonClicked()
}

0 comments on commit 66756b1

Please sign in to comment.