Skip to content

Commit

Permalink
Merge pull request #48 from PatilShreyas/version-2.2.1-dev
Browse files Browse the repository at this point in the history
Release v2.2.1
  • Loading branch information
PatilShreyas committed Apr 24, 2021
2 parents 005fe20 + 62f4094 commit bff1b81
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 342 deletions.
4 changes: 2 additions & 2 deletions MaterialDialogLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.annotation:annotation:1.2.0'

// Material Design Library
implementation 'com.google.android.material:material:1.3.0'

// Lottie Animation Library
implementation 'com.airbnb.android:lottie:3.6.0'
implementation 'com.airbnb.android:lottie:3.7.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Build;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -24,9 +26,11 @@
import dev.shreyaspatil.MaterialDialog.interfaces.OnDismissListener;
import dev.shreyaspatil.MaterialDialog.interfaces.OnShowListener;
import dev.shreyaspatil.MaterialDialog.model.DialogButton;
import dev.shreyaspatil.MaterialDialog.model.DialogText;
import dev.shreyaspatil.MaterialDialog.model.TextAlignment;

@SuppressWarnings("unused")
public class AbstractDialog implements DialogInterface {
public abstract class AbstractDialog implements DialogInterface {

//Constants
public static final int BUTTON_POSITIVE = 1;
Expand All @@ -36,23 +40,25 @@ public class AbstractDialog implements DialogInterface {

protected Dialog mDialog;
protected Activity mActivity;
protected String title;
protected String message;
protected DialogText title;
protected DialogText message;
protected boolean mCancelable;
protected DialogButton mPositiveButton;
protected DialogButton mNegativeButton;
protected int mAnimationResId;
protected String mAnimationFile;
protected LottieAnimationView mAnimationView;

protected TextAlignment mTitleTextAlignment;
protected TextAlignment mMessageTextAlignment;

protected OnDismissListener mOnDismissListener;
protected OnCancelListener mOnCancelListener;
protected OnShowListener mOnShowListener;


protected AbstractDialog(@NonNull Activity mActivity,
@NonNull String title,
@NonNull String message,
@NonNull DialogText title,
@NonNull DialogText message,
boolean mCancelable,
@NonNull DialogButton mPositiveButton,
@NonNull DialogButton mNegativeButton,
Expand Down Expand Up @@ -83,15 +89,23 @@ protected View createView(@NonNull LayoutInflater inflater, @Nullable ViewGroup
// Set Title
if (title != null) {
mTitleView.setVisibility(View.VISIBLE);
mTitleView.setText(title);
mTitleView.setText(title.getText());
mTitleView.setTextAlignment(title.getTextAlignment().getAlignment());
} else {
mTitleView.setVisibility(View.GONE);
}

// Set Message
if (message != null) {
mMessageView.setVisibility(View.VISIBLE);
mMessageView.setText(message);
Spanned spannedMessage = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
spannedMessage = Html.fromHtml(message.getText(), Html.FROM_HTML_MODE_COMPACT);
} else {
spannedMessage = Html.fromHtml(message.getText());
}
mMessageView.setText(spannedMessage);
mMessageView.setTextAlignment(message.getTextAlignment().getAlignment());
} else {
mMessageView.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -329,4 +343,157 @@ private void throwNullDialog() {
public interface OnClickListener {
void onClick(DialogInterface dialogInterface, int which);
}

/**
* Builder for {@link AbstractDialog}.
*/
public static abstract class Builder<D extends AbstractDialog> {
protected final Activity activity;
protected DialogText title;
protected DialogText message;
protected boolean isCancelable;
protected DialogButton positiveButton;
protected DialogButton negativeButton;
protected int animationResId = NO_ANIMATION;
protected String animationFile;

/**
* @param activity where Material Dialog is to be built.
*/
public Builder(@NonNull Activity activity) {
this.activity = activity;
}

/**
* @param title Sets the Title of Material Dialog with the default alignment as center.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setTitle(@NonNull String title) {
return setTitle(title, TextAlignment.CENTER);
}

/**
* @param title Sets the Title of Material Dialog.
* @param alignment Sets the Alignment for the title.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setTitle(@NonNull String title, @NonNull TextAlignment alignment) {
this.title = new DialogText(title, alignment);
return this;
}

/**
* @param message Sets the Message of Material Dialog with the default alignment as center.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setMessage(@NonNull String message) {
return setMessage(message, TextAlignment.CENTER);
}

/**
* @param message Sets the Message of Material Dialog.
* @param alignment Sets the Alignment for the message.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setMessage(@NonNull String message, @NonNull TextAlignment alignment) {
this.message = new DialogText(message, alignment);
return this;
}

/**
* @param isCancelable Sets cancelable property of Material Dialog.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setCancelable(boolean isCancelable) {
this.isCancelable = isCancelable;
return this;
}

/**
* Sets the Positive Button to Material Dialog without icon
*
* @param name sets the name/label of button.
* @param onClickListener interface for callback event on click of button.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setPositiveButton(@NonNull String name, @NonNull OnClickListener onClickListener) {
return setPositiveButton(name, NO_ICON, onClickListener);
}

/**
* Sets the Positive Button to Material Dialog with icon
*
* @param name sets the name/label of button.
* @param icon sets the resource icon for button.
* @param onClickListener interface for callback event on click of button.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setPositiveButton(@NonNull String name, int icon, @NonNull OnClickListener onClickListener) {
positiveButton = new DialogButton(name, icon, onClickListener);
return this;
}

/**
* Sets the Negative Button to Material Dialog without icon.
*
* @param name sets the name/label of button.
* @param onClickListener interface for callback event on click of button.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setNegativeButton(@NonNull String name, @NonNull OnClickListener onClickListener) {
return setNegativeButton(name, NO_ICON, onClickListener);
}

/**
* Sets the Negative Button to Material Dialog with icon
*
* @param name sets the name/label of button.
* @param icon sets the resource icon for button.
* @param onClickListener interface for callback event on click of button.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setNegativeButton(@NonNull String name, int icon, @NonNull OnClickListener onClickListener) {
negativeButton = new DialogButton(name, icon, onClickListener);
return this;
}

/**
* It sets the resource json to the {@link com.airbnb.lottie.LottieAnimationView}.
*
* @param animationResId sets the resource to {@link com.airbnb.lottie.LottieAnimationView}.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setAnimation(@RawRes int animationResId) {
this.animationResId = animationResId;
return this;
}

/**
* It sets the json file to the {@link com.airbnb.lottie.LottieAnimationView} from assets.
*
* @param fileName sets the file from assets to {@link com.airbnb.lottie.LottieAnimationView}.
* @return this, for chaining.
*/
@NonNull
public Builder<D> setAnimation(@NonNull String fileName) {
this.animationFile = fileName;
return this;
}

/**
* Builds the dialog.
*/
@NonNull
public abstract D build();
}
}

0 comments on commit bff1b81

Please sign in to comment.