Skip to content
This repository was archived by the owner on Jun 19, 2021. It is now read-only.

Commit 74bd6b1

Browse files
committed
Updated to include the option to not specify one of the fields for a TutorialItem
1 parent 472b9ba commit 74bd6b1

4 files changed

Lines changed: 40 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ This library is using the following:
4848

4949
# License
5050

51+
MIT License
52+
5153
Copyright (c) 2015 Rebecca Franks
5254

5355
Permission is hereby granted, free of charge, to any person obtaining a copy

app/src/main/java/za/co/riggaroo/helptut/helptutorialexample/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ private ArrayList<TutorialItem> getTutorialItems(Context context) {
4545
TutorialItem tutorialItem2 = new TutorialItem(context.getString(R.string.slide_2_volunteer_professionals), context.getString(R.string.slide_2_volunteer_professionals_subtitle),
4646
R.color.slide_2, R.drawable.tut_page_2_front, R.drawable.tut_page_2_background);
4747

48-
TutorialItem tutorialItem3 = new TutorialItem(context.getString(R.string.slide_3_download_and_go), context.getString(R.string.slide_3_download_and_go_subtitle),
49-
R.color.slide_3, R.drawable.tut_page_3_foreground, R.drawable.tut_page_3_background);
48+
TutorialItem tutorialItem3 = new TutorialItem(context.getString(R.string.slide_3_download_and_go), null,
49+
R.color.slide_3, R.drawable.tut_page_3_foreground);
5050

5151
TutorialItem tutorialItem4 = new TutorialItem(context.getString(R.string.slide_4_different_languages), context.getString(R.string.slide_4_different_languages_subtitle),
52-
R.color.slide_4, R.drawable.tut_page_4_foreground, R.drawable.tut_page_4_background);
52+
R.color.slide_4, R.drawable.tut_page_4_foreground, R.drawable.tut_page_4_background);
5353

5454
ArrayList<TutorialItem> tutorialItems = new ArrayList<>();
5555
tutorialItems.add(tutorialItem1);

materialhelptutorial/src/main/java/za/co/riggaroo/materialhelptutorial/MaterialTutorialFragment.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.v4.app.Fragment;
5+
import android.text.TextUtils;
56
import android.view.LayoutInflater;
67
import android.view.View;
78
import android.view.ViewGroup;
@@ -44,18 +45,25 @@ public void onCreate(Bundle savedInstanceState) {
4445
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
4546
super.onCreateView(inflater, container, savedInstanceState);
4647
View v = inflater.inflate(R.layout.fragment_help_tutorial_image, container, false);
48+
v.setTag(page);
4749

4850
ImageView imageViewFront = (ImageView) v.findViewById(R.id.fragment_help_tutorial_imageview);
4951
ImageView imageViewBack = (ImageView) v.findViewById(R.id.fragment_help_tutorial_imageview_background);
52+
TextView textViewSubTitle = (TextView) v.findViewById(R.id.fragment_help_tutorial_subtitle_text);
5053

5154
TextView textView = (TextView) v.findViewById(R.id.fragment_help_tutorial_text);
52-
textView.setText(tutorialItem.getTitleText());
53-
v.setTag(page);
54-
55-
TextView textViewSubTitle = (TextView) v.findViewById(R.id.fragment_help_tutorial_subtitle_text);
56-
textViewSubTitle.setText(tutorialItem.getSubTitleText());
57-
Glide.with(this).load(tutorialItem.getBackgroundImageUrl()).into(imageViewBack);
58-
Glide.with(this).load(tutorialItem.getForegroundImageUrl()).into(imageViewFront);
55+
if (!TextUtils.isEmpty(tutorialItem.getTitleText())) {
56+
textView.setText(tutorialItem.getTitleText());
57+
}
58+
if (!TextUtils.isEmpty(tutorialItem.getSubTitleText())) {
59+
textViewSubTitle.setText(tutorialItem.getSubTitleText());
60+
}
61+
if (tutorialItem.getBackgroundImageRes() != -1) {
62+
Glide.with(this).load(tutorialItem.getBackgroundImageRes()).into(imageViewBack);
63+
}
64+
if (tutorialItem.getForegroundImageRes() != -1) {
65+
Glide.with(this).load(tutorialItem.getForegroundImageRes()).into(imageViewFront);
66+
}
5967
return v;
6068
}
6169

materialhelptutorial/src/main/java/za/co/riggaroo/materialhelptutorial/TutorialItem.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ public class TutorialItem implements Parcelable {
88
private String titleText;
99
private String subTitleText;
1010
private int backgroundColor;
11-
private int foregroundImageUrl;
12-
private int backgroundImageUrl;
11+
private int foregroundImageRes;
12+
private int backgroundImageRes = -1;
1313

14-
public TutorialItem(String titleText, String subTitleText, int backgroundColor, int foregroundImageUrl, int backgroundImageUrl) {
14+
public TutorialItem(String titleText, String subTitleText, int backgroundColor, int foregroundImageRes, int backgroundImageRes) {
1515
this.titleText = titleText;
1616
this.subTitleText = subTitleText;
1717
this.backgroundColor = backgroundColor;
18-
this.foregroundImageUrl = foregroundImageUrl;
19-
this.backgroundImageUrl = backgroundImageUrl;
18+
this.foregroundImageRes = foregroundImageRes;
19+
this.backgroundImageRes = backgroundImageRes;
20+
}
21+
22+
public TutorialItem(String titleText, String subTitleText, int backgroundColor, int foregroundImageRes) {
23+
this.titleText = titleText;
24+
this.subTitleText = subTitleText;
25+
this.backgroundColor = backgroundColor;
26+
this.foregroundImageRes = foregroundImageRes;
2027
}
2128

2229
public String getTitleText() {
@@ -31,12 +38,12 @@ public int getBackgroundColor() {
3138
return backgroundColor;
3239
}
3340

34-
public int getForegroundImageUrl() {
35-
return foregroundImageUrl;
41+
public int getForegroundImageRes() {
42+
return foregroundImageRes;
3643
}
3744

38-
public int getBackgroundImageUrl() {
39-
return backgroundImageUrl;
45+
public int getBackgroundImageRes() {
46+
return backgroundImageRes;
4047
}
4148

4249
@Override
@@ -49,16 +56,16 @@ public void writeToParcel(Parcel dest, int flags) {
4956
dest.writeString(this.titleText);
5057
dest.writeString(this.subTitleText);
5158
dest.writeInt(this.backgroundColor);
52-
dest.writeInt(this.foregroundImageUrl);
53-
dest.writeInt(this.backgroundImageUrl);
59+
dest.writeInt(this.foregroundImageRes);
60+
dest.writeInt(this.backgroundImageRes);
5461
}
5562

5663
protected TutorialItem(Parcel in) {
5764
this.titleText = in.readString();
5865
this.subTitleText = in.readString();
5966
this.backgroundColor = in.readInt();
60-
this.foregroundImageUrl = in.readInt();
61-
this.backgroundImageUrl = in.readInt();
67+
this.foregroundImageRes = in.readInt();
68+
this.backgroundImageRes = in.readInt();
6269
}
6370

6471
public static final Parcelable.Creator<TutorialItem> CREATOR = new Parcelable.Creator<TutorialItem>() {

0 commit comments

Comments
 (0)