1
1
package fr .gaulupeau .apps .Poche .data ;
2
2
3
3
import android .content .Context ;
4
+ import android .graphics .Color ;
5
+ import android .graphics .drawable .Drawable ;
4
6
import android .support .v7 .widget .RecyclerView ;
7
+ import android .util .Log ;
8
+ import android .util .TypedValue ;
5
9
import android .view .LayoutInflater ;
6
10
import android .view .View ;
7
11
import android .view .ViewGroup ;
8
12
import android .widget .ImageView ;
13
+ import android .widget .LinearLayout ;
9
14
import android .widget .TextView ;
10
15
16
+ import java .util .ArrayList ;
17
+ import java .util .Iterator ;
11
18
import java .util .List ;
12
19
13
20
import fr .gaulupeau .apps .InThePoche .R ;
14
21
import fr .gaulupeau .apps .Poche .data .dao .entities .Article ;
22
+ import fr .gaulupeau .apps .Poche .data .dao .entities .Tag ;
15
23
16
24
import static fr .gaulupeau .apps .Poche .data .ListTypes .*;
17
25
@@ -53,15 +61,19 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
53
61
OnItemClickListener listener ;
54
62
TextView title ;
55
63
TextView url ;
64
+ LinearLayout tagContainer ;
56
65
ImageView favourite ;
57
66
ImageView read ;
58
67
TextView readingTime ;
68
+ boolean areTagsAdded ;
59
69
60
70
public ViewHolder (View itemView , OnItemClickListener listener ) {
61
71
super (itemView );
62
72
this .listener = listener ;
63
73
title = (TextView ) itemView .findViewById (R .id .title );
64
74
url = (TextView ) itemView .findViewById (R .id .url );
75
+ tagContainer = (LinearLayout ) itemView .findViewById (R .id .tagContainer );
76
+ areTagsAdded = false ;
65
77
favourite = (ImageView ) itemView .findViewById (R .id .favourite );
66
78
read = (ImageView ) itemView .findViewById (R .id .read );
67
79
readingTime = (TextView ) itemView .findViewById (R .id .estimatedReadingTime );
@@ -71,6 +83,29 @@ public ViewHolder(View itemView, OnItemClickListener listener) {
71
83
public void bind (Article article ) {
72
84
title .setText (article .getTitle ());
73
85
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 ;
74
109
75
110
boolean showFavourite = false ;
76
111
boolean showRead = false ;
0 commit comments