Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
• OnButtonClick Interface has an instance of SuperDialog instead of Dialog on first argument.
• added support for toggling setCancelable()
  • Loading branch information
kishannareshpal committed Dec 11, 2018
1 parent 1575c46 commit 6ec6ef4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionName "v1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
4 changes: 2 additions & 2 deletions superdialog/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.kishannareshpal'
version = '0.1.1'
version = 'v1.2'

android {
compileSdkVersion 28
Expand All @@ -12,7 +12,7 @@ android {
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "0.1.1"
versionName "v1.2"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class SuperDialog extends DialogFragment {

private boolean isShown = false;
private Context ctx;
SuperDialog superDialog;

// Components
private AnimatedIcon ai_animatedIcon;
Expand All @@ -54,6 +55,7 @@ public class SuperDialog extends DialogFragment {
private int negativeColorRes = DEFAULT;
private int cancelColorRes = DEFAULT;
private boolean isAllCaps;
private boolean cancelable;
private String title;
private String message;
private String positiveText;
Expand All @@ -69,14 +71,19 @@ public void onDismiss(DialogInterface dialog) {
}

public interface OnButtonClickListener {
void OnButtonClick(Dialog dialog, int whichButton);
void OnButtonClick(SuperDialog dialog, int whichButton);
}

public SuperDialog iconMode(int mode) {
this.iconMode = mode;
if (isShown) changeIconMode(mode);
return this;
}
public SuperDialog cancelable(boolean cancelable){
this.cancelable = cancelable;
if (isShown) changeCancelable(cancelable);
return this;
}
public SuperDialog positiveText(String positiveText) {
this.positiveText = positiveText;
if (isShown) changePositiveText(positiveText);
Expand Down Expand Up @@ -179,6 +186,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

// Init Utils
this.ctx = getActivity();
this.superDialog = this;

// Set transparent background and remove stock title decoration views.. so the round corners bg shows.
if (getDialog() != null && getDialog().getWindow() != null) {
Expand Down Expand Up @@ -245,6 +253,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
}



// Setup Cancelable
private void changeCancelable(boolean cancelable){
setCancelable(cancelable);
}

// Setup Positive Button
private void changePositiveText(String positiveText){
if (positiveText != null){
Expand All @@ -261,8 +275,10 @@ private void changeOnPositive(final OnButtonClickListener onPositive){
btn_positive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onPositive.OnButtonClick(getDialog(), POSITIVE);
getDialog().dismiss();
onPositive.OnButtonClick(superDialog, POSITIVE);
if (cancelable){
getDialog().dismiss();
}
}
});

Expand Down Expand Up @@ -303,8 +319,10 @@ private void changeOnNegative(final OnButtonClickListener onNegative){
btn_negative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onNegative.OnButtonClick(getDialog(), NEGATIVE);
getDialog().dismiss();
onNegative.OnButtonClick(superDialog, NEGATIVE);
if (cancelable) {
getDialog().dismiss();
}
}
});

Expand Down Expand Up @@ -345,8 +363,10 @@ private void changeOnCancel(final OnButtonClickListener onCancel){
btn_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onCancel.OnButtonClick(getDialog(), CANCEL);
getDialog().dismiss();
onCancel.OnButtonClick(superDialog, CANCEL);
if (cancelable) {
getDialog().dismiss();
}
}
});

Expand Down

0 comments on commit 6ec6ef4

Please sign in to comment.