2828import android .view .LayoutInflater ;
2929import android .view .View ;
3030import android .view .ViewGroup ;
31- import android .widget .ImageView ;
3231import android .widget .TextView ;
3332import android .widget .Toast ;
3433import androidx .annotation .NonNull ;
@@ -51,21 +50,33 @@ public View onCreateDemoView(
5150 RecyclerView view =
5251 (RecyclerView ) layoutInflater .inflate (R .layout .cat_lists_bright_background_fragment , viewGroup , false );
5352 view .setLayoutManager (new LinearLayoutManager (getContext ()));
54- List <CustomCardData > data = new ArrayList <>();
53+ List <CustomListItemData > data = new ArrayList <>();
5554 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 ));
5758 itemCount += 1 ;
5859
59- data .add (new CustomCardData ("Subheader 1" ));
60+ data .add (new CustomListItemData ("Subheader 1" ));
6061
6162 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 ));
6369 }
6470
65- data .add (new CustomCardData ("Subheader 2" ));
71+ data .add (new CustomListItemData ("Subheader 2" ));
6672
6773 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 ));
6980 }
7081
7182 view .setAdapter (new ListsAdapter (data ));
@@ -79,9 +90,9 @@ public static class ListsAdapter extends Adapter<ViewHolder> {
7990
8091 private static final int VIEW_TYPE_SUBHEADING = 1 ;
8192 private static final int VIEW_TYPE_LIST_ITEM = 2 ;
82- private final List <CustomCardData > items ;
93+ private final List <CustomListItemData > items ;
8394
84- public ListsAdapter (@ NonNull List <CustomCardData > items ) {
95+ public ListsAdapter (@ NonNull List <CustomListItemData > items ) {
8596 this .items = items ;
8697 }
8798
@@ -94,7 +105,9 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
94105 (ViewGroup )
95106 LayoutInflater .from (parent .getContext ())
96107 .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 );
98111 return new CustomItemViewHolder (item );
99112 case VIEW_TYPE_SUBHEADING :
100113 TextView subheader =
@@ -109,7 +122,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
109122
110123 @ Override
111124 public int getItemViewType (int position ) {
112- CustomCardData data = getItemAt (position );
125+ CustomListItemData data = getItemAt (position );
113126 if (data .subheading != null ) {
114127 return VIEW_TYPE_SUBHEADING ;
115128 }
@@ -119,7 +132,7 @@ public int getItemViewType(int position) {
119132 @ Override
120133 public void onBindViewHolder (
121134 @ NonNull ViewHolder viewHolder , int position ) {
122- CustomCardData data = getItemAt (position );
135+ CustomListItemData data = getItemAt (position );
123136 if (getItemViewType (position ) == VIEW_TYPE_SUBHEADING ) {
124137 ((SubheaderViewHolder ) viewHolder ).bind (data );
125138 } else if (getItemViewType (position ) == VIEW_TYPE_LIST_ITEM ) {
@@ -133,29 +146,11 @@ public int getItemCount() {
133146 }
134147
135148 @ NonNull
136- public CustomCardData getItemAt (int i ) {
149+ public CustomListItemData getItemAt (int i ) {
137150 return items .get (i );
138151 }
139152 }
140153
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-
159154 static class MarginItemDecoration extends ItemDecoration {
160155 private final int itemMargin ;
161156
@@ -178,25 +173,19 @@ public void getItemOffsets(@NonNull Rect outRect,
178173 /** A ViewHolder that shows custom list items */
179174 public static class CustomItemViewHolder extends ListItemViewHolder {
180175
181- private final ImageView startButton ;
182- private final ImageView endButton ;
183- private final TextView text ;
176+ private final TextView textView ;
184177 private final MaterialCardView cardView ;
185178
186179
187180 public CustomItemViewHolder (@ NonNull View itemView ) {
188181 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 );
192183 cardView = itemView .findViewById (R .id .cat_list_item_card_view );
193184 }
194185
195- public void bind (@ NonNull CustomCardData data ) {
186+ public void bind (@ NonNull CustomListItemData data ) {
196187 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 );
200189
201190 cardView .setChecked (data .checked );
202191 cardView .setOnClickListener (
@@ -219,7 +208,7 @@ public SubheaderViewHolder(@NonNull View itemView) {
219208 text = itemView .findViewById (R .id .cat_list_subheader_text );
220209 }
221210
222- public void bind (@ NonNull CustomCardData data ) {
211+ public void bind (@ NonNull CustomListItemData data ) {
223212 text .setText (data .subheading );
224213 }
225214 }
0 commit comments