28
28
import android .view .LayoutInflater ;
29
29
import android .view .View ;
30
30
import android .view .ViewGroup ;
31
- import android .widget .ImageView ;
32
31
import android .widget .TextView ;
33
32
import android .widget .Toast ;
34
33
import androidx .annotation .NonNull ;
@@ -51,21 +50,33 @@ public View onCreateDemoView(
51
50
RecyclerView view =
52
51
(RecyclerView ) layoutInflater .inflate (R .layout .cat_lists_bright_background_fragment , viewGroup , false );
53
52
view .setLayoutManager (new LinearLayoutManager (getContext ()));
54
- List <CustomCardData > data = new ArrayList <>();
53
+ List <CustomListItemData > data = new ArrayList <>();
55
54
int itemCount = 0 ;
56
- data .add (new CustomCardData (0 , 0 , 1 ));
55
+ data .add (
56
+ new CustomListItemData (
57
+ String .format (view .getContext ().getString (R .string .cat_list_item_text ), 0 ), 0 , 1 ));
57
58
itemCount += 1 ;
58
59
59
- data .add (new CustomCardData ("Subheader 1" ));
60
+ data .add (new CustomListItemData ("Subheader 1" ));
60
61
61
62
for (int i = 0 ; i < 3 ; i ++) {
62
- data .add (new CustomCardData (itemCount + i , i , 3 ));
63
+ data .add (
64
+ new CustomListItemData (
65
+ String .format (
66
+ view .getContext ().getString (R .string .cat_list_item_text ), itemCount + i ),
67
+ i ,
68
+ 3 ));
63
69
}
64
70
65
- data .add (new CustomCardData ("Subheader 2" ));
71
+ data .add (new CustomListItemData ("Subheader 2" ));
66
72
67
73
for (int i = 0 ; i < 5 ; i ++) {
68
- data .add (new CustomCardData (itemCount + i , i , 5 ));
74
+ data .add (
75
+ new CustomListItemData (
76
+ String .format (
77
+ view .getContext ().getString (R .string .cat_list_item_text ), itemCount + i ),
78
+ i ,
79
+ 5 ));
69
80
}
70
81
71
82
view .setAdapter (new ListsAdapter (data ));
@@ -79,9 +90,9 @@ public static class ListsAdapter extends Adapter<ViewHolder> {
79
90
80
91
private static final int VIEW_TYPE_SUBHEADING = 1 ;
81
92
private static final int VIEW_TYPE_LIST_ITEM = 2 ;
82
- private final List <CustomCardData > items ;
93
+ private final List <CustomListItemData > items ;
83
94
84
- public ListsAdapter (@ NonNull List <CustomCardData > items ) {
95
+ public ListsAdapter (@ NonNull List <CustomListItemData > items ) {
85
96
this .items = items ;
86
97
}
87
98
@@ -94,7 +105,9 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
94
105
(ViewGroup )
95
106
LayoutInflater .from (parent .getContext ())
96
107
.inflate (
97
- R .layout .cat_list_item_segmented_viewholder , parent , /* attachToRoot= */ false );
108
+ R .layout .cat_list_item_segmented_viewholder ,
109
+ parent ,
110
+ /* attachToRoot= */ false );
98
111
return new CustomItemViewHolder (item );
99
112
case VIEW_TYPE_SUBHEADING :
100
113
TextView subheader =
@@ -109,7 +122,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
109
122
110
123
@ Override
111
124
public int getItemViewType (int position ) {
112
- CustomCardData data = getItemAt (position );
125
+ CustomListItemData data = getItemAt (position );
113
126
if (data .subheading != null ) {
114
127
return VIEW_TYPE_SUBHEADING ;
115
128
}
@@ -119,7 +132,7 @@ public int getItemViewType(int position) {
119
132
@ Override
120
133
public void onBindViewHolder (
121
134
@ NonNull ViewHolder viewHolder , int position ) {
122
- CustomCardData data = getItemAt (position );
135
+ CustomListItemData data = getItemAt (position );
123
136
if (getItemViewType (position ) == VIEW_TYPE_SUBHEADING ) {
124
137
((SubheaderViewHolder ) viewHolder ).bind (data );
125
138
} else if (getItemViewType (position ) == VIEW_TYPE_LIST_ITEM ) {
@@ -133,29 +146,11 @@ public int getItemCount() {
133
146
}
134
147
135
148
@ NonNull
136
- public CustomCardData getItemAt (int i ) {
149
+ public CustomListItemData getItemAt (int i ) {
137
150
return items .get (i );
138
151
}
139
152
}
140
153
141
- static class CustomCardData {
142
- int cardNumber ;
143
- boolean checked ;
144
- int indexInSection ;
145
- int sectionCount ;
146
- String subheading ;
147
-
148
- public CustomCardData (int cardNumber , int indexInSection , int sectionCount ) {
149
- this .cardNumber = cardNumber ;
150
- this .indexInSection = indexInSection ;
151
- this .sectionCount = sectionCount ;
152
- }
153
-
154
- public CustomCardData (String subheading ) {
155
- this .subheading = subheading ;
156
- }
157
- }
158
-
159
154
static class MarginItemDecoration extends ItemDecoration {
160
155
private final int itemMargin ;
161
156
@@ -178,25 +173,19 @@ public void getItemOffsets(@NonNull Rect outRect,
178
173
/** A ViewHolder that shows custom list items */
179
174
public static class CustomItemViewHolder extends ListItemViewHolder {
180
175
181
- private final ImageView startButton ;
182
- private final ImageView endButton ;
183
- private final TextView text ;
176
+ private final TextView textView ;
184
177
private final MaterialCardView cardView ;
185
178
186
179
187
180
public CustomItemViewHolder (@ NonNull View itemView ) {
188
181
super (itemView );
189
- startButton = itemView .findViewById (R .id .cat_list_item_start_icon );
190
- endButton = itemView .findViewById (R .id .cat_list_item_end_icon );
191
- text = itemView .findViewById (R .id .cat_list_item_text );
182
+ textView = itemView .findViewById (R .id .cat_list_item_text );
192
183
cardView = itemView .findViewById (R .id .cat_list_item_card_view );
193
184
}
194
185
195
- public void bind (@ NonNull CustomCardData data ) {
186
+ public void bind (@ NonNull CustomListItemData data ) {
196
187
super .bind (data .indexInSection , data .sectionCount );
197
- text .setText (String .valueOf (data .cardNumber ));
198
- startButton .setImageResource (R .drawable .logo_avatar_anonymous_40dp );
199
- endButton .setImageResource (R .drawable .ic_drag_handle_vd_theme_24px );
188
+ textView .setText (data .text );
200
189
201
190
cardView .setChecked (data .checked );
202
191
cardView .setOnClickListener (
@@ -219,7 +208,7 @@ public SubheaderViewHolder(@NonNull View itemView) {
219
208
text = itemView .findViewById (R .id .cat_list_subheader_text );
220
209
}
221
210
222
- public void bind (@ NonNull CustomCardData data ) {
211
+ public void bind (@ NonNull CustomListItemData data ) {
223
212
text .setText (data .subheading );
224
213
}
225
214
}
0 commit comments