Skip to content

Commit

Permalink
show tags in list item view
Browse files Browse the repository at this point in the history
  • Loading branch information
Strubbl committed Sep 9, 2017
1 parent 4929275 commit aa1f41f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package fr.gaulupeau.apps.Poche.data;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import fr.gaulupeau.apps.InThePoche.R;
import fr.gaulupeau.apps.Poche.data.dao.entities.Article;
import fr.gaulupeau.apps.Poche.data.dao.entities.Tag;

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

Expand Down Expand Up @@ -53,15 +61,19 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
OnItemClickListener listener;
TextView title;
TextView url;
LinearLayout tagContainer;
ImageView favourite;
ImageView read;
TextView readingTime;
boolean areTagsAdded;

public ViewHolder(View itemView, OnItemClickListener listener) {
super(itemView);
this.listener = listener;
title = (TextView) itemView.findViewById(R.id.title);
url = (TextView) itemView.findViewById(R.id.url);
tagContainer = (LinearLayout) itemView.findViewById(R.id.tagContainer);
areTagsAdded = false;
favourite = (ImageView) itemView.findViewById(R.id.favourite);
read = (ImageView) itemView.findViewById(R.id.read);
readingTime = (TextView) itemView.findViewById(R.id.estimatedReadingTime);
Expand All @@ -71,6 +83,29 @@ public ViewHolder(View itemView, OnItemClickListener listener) {
public void bind(Article article) {
title.setText(article.getTitle());
url.setText(article.getDomain());
if (areTagsAdded){
tagContainer.removeAllViews();
areTagsAdded = false;
}
List<String> tagsAdded = new ArrayList<>(); // do not add duplicate labels
for (Iterator<Tag> tags = article.getTags().iterator(); tags.hasNext();) {
Tag t = tags.next();
if(!areTagsAdded && !tagsAdded.contains(t.getLabel())) {
// TODO apply current theme
TextView tagText = new TextView(context);
tagText.setText(t.getLabel());
tagText.setBackground(context.getResources().getDrawable(R.drawable.tag_shape));
tagText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
tagText.setTextColor(Color.WHITE);
tagText.setPadding(5, 2, 5, 2); // (left, top, right, bottom);
LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lllp.setMargins(0, 0, 5, 0);
tagText.setLayoutParams(lllp);
tagContainer.addView(tagText);
tagsAdded.add(t.getLabel());
}
}
areTagsAdded = true;

boolean showFavourite = false;
boolean showRead = false;
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/tag_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1px"
android:color="#ffffff" />
<corners android:radius="10px"/>
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/tag_shape_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1px"
android:color="#000000" />
<corners android:radius="10px"/>
<padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
android:src="?attr/listItem_icon_read"/>
</LinearLayout>

<LinearLayout
android:id="@+id/tagContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down

0 comments on commit aa1f41f

Please sign in to comment.