Skip to content

Commit c388920

Browse files
imhappidsn5ft
authored andcommitted
[Lists] Updating List catalog demo to spec
PiperOrigin-RevId: 797102136
1 parent 089372f commit c388920

File tree

13 files changed

+156
-117
lines changed

13 files changed

+156
-117
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Copyright 2025 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="960"
20+
android:viewportHeight="960"
21+
android:tint="?attr/colorControlNormal">
22+
<path
23+
android:fillColor="@android:color/white"
24+
android:pathData="M320,720L480,598L640,720L580,522L740,408L544,408L480,200L416,408L220,408L380,522L320,720ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,346 707,253Q614,160 480,160Q346,160 253,253Q160,346 160,480Q160,614 253,707Q346,800 480,800ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
25+
</vector>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.material.catalog.listitem;
17+
18+
/** A sample data class used to represent List Items **/
19+
class CustomListItemData {
20+
String text;
21+
boolean checked;
22+
int indexInSection;
23+
int sectionCount;
24+
String subheading;
25+
26+
public CustomListItemData(String text, int indexInSection, int sectionCount) {
27+
this.text = text;
28+
this.indexInSection = indexInSection;
29+
this.sectionCount = sectionCount;
30+
}
31+
32+
public CustomListItemData(String subheading) {
33+
this.subheading = subheading;
34+
}
35+
}

