1
1
package com .stepstone .stepper .viewmodel ;
2
2
3
3
import android .content .Context ;
4
+ import android .support .annotation .DrawableRes ;
4
5
import android .support .annotation .NonNull ;
5
6
import android .support .annotation .Nullable ;
6
7
import android .support .annotation .StringRes ;
7
8
9
+ import com .stepstone .stepper .R ;
10
+
8
11
/**
9
12
* Contains view information about the step.
10
13
*
11
14
* @author Piotr Zawadzki
12
15
*/
13
16
public class StepViewModel {
14
17
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
+
15
25
private StepViewModel () {}
16
26
17
27
/**
18
28
* The displayable name of the step.
19
29
*/
20
30
@ Nullable
21
- private CharSequence title ;
31
+ private CharSequence mTitle ;
22
32
23
33
/**
24
34
* Allows to override the text on the Next button for this step.
@@ -29,7 +39,7 @@ private StepViewModel() {}
29
39
* This is not used for the last step.
30
40
*/
31
41
@ Nullable
32
- private CharSequence nextButtonLabel ;
42
+ private CharSequence mNextButtonLabel ;
33
43
34
44
/**
35
45
* Allows to override the text on the Back button for this step.
@@ -39,44 +49,74 @@ private StepViewModel() {}
39
49
* By default this is {@code null}.
40
50
*/
41
51
@ 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 ;
43
67
44
68
@ Nullable
45
69
public CharSequence getTitle () {
46
- return title ;
70
+ return mTitle ;
47
71
}
48
72
49
73
@ Nullable
50
74
public CharSequence getNextButtonLabel () {
51
- return nextButtonLabel ;
75
+ return mNextButtonLabel ;
52
76
}
53
77
54
78
@ Nullable
55
79
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 ;
57
91
}
58
92
59
93
public static class Builder {
60
94
61
95
@ NonNull
62
- private final Context context ;
96
+ private final Context mContext ;
63
97
64
98
@ Nullable
65
- private CharSequence title ;
99
+ private CharSequence mTitle ;
66
100
67
101
@ Nullable
68
- private CharSequence nextButtonLabel ;
102
+ private CharSequence mNextButtonLabel ;
69
103
70
104
@ 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 ;
72
112
73
113
/**
74
114
* Creates a builder for the step info.
75
115
*
76
116
* @param context the parent context
77
117
*/
78
118
public Builder (@ NonNull Context context ) {
79
- this .context = context ;
119
+ this .mContext = context ;
80
120
}
81
121
82
122
/**
@@ -86,7 +126,7 @@ public Builder(@NonNull Context context) {
86
126
* @return This Builder object to allow for chaining of calls to set methods
87
127
*/
88
128
public Builder setTitle (@ StringRes int titleId ) {
89
- this .title = context .getString (titleId );
129
+ this .mTitle = mContext .getString (titleId );
90
130
return this ;
91
131
}
92
132
@@ -97,7 +137,7 @@ public Builder setTitle(@StringRes int titleId) {
97
137
* @return This Builder object to allow for chaining of calls to set methods
98
138
*/
99
139
public Builder setTitle (@ Nullable CharSequence title ) {
100
- this .title = title ;
140
+ this .mTitle = title ;
101
141
return this ;
102
142
}
103
143
@@ -108,7 +148,7 @@ public Builder setTitle(@Nullable CharSequence title) {
108
148
* @return This Builder object to allow for chaining of calls to set methods
109
149
*/
110
150
public Builder setNextButtonLabel (@ StringRes int nextButtonLabelId ) {
111
- this .nextButtonLabel = context .getString (nextButtonLabelId );
151
+ this .mNextButtonLabel = mContext .getString (nextButtonLabelId );
112
152
return this ;
113
153
}
114
154
@@ -119,7 +159,7 @@ public Builder setNextButtonLabel(@StringRes int nextButtonLabelId) {
119
159
* @return This Builder object to allow for chaining of calls to set methods
120
160
*/
121
161
public Builder setNextButtonLabel (@ Nullable CharSequence nextButtonLabel ) {
122
- this .nextButtonLabel = nextButtonLabel ;
162
+ this .mNextButtonLabel = nextButtonLabel ;
123
163
return this ;
124
164
}
125
165
@@ -130,7 +170,7 @@ public Builder setNextButtonLabel(@Nullable CharSequence nextButtonLabel) {
130
170
* @return This Builder object to allow for chaining of calls to set methods
131
171
*/
132
172
public Builder setBackButtonLabel (@ StringRes int backButtonLabelId ) {
133
- this .backButtonLabel = context .getString (backButtonLabelId );
173
+ this .mBackButtonLabel = mContext .getString (backButtonLabelId );
134
174
return this ;
135
175
}
136
176
@@ -141,7 +181,29 @@ public Builder setBackButtonLabel(@StringRes int backButtonLabelId) {
141
181
* @return This Builder object to allow for chaining of calls to set methods
142
182
*/
143
183
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 ;
145
207
return this ;
146
208
}
147
209
@@ -152,9 +214,11 @@ public Builder setBackButtonLabel(@Nullable CharSequence backButtonLabel) {
152
214
*/
153
215
public StepViewModel create () {
154
216
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 ;
158
222
return viewModel ;
159
223
}
160
224
0 commit comments