Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.2.1 #48

Merged
merged 20 commits into from Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
76b6b72
Update gradle plugin version
PatilShreyas Apr 23, 2021
cb2292d
Add common model for Dialog text
PatilShreyas Apr 23, 2021
134ed15
Add enum for predefined Text alignments
PatilShreyas Apr 23, 2021
cd07895
Update dependencies
PatilShreyas Apr 23, 2021
cbe4a27
Refactor: Use dialog text and provide alignment for title and message
PatilShreyas Apr 23, 2021
86a4428
Refactor changes in Material and Bottom Sheet dialog
PatilShreyas Apr 23, 2021
d909da7
Add alignment demonstration in demo app
PatilShreyas Apr 23, 2021
667e9f8
Refactor: Move builder to common abstract dialog
PatilShreyas Apr 24, 2021
ab16675
Refactor: Use common dialog builder
PatilShreyas Apr 24, 2021
2626e07
Provide ScrollView for portrait alert dialog layout
PatilShreyas Apr 24, 2021
9997543
Bump library version
PatilShreyas Apr 24, 2021
5e2309e
Add support for HTML spanned text for message text
PatilShreyas Apr 24, 2021
a09b79c
Merge pull request #45 from PatilShreyas/feature/text-alignment
PatilShreyas Apr 24, 2021
f012d12
Merge pull request #46 from PatilShreyas/fix/long-message
PatilShreyas Apr 24, 2021
f9bfcc5
Merge pull request #47 from PatilShreyas/feature/html-supported-message
PatilShreyas Apr 24, 2021
31e6080
Show demo for HTML spanned text message of dialog
PatilShreyas Apr 24, 2021
b303ab9
Refactor: Use new method for `fromHtml()`
PatilShreyas Apr 24, 2021
7ca0179
Add info for new features
PatilShreyas Apr 24, 2021
9aa7c79
Update lib dependency version in demo app
PatilShreyas Apr 24, 2021
62f4094
Update doc for HTML support part
PatilShreyas Apr 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions MaterialDialogLibrary/build.gradle
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
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();
}
}