11package com .stepstone .stepper .viewmodel ;
22
33import android .content .Context ;
4+ import android .support .annotation .DrawableRes ;
45import android .support .annotation .NonNull ;
56import android .support .annotation .Nullable ;
67import android .support .annotation .StringRes ;
78
9+ import com .stepstone .stepper .R ;
10+
811/**
912 * Contains view information about the step.
1013 *
1114 * @author Piotr Zawadzki
1215 */
1316public class StepViewModel {
1417
18+ /**
19+ * Drawable resource ID to be used for back/next navigation button compound drawables when we do not want to show them.
20+ * @see #mNextButtonEndDrawableResId
21+ * @see #mBackButtonStartDrawableResId
22+ */
23+ public static final int NULL_DRAWABLE = -1 ;
24+
1525 private StepViewModel () {}
1626
1727 /**
1828 * The displayable name of the step.
1929 */
2030 @ Nullable
21- private CharSequence title ;
31+ private CharSequence mTitle ;
2232
2333 /**
2434 * Allows to override the text on the Next button for this step.
@@ -29,7 +39,7 @@ private StepViewModel() {}
2939 * This is not used for the last step.
3040 */
3141 @ Nullable
32- private CharSequence nextButtonLabel ;
42+ private CharSequence mNextButtonLabel ;
3343
3444 /**
3545 * Allows to override the text on the Back button for this step.
@@ -39,44 +49,74 @@ private StepViewModel() {}
3949 * By default this is {@code null}.
4050 */
4151 @ Nullable
42- private CharSequence backButtonLabel ;
52+ private CharSequence mBackButtonLabel ;
53+
54+ /**
55+ * Drawable resource ID to be used for next button's end compound drawable.
56+ * {@link com.stepstone.stepper.R.drawable#ic_chevron_end} is the default.
57+ */
58+ @ DrawableRes
59+ private int mNextButtonEndDrawableResId ;
60+
61+ /**
62+ * Drawable resource ID to be used for back button's start compound drawable.
63+ * {@link com.stepstone.stepper.R.drawable#ic_chevron_start} is the default.
64+ */
65+ @ DrawableRes
66+ private int mBackButtonStartDrawableResId ;
4367
4468 @ Nullable
4569 public CharSequence getTitle () {
46- return title ;
70+ return mTitle ;
4771 }
4872
4973 @ Nullable
5074 public CharSequence getNextButtonLabel () {
51- return nextButtonLabel ;
75+ return mNextButtonLabel ;
5276 }
5377
5478 @ Nullable
5579 public CharSequence getBackButtonLabel () {
56- return backButtonLabel ;
80+ return mBackButtonLabel ;
81+ }
82+
83+ @ DrawableRes
84+ public int getNextButtonEndDrawableResId () {
85+ return mNextButtonEndDrawableResId ;
86+ }
87+
88+ @ DrawableRes
89+ public int getBackButtonStartDrawableResId () {
90+ return mBackButtonStartDrawableResId ;
5791 }
5892
5993 public static class Builder {
6094
6195 @ NonNull
62- private final Context context ;
96+ private final Context mContext ;
6397
6498 @ Nullable
65- private CharSequence title ;
99+ private CharSequence mTitle ;
66100
67101 @ Nullable
68- private CharSequence nextButtonLabel ;
102+ private CharSequence mNextButtonLabel ;
69103
70104 @ Nullable
71- private CharSequence backButtonLabel ;
105+ private CharSequence mBackButtonLabel ;
106+
107+ @ DrawableRes
108+ private int mNextButtonEndDrawableResId = R .drawable .ic_chevron_end ;
109+
110+ @ DrawableRes
111+ private int mBackButtonStartDrawableResId = R .drawable .ic_chevron_start ;
72112
73113 /**
74114 * Creates a builder for the step info.
75115 *
76116 * @param context the parent context
77117 */
78118 public Builder (@ NonNull Context context ) {
79- this .context = context ;
119+ this .mContext = context ;
80120 }
81121
82122 /**
@@ -86,7 +126,7 @@ public Builder(@NonNull Context context) {
86126 * @return This Builder object to allow for chaining of calls to set methods
87127 */
88128 public Builder setTitle (@ StringRes int titleId ) {
89- this .title = context .getString (titleId );
129+ this .mTitle = mContext .getString (titleId );
90130 return this ;
91131 }
92132
@@ -97,7 +137,7 @@ public Builder setTitle(@StringRes int titleId) {
97137 * @return This Builder object to allow for chaining of calls to set methods
98138 */
99139 public Builder setTitle (@ Nullable CharSequence title ) {
100- this .title = title ;
140+ this .mTitle = title ;
101141 return this ;
102142 }
103143
@@ -108,7 +148,7 @@ public Builder setTitle(@Nullable CharSequence title) {
108148 * @return This Builder object to allow for chaining of calls to set methods
109149 */
110150 public Builder setNextButtonLabel (@ StringRes int nextButtonLabelId ) {
111- this .nextButtonLabel = context .getString (nextButtonLabelId );
151+ this .mNextButtonLabel = mContext .getString (nextButtonLabelId );
112152 return this ;
113153 }
114154
@@ -119,7 +159,7 @@ public Builder setNextButtonLabel(@StringRes int nextButtonLabelId) {
119159 * @return This Builder object to allow for chaining of calls to set methods
120160 */
121161 public Builder setNextButtonLabel (@ Nullable CharSequence nextButtonLabel ) {
122- this .nextButtonLabel = nextButtonLabel ;
162+ this .mNextButtonLabel = nextButtonLabel ;
123163 return this ;
124164 }
125165
@@ -130,7 +170,7 @@ public Builder setNextButtonLabel(@Nullable CharSequence nextButtonLabel) {
130170 * @return This Builder object to allow for chaining of calls to set methods
131171 */
132172 public Builder setBackButtonLabel (@ StringRes int backButtonLabelId ) {
133- this .backButtonLabel = context .getString (backButtonLabelId );
173+ this .mBackButtonLabel = mContext .getString (backButtonLabelId );
134174 return this ;
135175 }
136176
@@ -141,7 +181,29 @@ public Builder setBackButtonLabel(@StringRes int backButtonLabelId) {
141181 * @return This Builder object to allow for chaining of calls to set methods
142182 */
143183 public Builder setBackButtonLabel (@ Nullable CharSequence backButtonLabel ) {
144- this .backButtonLabel = backButtonLabel ;
184+ this .mBackButtonLabel = backButtonLabel ;
185+ return this ;
186+ }
187+
188+ /**
189+ * Set the drawable resource ID to be used for next button's end compound drawable.
190+ *
191+ * @param nextButtonEndDrawableResId drawable resource ID to be used for next button's end compound drawable.
192+ * @return This Builder object to allow for chaining of calls to set methods
193+ */
194+ public Builder setNextButtonEndDrawableResId (@ DrawableRes int nextButtonEndDrawableResId ) {
195+ this .mNextButtonEndDrawableResId = nextButtonEndDrawableResId ;
196+ return this ;
197+ }
198+
199+ /**
200+ * Set the drawable resource ID to be used for back button's start compound drawable.
201+ *
202+ * @param backButtonStartDrawableResId drawable resource ID to be used for back button's start compound drawable.
203+ * @return This Builder object to allow for chaining of calls to set methods
204+ */
205+ public Builder setBackButtonStartDrawableResId (@ DrawableRes int backButtonStartDrawableResId ) {
206+ this .mBackButtonStartDrawableResId = backButtonStartDrawableResId ;
145207 return this ;
146208 }
147209
@@ -152,9 +214,11 @@ public Builder setBackButtonLabel(@Nullable CharSequence backButtonLabel) {
152214 */
153215 public StepViewModel create () {
154216 final StepViewModel viewModel = new StepViewModel ();
155- viewModel .title = this .title ;
156- viewModel .backButtonLabel = this .backButtonLabel ;
157- viewModel .nextButtonLabel = this .nextButtonLabel ;
217+ viewModel .mTitle = this .mTitle ;
218+ viewModel .mBackButtonLabel = this .mBackButtonLabel ;
219+ viewModel .mNextButtonLabel = this .mNextButtonLabel ;
220+ viewModel .mNextButtonEndDrawableResId = this .mNextButtonEndDrawableResId ;
221+ viewModel .mBackButtonStartDrawableResId = this .mBackButtonStartDrawableResId ;
158222 return viewModel ;
159223 }
160224
0 commit comments