Skip to content

Commit 1d907bd

Browse files
authored
Merge pull request #50 from PatilShreyas/hotfix/v2.2.2
[Hotfix] Release v2.2.2
2 parents bff1b81 + 2d79eda commit 1d907bd

File tree

10 files changed

+110
-39
lines changed

10 files changed

+110
-39
lines changed

MaterialDialogLibrary/src/main/java/dev/shreyaspatil/MaterialDialog/AbstractDialog.java

+34-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.content.res.Configuration;
77
import android.content.res.TypedArray;
88
import android.os.Build;
9-
import android.text.Html;
109
import android.text.Spanned;
1110
import android.view.LayoutInflater;
1211
import android.view.View;
@@ -26,7 +25,8 @@
2625
import dev.shreyaspatil.MaterialDialog.interfaces.OnDismissListener;
2726
import dev.shreyaspatil.MaterialDialog.interfaces.OnShowListener;
2827
import dev.shreyaspatil.MaterialDialog.model.DialogButton;
29-
import dev.shreyaspatil.MaterialDialog.model.DialogText;
28+
import dev.shreyaspatil.MaterialDialog.model.DialogMessage;
29+
import dev.shreyaspatil.MaterialDialog.model.DialogTitle;
3030
import dev.shreyaspatil.MaterialDialog.model.TextAlignment;
3131

