Skip to content

Commit a471501

Browse files
committed
Add spannable support for tutorial
Replace string with char sequence for title, subtitle and description.
1 parent b130564 commit a471501

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/tutorial/DynamicTutorial.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import android.os.Parcel;
2020
import android.os.Parcelable;
21+
import android.text.TextUtils;
2122

2223
import androidx.annotation.ColorInt;
2324
import androidx.annotation.DrawableRes;
@@ -52,17 +53,17 @@ public class DynamicTutorial implements Parcelable,
5253
/**
5354
* Title used by this tutorial.
5455
*/
55-
private String title;
56+
private CharSequence title;
5657

5758
/**
5859
* Subtitle used by this tutorial.
5960
*/
60-
private String subtitle;
61+
private CharSequence subtitle;
6162

6263
/**
6364
* Description used by this tutorial.
6465
*/
65-
private String description;
66+
private CharSequence description;
6667

6768
/**
6869
* Image resource used by this tutorial.
@@ -100,7 +101,7 @@ public class DynamicTutorial implements Parcelable,
100101
* @param imageRes The image resource for this tutorial.
101102
*/
102103
public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
103-
@Nullable String title, @Nullable String description, @DrawableRes int imageRes) {
104+
@Nullable CharSequence title, @Nullable CharSequence description, @DrawableRes int imageRes) {
104105
this(id, color, tintColor, title, null, description, imageRes);
105106
}
106107

@@ -116,8 +117,8 @@ public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
116117
* @param imageRes The image resource for this tutorial.
117118
*/
118119
public DynamicTutorial(int id, @ColorInt int color,
119-
@ColorInt int tintColor, @Nullable String title, @Nullable String subtitle,
120-
@Nullable String description, @DrawableRes int imageRes) {
120+
@ColorInt int tintColor, @Nullable CharSequence title, @Nullable CharSequence subtitle,
121+
@Nullable CharSequence description, @DrawableRes int imageRes) {
121122
this(id, color, tintColor, title, subtitle, description,
122123
imageRes, false);
123124
}
@@ -135,7 +136,7 @@ public DynamicTutorial(int id, @ColorInt int color,
135136
* @param tintImage {@code true} to tint the image according to the tint color.
136137
*/
137138
public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
138-
@Nullable String title, @Nullable String subtitle, @Nullable String description,
139+
@Nullable CharSequence title, @Nullable CharSequence subtitle, @Nullable CharSequence description,
139140
@DrawableRes int imageRes, boolean tintImage) {
140141
this(id, color, tintColor, title, subtitle, description,
141142
imageRes, tintImage, false);
@@ -155,7 +156,7 @@ public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
155156
* @param sharedElement {@code true} to set the shared element.
156157
*/
157158
public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
158-
@Nullable String title, @Nullable String subtitle, @Nullable String description,
159+
@Nullable CharSequence title, @Nullable CharSequence subtitle, @Nullable CharSequence description,
159160
@DrawableRes int imageRes, boolean tintImage, boolean sharedElement) {
160161
this(id, color, tintColor, title, subtitle, description, imageRes,
161162
tintImage, id == ADS_TUTORIAL_WELCOME, sharedElement);
@@ -176,7 +177,7 @@ public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
176177
* @param sharedElement {@code true} to set the shared element.
177178
*/
178179
public DynamicTutorial(int id, @ColorInt int color, @ColorInt int tintColor,
179-
@Nullable String title, @Nullable String subtitle, @Nullable String description,
180+
@Nullable CharSequence title, @Nullable CharSequence subtitle, @Nullable CharSequence description,
180181
@DrawableRes int imageRes, boolean tintImage, boolean backgroundAnimation,
181182
boolean sharedElement) {
182183
this.id = id;
@@ -200,9 +201,9 @@ public DynamicTutorial(@NonNull Parcel in) {
200201
this.id = in.readInt();
201202
this.color = in.readInt();
202203
this.tintColor = in.readInt();
203-
this.title = in.readString();
204-
this.subtitle = in.readString();
205-
this.description = in.readString();
204+
this.title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
205+
this.subtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
206+
this.description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
206207
this.imageRes = in.readInt();
207208
this.tintImage = in.readByte() != 0;
208209
this.backgroundAnimation = in.readByte() != 0;
@@ -235,9 +236,9 @@ public void writeToParcel(Parcel dest, int flags) {
235236
dest.writeInt(id);
236237
dest.writeInt(color);
237238
dest.writeInt(tintColor);
238-
dest.writeString(title);
239-
dest.writeString(subtitle);
240-
dest.writeString(description);
239+
TextUtils.writeToParcel(title, dest, flags);
240+
TextUtils.writeToParcel(subtitle, dest, flags);
241+
TextUtils.writeToParcel(description, dest, flags);
241242
dest.writeInt(imageRes);
242243
dest.writeByte((byte) (tintImage ? 1 : 0));
243244
dest.writeByte((byte) (backgroundAnimation ? 1 : 0));
@@ -365,7 +366,7 @@ public boolean isSharedElement() {
365366
*
366367
* @return The title used by this tutorial.
367368
*/
368-
public @Nullable String getTitle() {
369+
public @Nullable CharSequence getTitle() {
369370
return title;
370371
}
371372

@@ -377,7 +378,7 @@ public boolean isSharedElement() {
377378
* @return The {@link DynamicTutorial} object to allow for chaining of calls to
378379
* set methods.
379380
*/
380-
public @NonNull DynamicTutorial setTitle(@Nullable String title) {
381+
public @NonNull DynamicTutorial setTitle(@Nullable CharSequence title) {
381382
this.title = title;
382383

383384
return this;
@@ -388,7 +389,7 @@ public boolean isSharedElement() {
388389
*
389390
* @return The subtitle used by this tutorial.
390391
*/
391-
public @Nullable String getSubtitle() {
392+
public @Nullable CharSequence getSubtitle() {
392393
return subtitle;
393394
}
394395

@@ -400,7 +401,7 @@ public boolean isSharedElement() {
400401
* @return The {@link DynamicTutorial} object to allow for chaining of calls to
401402
* set methods.
402403
*/
403-
public @NonNull DynamicTutorial setSubtitle(@Nullable String subtitle) {
404+
public @NonNull DynamicTutorial setSubtitle(@Nullable CharSequence subtitle) {
404405
this.subtitle = subtitle;
405406

406407
return this;
@@ -411,7 +412,7 @@ public boolean isSharedElement() {
411412
*
412413
* @return The description used by this tutorial.
413414
*/
414-
public @Nullable String getDescription() {
415+
public @Nullable CharSequence getDescription() {
415416
return description;
416417
}
417418

@@ -423,7 +424,7 @@ public boolean isSharedElement() {
423424
* @return The {@link DynamicTutorial} object to allow for chaining of calls to
424425
* set methods.
425426
*/
426-
public @NonNull DynamicTutorial setDescription(@Nullable String description) {
427+
public @NonNull DynamicTutorial setDescription(@Nullable CharSequence description) {
427428
this.description = description;
428429

429430
return this;

0 commit comments

Comments
 (0)