Skip to content

Commit 0913cd4

Browse files
committed
show tags in list item view
1 parent da43b3e commit 0913cd4

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java

+35
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package fr.gaulupeau.apps.Poche.data;
22

33
import android.content.Context;
4+
import android.graphics.Color;
5+
import android.graphics.drawable.Drawable;
46
import android.support.v7.widget.RecyclerView;
7+
import android.util.Log;
8+
import android.util.TypedValue;
59
import android.view.LayoutInflater;
610
import android.view.View;
711
import android.view.ViewGroup;
812
import android.widget.ImageView;
13+
import android.widget.LinearLayout;
914
import android.widget.TextView;
1015

16+
import java.util.ArrayList;
17+
import java.util.Iterator;
1118
import java.util.List;
1219

1320
import fr.gaulupeau.apps.InThePoche.R;
1421
import fr.gaulupeau.apps.Poche.data.dao.entities.Article;
22+
import fr.gaulupeau.apps.Poche.data.dao.entities.Tag;
1523

1624
import static fr.gaulupeau.apps.Poche.data.ListTypes.*;
1725

@@ -53,15 +61,19 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
5361
OnItemClickListener listener;
5462
TextView title;
5563
TextView url;
64+
LinearLayout tagContainer;
5665
ImageView favourite;
5766
ImageView read;
5867
TextView readingTime;
68+
boolean areTagsAdded;
5969

6070
public ViewHolder(View itemView, OnItemClickListener listener) {
6171
super(itemView);
6272
this.listener = listener;
6373
title = (TextView) itemView.findViewById(R.id.title);
6474
url = (TextView) itemView.findViewById(R.id.url);
75+
tagContainer = (LinearLayout) itemView.findViewById(R.id.tagContainer);
76+
areTagsAdded = false;
6577
favourite = (ImageView) itemView.findViewById(R.id.favourite);
6678
read = (ImageView) itemView.findViewById(R.id.read);
6779
readingTime = (TextView) itemView.findViewById(R.id.estimatedReadingTime);
@@ -71,6 +83,29 @@ public ViewHolder(View itemView, OnItemClickListener listener) {
7183
public void bind(Article article) {
7284
title.setText(article.getTitle());
7385
url.setText(article.getDomain());
86+
if (areTagsAdded){
87+
tagContainer.removeAllViews();
88+
areTagsAdded = false;
89+
}
90+
List<String> tagsAdded = new ArrayList<>(); // do not add duplicate labels
91+
for (Iterator<Tag> tags = article.getTags().iterator(); tags.hasNext();) {
92+
Tag t = tags.next();
93+
if(!areTagsAdded && !tagsAdded.contains(t.getLabel())) {
94+
// TODO apply current theme
95+
TextView tagText = new TextView(context);
96+
tagText.setText(t.getLabel());
97+
tagText.setBackground(context.getResources().getDrawable(R.drawable.tag_shape));
98+
tagText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
99+
tagText.setTextColor(Color.WHITE);
100+
tagText.setPadding(5, 2, 5, 2); // (left, top, right, bottom);
101+
LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
102+
lllp.setMargins(0, 0, 5, 0);
103+
tagText.setLayoutParams(lllp);
104+
tagContainer.addView(tagText);
105+
tagsAdded.add(t.getLabel());
106+
}
107+
}
108+
areTagsAdded = true;
74109

75110
boolean showFavourite = false;
76111
boolean showRead = false;

Diff for: app/src/main/res/drawable/tag_shape.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<stroke
4+
android:width="1px"
5+
android:color="#ffffff" />
6+
<corners android:radius="10px"/>
7+
</shape>

Diff for: app/src/main/res/drawable/tag_shape_dark.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<stroke
4+
android:width="1px"
5+
android:color="#000000" />
6+
<corners android:radius="10px"/>
7+
<padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
8+
</shape>

Diff for: app/src/main/res/layout/list_item.xml

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
android:src="?attr/listItem_icon_read"/>
3636
</LinearLayout>
3737

38+
<LinearLayout
39+
android:id="@+id/tagContainer"
40+
android:layout_width="match_parent"
41+
android:layout_height="match_parent"
42+
android:orientation="horizontal">
43+
</LinearLayout>
44+
3845
<LinearLayout
3946
android:layout_width="match_parent"
4047
android:layout_height="match_parent"

0 commit comments

Comments
 (0)