3232
@SuppressWarnings("unused")
@@ -40,8 +40,8 @@ public abstract class AbstractDialog implements DialogInterface {
4040

4141
protected Dialog mDialog;
4242
protected Activity mActivity;
43-
protected DialogText title;
44-
protected DialogText message;
43+
protected DialogTitle title;
44+
protected DialogMessage message;
4545
protected boolean mCancelable;
4646
protected DialogButton mPositiveButton;
4747
protected DialogButton mNegativeButton;
@@ -57,8 +57,8 @@ public abstract class AbstractDialog implements DialogInterface {
5757
protected OnShowListener mOnShowListener;
5858

5959
protected AbstractDialog(@NonNull Activity mActivity,
60-
@NonNull DialogText title,
61-
@NonNull DialogText message,
60+
@NonNull DialogTitle title,
61+
@NonNull DialogMessage message,
6262
boolean mCancelable,
6363
@NonNull DialogButton mPositiveButton,
6464
@NonNull DialogButton mNegativeButton,
@@ -98,13 +98,8 @@ protected View createView(@NonNull LayoutInflater inflater, @Nullable ViewGroup
9898
// Set Message
9999
if (message != null) {
100100
mMessageView.setVisibility(View.VISIBLE);
101-
Spanned spannedMessage = null;
102-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
103-
spannedMessage = Html.fromHtml(message.getText(), Html.FROM_HTML_MODE_COMPACT);
104-
} else {
105-
spannedMessage = Html.fromHtml(message.getText());
106-
}
107-
mMessageView.setText(spannedMessage);
101+
102+
mMessageView.setText(message.getText());
108103
mMessageView.setTextAlignment(message.getTextAlignment().getAlignment());
109104
} else {
110105
mMessageView.setVisibility(View.GONE);
@@ -349,8 +344,8 @@ public interface OnClickListener {
349344
*/
350345
public static abstract class Builder<D extends AbstractDialog> {
351346
protected final Activity activity;
352-
protected DialogText title;
353-
protected DialogText message;
347+
protected DialogTitle title;
348+
protected DialogMessage message;
354349
protected boolean isCancelable;
355350
protected DialogButton positiveButton;
356351
protected DialogButton negativeButton;
@@ -380,12 +375,12 @@ public Builder<D> setTitle(@NonNull String title) {
380375
*/
381376
@NonNull
382377
public Builder<D> setTitle(@NonNull String title, @NonNull TextAlignment alignment) {
383-
this.title = new DialogText(title, alignment);
378+
this.title = new DialogTitle(title, alignment);
384379
return this;
385380
}
386381

387382
/**
388-
* @param message Sets the Message of Material Dialog with the default alignment as center.
383+
* @param message Sets the plain text Message of Material Dialog with the default alignment as center.
389384
* @return this, for chaining.
390385
*/
391386
@NonNull
@@ -394,13 +389,33 @@ public Builder<D> setMessage(@NonNull String message) {
394389
}
395390

396391
/**
397-
* @param message Sets the Message of Material Dialog.
392+
* @param message Sets the plain text Message of Material Dialog.
398393
* @param alignment Sets the Alignment for the message.
399394
* @return this, for chaining.
400395
*/
401396
@NonNull
402397
public Builder<D> setMessage(@NonNull String message, @NonNull TextAlignment alignment) {
403-
this.message = new DialogText(message, alignment);
398+
this.message = DialogMessage.text(message, alignment);
399+
return this;
400+
}
401+
402+
/**
403+
* @param message Sets the spanned text Message of Material Dialog with the default alignment as center.
404+
* @return this, for chaining.
405+
*/
406+
@NonNull
407+
public Builder<D> setMessage(@NonNull Spanned message) {
408+
return setMessage(message, TextAlignment.CENTER);
409+
}
410+
411+
/**
412+
* @param message Sets the spanned text Message of Material Dialog.
413+
* @param alignment Sets the Alignment for the message.
414+
* @return this, for chaining.
415+
*/
416+
@NonNull
417+
public Builder<D> setMessage(@NonNull Spanned message, @NonNull TextAlignment alignment) {
418+
this.message = DialogMessage.spanned(message, alignment);
404419
return this;
405420
}
406421

MaterialDialogLibrary/src/main/java/dev/shreyaspatil/MaterialDialog/BottomSheetMaterialDialog.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import com.google.android.material.bottomsheet.BottomSheetBehavior;
1919

2020
import dev.shreyaspatil.MaterialDialog.model.DialogButton;
21-
import dev.shreyaspatil.MaterialDialog.model.DialogText;
21+
import dev.shreyaspatil.MaterialDialog.model.DialogMessage;
22+
import dev.shreyaspatil.MaterialDialog.model.DialogTitle;
2223

2324
/**
2425
* Creates BottomSheet Material Dialog with 2 buttons.
@@ -29,8 +30,8 @@
2930
public final class BottomSheetMaterialDialog extends AbstractDialog {
3031

3132
private BottomSheetMaterialDialog(@NonNull final Activity mActivity,
32-
@NonNull DialogText title,
33-
@NonNull DialogText message,
33+
@NonNull DialogTitle title,
34+
@NonNull DialogMessage message,
3435
boolean mCancelable,
3536
@NonNull DialogButton mPositiveButton,
3637
@NonNull DialogButton mNegativeButton,

MaterialDialogLibrary/src/main/java/dev/shreyaspatil/MaterialDialog/MaterialDialog.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import androidx.appcompat.app.AlertDialog;
1010

1111
import dev.shreyaspatil.MaterialDialog.model.DialogButton;
12-
import dev.shreyaspatil.MaterialDialog.model.DialogText;
12+
import dev.shreyaspatil.MaterialDialog.model.DialogMessage;
13+
import dev.shreyaspatil.MaterialDialog.model.DialogTitle;
1314

1415
/**
1516
* Creates a Material Dialog with 2 buttons.
@@ -20,8 +21,8 @@
2021
public final class MaterialDialog extends AbstractDialog {
2122

2223
private MaterialDialog(@NonNull final Activity mActivity,
23-
@NonNull DialogText title,
24-
@NonNull DialogText message,
24+
@NonNull DialogTitle title,
25+
@NonNull DialogMessage message,
2526
boolean mCancelable,
2627
@NonNull DialogButton mPositiveButton,
2728
@NonNull DialogButton mNegativeButton,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package dev.shreyaspatil.MaterialDialog.model;
2+
3+
import android.text.Spanned;
4+
5+
public abstract class DialogMessage<T extends CharSequence> {
6+
private final TextAlignment textAlignment;
7+
8+
private DialogMessage(TextAlignment textAlignment) {
9+
this.textAlignment = textAlignment;
10+
}
11+
12+
public static SpannedMessage spanned(Spanned text, TextAlignment alignment) {
13+
return new SpannedMessage(text, alignment);
14+
}
15+
16+
public static TextMessage text(String text, TextAlignment alignment) {
17+
return new TextMessage(text, alignment);
18+
}
19+
20+
public TextAlignment getTextAlignment() {
21+
return textAlignment;
22+
}
23+
24+
public abstract T getText();
25+
26+
public static class SpannedMessage extends DialogMessage<Spanned> {
27+
28+
private final Spanned text;
29+
30+
SpannedMessage(Spanned text, TextAlignment textAlignment) {
31+
super(textAlignment);
32+
this.text = text;
33+
}
34+
35+
@Override
36+
public Spanned getText() {
37+
return text;
38+
}
39+
}
40+
41+
public static class TextMessage extends DialogMessage<String> {
42+
43+
private final String text;
44+
45+
TextMessage(String text, TextAlignment textAlignment) {
46+
super(textAlignment);
47+
this.text = text;
48+
}
49+
50+
@Override
51+
public String getText() {
52+
return text;
53+
}
54+
}
55+
}

MaterialDialogLibrary/src/main/java/dev/shreyaspatil/MaterialDialog/model/DialogText.java renamed to MaterialDialogLibrary/src/main/java/dev/shreyaspatil/MaterialDialog/model/DialogTitle.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package dev.shreyaspatil.MaterialDialog.model;
22

3-
public class DialogText {
3+
public class DialogTitle {
44
private final String text;
55
private final TextAlignment textAlignment;
66

7-
public DialogText(String text, TextAlignment textAlignment) {
7+
public DialogTitle(String text, TextAlignment textAlignment) {
88
this.text = text;
99
this.textAlignment = textAlignment;
1010
}

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ If it's not provided in builder, `TextAlignment.CENTER` is considered by default
218218

219219
### HTML formatting for Message
220220

221-
HTML span formatting is supported only for dialog's ***message***. While setting a message, you can directly provide formatted string as shown in following example.
221+
HTML spanned text is supported only for dialog's ***message***. While setting a message, you can directly provide `Spanned` instance as shown in following example.
222222

223223
```java
224224
MaterialDialog mDialog = new MaterialDialog.Builder(this)
225-
.setMessage("<b>Lorem <i>Ipsum</i></b>. Click <a href=\"https://example.com\">here</a> for more information")
225+
.setMessage(Html.fromText("<b>Lorem <i>Ipsum</i></b>. <br> Click <a href=\"https://example.com\">here</a> for more information"))
226226
```
227227

228228
<a name="showAnims"></a>
@@ -256,9 +256,7 @@ Prototype :
256256
Resource file should be passed to method. e.g. `R.raw.delete_anim`.
257257
```java
258258
MaterialButton mDialog = new MaterialDialog.Builder(this)
259-
// Other Methods to create Dialog........
260-
.setAnimation(R.raw.delete_anim)
261-
//...
259+
.setAnimation(R.raw.delete_anim)
262260
```
263261
<a name="showAnimFile"></a>
264262
#### ii. Using `Asset` File

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies {
2424
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
2525

2626
// Material Dialog Library
27-
implementation 'dev.shreyaspatil.MaterialDialog:MaterialDialog:2.2.1'
27+
implementation 'dev.shreyaspatil.MaterialDialog:MaterialDialog:2.2.2'
2828

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

app/src/main/java/dev/shreyaspatil/MaterialDialogExample/MainActivity.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.SuppressLint;
44
import android.os.Bundle;
5+
import android.text.Html;
56
import android.view.View;
67
import android.widget.Button;
78
import android.widget.Toast;
@@ -36,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
3637
// Simple Material Dialog
3738
mSimpleDialog = new MaterialDialog.Builder(this)
3839
.setTitle("Delete?", TextAlignment.START)
39-
.setMessage("Are you sure want to <i>delete this file</i>?", TextAlignment.START)
40+
.setMessage(Html.fromHtml("Are you sure want to <i>delete this file</i>?"), TextAlignment.START)
4041
.setCancelable(false)
4142
.setPositiveButton("Delete", R.drawable.ic_delete, new MaterialDialog.OnClickListener() {
4243
@Override
@@ -57,7 +58,7 @@ public void onClick(DialogInterface dialogInterface, int which) {
5758
// Simple BottomSheet Material Dialog
5859
mSimpleBottomSheetDialog = new BottomSheetMaterialDialog.Builder(this)
5960
.setTitle("Delete?", TextAlignment.CENTER)
60-
.setMessage("Are you sure want to <i>delete this file</i>?", TextAlignment.CENTER)
61+
.setMessage("Are you sure want to delete this file?", TextAlignment.CENTER)
6162
.setCancelable(false)
6263
.setPositiveButton("Delete", R.drawable.ic_delete, new BottomSheetMaterialDialog.OnClickListener() {
6364
@Override
@@ -78,7 +79,7 @@ public void onClick(DialogInterface dialogInterface, int which) {
7879
// Animated Simple Material Dialog
7980
mAnimatedDialog = new MaterialDialog.Builder(this)
8081
.setTitle("Delete?")
81-
.setMessage("Are you sure want to <i>delete this file</i>?")
82+
.setMessage("Are you sure want to delete this file?")
8283
.setCancelable(false)
8384
.setPositiveButton("Delete", R.drawable.ic_delete, new MaterialDialog.OnClickListener() {
8485
@Override
@@ -100,7 +101,7 @@ public void onClick(DialogInterface dialogInterface, int which) {
100101
// Animated BottomSheet Material Dialog
101102
mAnimatedBottomSheetDialog = new BottomSheetMaterialDialog.Builder(this)
102103
.setTitle("Delete?")
103-
.setMessage("Are you sure want to <i>delete this file</i>?")
104+
.setMessage("Are you sure want to delete this file?")
104105
.setCancelable(false)
105106
.setPositiveButton("Delete", R.drawable.ic_delete, new BottomSheetMaterialDialog.OnClickListener() {
106107
@Override

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:4.1.3'
1111

12-
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.1'
12+
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2'
1313
}
1414
}
1515

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ android.enableJetifier=true
2020
# Maven Publish Details
2121
GROUP=dev.shreyaspatil.MaterialDialog
2222
POM_ARTIFACT_ID=MaterialDialog
23-
VERSION_NAME=2.2.0
23+
VERSION_NAME=2.2.2
2424
POM_NAME=MaterialDialog-Android
2525
POM_DESCRIPTION=Android Library to implement animated, beautiful, stylish Material Dialog in android apps easily.
2626
POM_INCEPTION_YEAR=2021

0 commit comments

Comments
 (0)