catalog/java/io/material/catalog/listitem/ListsMainDemoFragment.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.view.LayoutInflater;
2929
import android.view.View;
3030
import android.view.ViewGroup;
31-
import android.widget.ImageView;
3231
import android.widget.TextView;
3332
import android.widget.Toast;
3433
import androidx.annotation.NonNull;
@@ -51,9 +50,13 @@ public View onCreateDemoView(
5150
(RecyclerView) layoutInflater.inflate(R.layout.cat_lists_fragment, viewGroup, false);
5251

5352
view.setLayoutManager(new LinearLayoutManager(getContext()));
54-
List<CustomCardData> data = new ArrayList<>();
53+
List<CustomListItemData> data = new ArrayList<>();
5554
for (int i = 0; i < 20; i++) {
56-
data.add(new CustomCardData(i+1));
55+
data.add(
56+
new CustomListItemData(
57+
String.format(view.getContext().getString(R.string.cat_list_item_text), i + 1),
58+
i,
59+
20));
5760
}
5861

5962
view.setAdapter(new ListsAdapter(data));
@@ -65,9 +68,9 @@ public View onCreateDemoView(
6568
/** An Adapter that shows custom list items */
6669
public static class ListsAdapter extends Adapter<CustomItemViewHolder> {
6770

68-
private final List<CustomCardData> items;
71+
private final List<CustomListItemData> items;
6972

70-
public ListsAdapter(@NonNull List<CustomCardData> items) {
73+
public ListsAdapter(@NonNull List<CustomListItemData> items) {
7174
this.items = items;
7275
}
7376

@@ -76,14 +79,15 @@ public ListsAdapter(@NonNull List<CustomCardData> items) {
7679
public CustomItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
7780
ViewGroup item =
7881
(ViewGroup)
79-
LayoutInflater.from(parent.getContext()).inflate(R.layout.cat_list_item_viewholder, parent, /* attachToRoot= */ false);
82+
LayoutInflater.from(parent.getContext())
83+
.inflate(R.layout.cat_list_item_viewholder, parent, /* attachToRoot= */ false);
8084
return new CustomItemViewHolder(item);
8185
}
8286

8387
@Override
8488
public void onBindViewHolder(
8589
@NonNull CustomItemViewHolder viewHolder, int position) {
86-
CustomCardData data = getItemAt(position);
90+
CustomListItemData data = getItemAt(position);
8791
viewHolder.bind(data);
8892
}
8993

@@ -93,19 +97,11 @@ public int getItemCount() {
9397
}
9498

9599
@NonNull
96-
public CustomCardData getItemAt(int i) {
100+
public CustomListItemData getItemAt(int i) {
97101
return items.get(i);
98102
}
99103
}
100104

101-
static class CustomCardData {
102-
int cardNumber;
103-
boolean checked;
104-
public CustomCardData(int i) {
105-
cardNumber = i;
106-
}
107-
}
108-
109105
static class MarginItemDecoration extends ItemDecoration {
110106
private final int itemMargin;
111107

@@ -128,26 +124,19 @@ public void getItemOffsets(@NonNull Rect outRect,
128124
/** A ViewHolder that shows custom list items */
129125
public static class CustomItemViewHolder extends ListItemViewHolder {
130126

131-
private final ImageView startButton;
132-
private final ImageView endButton;
133-
private final TextView text;
127+
private final TextView textView;
134128
private final MaterialCardView cardView;
135129

136130

137131
public CustomItemViewHolder(@NonNull View itemView) {
138132
super(itemView);
139-
startButton = itemView.findViewById(R.id.cat_list_item_start_icon);
140-
endButton = itemView.findViewById(R.id.cat_list_item_end_icon);
141-
text = itemView.findViewById(R.id.cat_list_item_text);
133+
textView = itemView.findViewById(R.id.cat_list_item_text);
142134
cardView = itemView.findViewById(R.id.cat_list_item_card_view);
143135
}
144136

145-
public void bind(@NonNull CustomCardData data) {
137+
public void bind(@NonNull CustomListItemData data) {
146138
super.bind();
147-
text.setText(String.valueOf(data.cardNumber));
148-
startButton.setImageResource(R.drawable.logo_avatar_anonymous_40dp);
149-
endButton.setImageResource(R.drawable.ic_drag_handle_vd_theme_24px);
150-
139+
textView.setText(data.text);
151140
cardView.setChecked(data.checked);
152141
cardView.setOnClickListener(
153142
v -> {

catalog/java/io/material/catalog/listitem/MultiSectionListDemoFragment.java

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.view.LayoutInflater;
2929
import android.view.View;
3030
import android.view.ViewGroup;
31-
import android.widget.ImageView;
3231
import android.widget.TextView;
3332
import android.widget.Toast;
3433
import 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
}

catalog/java/io/material/catalog/listitem/SegmentedListDemoFragment.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ public View onCreateDemoView(
3939
@Nullable ViewGroup viewGroup,
4040
@Nullable Bundle bundle) {
4141
RecyclerView view =
42-
(RecyclerView) layoutInflater.inflate(R.layout.cat_lists_bright_background_fragment, viewGroup, false);
42+
(RecyclerView)
43+
layoutInflater.inflate(R.layout.cat_lists_bright_background_fragment, viewGroup, false);
4344

4445
view.setLayoutManager(new LinearLayoutManager(getContext()));
45-
List<CustomCardData> data = new ArrayList<>();
46+
List<CustomListItemData> data = new ArrayList<>();
4647
for (int i = 0; i < 20; i++) {
47-
data.add(new CustomCardData(i+1));
48+
data.add(
49+
new CustomListItemData(
50+
String.format(view.getContext().getString(R.string.cat_list_item_text), i + 1),
51+
i,
52+
20));
4853
}
4954

5055
view.setAdapter(new ListsAdapter(data));
@@ -56,7 +61,7 @@ public View onCreateDemoView(
5661
/** An Adapter that shows custom list items */
5762
public static class ListsAdapter extends ListsMainDemoFragment.ListsAdapter {
5863

59-
public ListsAdapter(@NonNull List<CustomCardData> items) {
64+
public ListsAdapter(@NonNull List<CustomListItemData> items) {
6065
super(items);
6166
}
6267

@@ -65,7 +70,11 @@ public ListsAdapter(@NonNull List<CustomCardData> items) {
6570
public CustomItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
6671
ViewGroup item =
6772
(ViewGroup)
68-
LayoutInflater.from(parent.getContext()).inflate(R.layout.cat_list_item_segmented_viewholder, parent, /* attachToRoot= */ false);
73+
LayoutInflater.from(parent.getContext())
74+
.inflate(
75+
R.layout.cat_list_item_segmented_viewholder,
76+
parent,
77+
/* attachToRoot= */ false);
6978
return new CustomItemViewHolder(item);
7079
}
7180
}

0 commit comments

Comments
 (0)