11package fr .gaulupeau .apps .Poche .data ;
22
33import android .content .Context ;
4+ import android .graphics .Color ;
5+ import android .graphics .drawable .Drawable ;
46import android .support .v7 .widget .RecyclerView ;
7+ import android .util .Log ;
8+ import android .util .TypedValue ;
59import android .view .LayoutInflater ;
610import android .view .View ;
711import android .view .ViewGroup ;
812import android .widget .ImageView ;
13+ import android .widget .LinearLayout ;
914import android .widget .TextView ;
1015
16+ import java .util .ArrayList ;
17+ import java .util .Iterator ;
1118import java .util .List ;
1219
1320import fr .gaulupeau .apps .InThePoche .R ;
1421import fr .gaulupeau .apps .Poche .data .dao .entities .Article ;
22+ import fr .gaulupeau .apps .Poche .data .dao .entities .Tag ;
1523
1624import 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 ;
0 commit comments