diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java b/app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java index 6f151e257..822a8b6de 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java @@ -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.*; @@ -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); @@ -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 tagsAdded = new ArrayList<>(); // do not add duplicate labels + for (Iterator 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; diff --git a/app/src/main/res/drawable/tag_shape.xml b/app/src/main/res/drawable/tag_shape.xml new file mode 100644 index 000000000..66f7d2fd1 --- /dev/null +++ b/app/src/main/res/drawable/tag_shape.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/tag_shape_dark.xml b/app/src/main/res/drawable/tag_shape_dark.xml new file mode 100644 index 000000000..79830e319 --- /dev/null +++ b/app/src/main/res/drawable/tag_shape_dark.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml index eeda84fc0..d999fcd8e 100644 --- a/app/src/main/res/layout/list_item.xml +++ b/app/src/main/res/layout/list_item.xml @@ -35,6 +35,13 @@ android:src="?attr/listItem_icon_read"/> + + +