12
12
import android .graphics .Bitmap ;
13
13
import android .graphics .Color ;
14
14
import android .graphics .drawable .Drawable ;
15
+ import android .support .annotation .ColorInt ;
15
16
import android .support .v4 .app .FragmentManager ;
17
+ import android .support .v4 .content .ContextCompat ;
16
18
import android .text .Html ;
17
19
import android .text .Spanned ;
18
20
import android .text .format .DateUtils ;
25
27
import android .widget .ImageView ;
26
28
import android .widget .LinearLayout ;
27
29
import android .widget .TextView ;
30
+ import android .widget .Toast ;
28
31
29
32
/**
30
33
* Adapter which stores Messages in a view, and generates LinearLayouts for
@@ -34,8 +37,17 @@ public class MessageAdapter extends ArrayAdapter<Message> {
34
37
35
38
private static final HTMLSchema schema = new HTMLSchema ();
36
39
40
+ private @ ColorInt int mDefaultStreamHeaderColor ;
41
+ private @ ColorInt int mDefaultHuddleHeaderColor ;
42
+ private @ ColorInt int mDefaultStreamMessageColor ;
43
+ private @ ColorInt int mDefaultHuddleMessageColor ;
44
+
37
45
public MessageAdapter (Context context , List <Message > objects ) {
38
46
super (context , 0 , objects );
47
+ mDefaultStreamHeaderColor = ContextCompat .getColor (context , R .color .stream_header );
48
+ mDefaultStreamMessageColor = ContextCompat .getColor (context , R .color .stream_body );
49
+ mDefaultHuddleHeaderColor = ContextCompat .getColor (context , R .color .huddle_header );
50
+ mDefaultHuddleMessageColor = ContextCompat .getColor (context , R .color .huddle_body );
39
51
}
40
52
41
53
public View getView (int position , View convertView , ViewGroup group ) {
@@ -44,52 +56,67 @@ public View getView(int position, View convertView, ViewGroup group) {
44
56
final Message message = getItem (position );
45
57
LinearLayout tile ;
46
58
47
- if (convertView == null
48
- || !(convertView .getClass ().equals (LinearLayout .class ))) {
59
+ if (convertView == null || !(convertView .getClass ().equals (LinearLayout .class ))) {
49
60
// We didn't get passed a tile, so construct a new one.
50
61
// In the future, we should inflate from a layout here.
51
- LayoutInflater inflater = ((Activity ) this .getContext ())
52
- .getLayoutInflater ();
53
- tile = (LinearLayout ) inflater .inflate (R .layout .message_tile ,
54
- group , false );
62
+ LayoutInflater inflater = ((Activity ) this .getContext ()).getLayoutInflater ();
63
+ tile = (LinearLayout ) inflater .inflate (R .layout .message_tile , group , false );
55
64
} else {
56
65
tile = (LinearLayout ) convertView ;
57
66
}
58
67
59
- LinearLayout envelopeTile = (LinearLayout ) tile
60
- .findViewById (R .id .envelopeTile );
61
- TextView display_recipient = (TextView ) tile
62
- .findViewById (R .id .displayRecipient );
63
-
64
- if (message .getType () == MessageType .STREAM_MESSAGE ) {
65
- envelopeTile .setBackgroundResource (R .drawable .stream_header );
68
+ LinearLayout envelopeTile = (LinearLayout ) tile .findViewById (R .id .envelopeTile );
69
+ TextView display_recipient = (TextView ) tile .findViewById (R .id .displayRecipient );
66
70
67
- Stream stream = message .getStream ();
68
- if (stream != null ) {
69
- envelopeTile .setBackgroundColor (stream .getColor ());
70
- }
71
+ if (message .getType () != MessageType .STREAM_MESSAGE ) {
72
+ envelopeTile .setBackgroundColor (mDefaultHuddleHeaderColor );
71
73
} else {
72
- envelopeTile .setBackgroundResource (R .drawable .huddle_header );
74
+ Stream stream = message .getStream ();
75
+ @ ColorInt int color = stream == null ? mDefaultStreamHeaderColor : stream .getColor ();
76
+ envelopeTile .setBackgroundColor (color );
73
77
}
74
78
75
79
if (message .getType () != MessageType .STREAM_MESSAGE ) {
76
80
display_recipient .setText (context .getString (R .string .huddle_text , message .getDisplayRecipient (context .app )));
77
81
display_recipient .setTextColor (Color .WHITE );
82
+ display_recipient .setOnClickListener (null );
78
83
} else {
79
84
display_recipient .setText (message .getDisplayRecipient (context .app ));
80
85
display_recipient .setTextColor (Color .BLACK );
86
+ display_recipient .setOnClickListener (new View .OnClickListener () {
87
+ @ Override
88
+ public void onClick (View v ) {
89
+ // TODO: narrow to stream.
90
+ Toast .makeText (v .getContext (), "Narrow to stream" , Toast .LENGTH_LONG ).show ();
91
+ }
92
+ });
81
93
}
82
94
83
95
TextView sep = (TextView ) tile .findViewById (R .id .sep );
84
96
TextView instance = (TextView ) tile .findViewById (R .id .instance );
85
97
86
- if (message .getType () == MessageType .STREAM_MESSAGE ) {
98
+ if (message .getType () != MessageType .STREAM_MESSAGE ) {
99
+ instance .setVisibility (View .GONE );
100
+ sep .setVisibility (View .GONE );
101
+ instance .setOnClickListener (null );
102
+ } else {
87
103
instance .setVisibility (View .VISIBLE );
88
104
sep .setVisibility (View .VISIBLE );
89
105
instance .setText (message .getSubject ());
106
+ instance .setOnClickListener (new View .OnClickListener () {
107
+ @ Override
108
+ public void onClick (View v ) {
109
+ // TODO: narrow to thread
110
+ Toast .makeText (v .getContext (), "Narrow to thread" , Toast .LENGTH_LONG ).show ();
111
+ }
112
+ });
113
+ }
114
+
115
+ LinearLayout messageTile = (LinearLayout ) tile .findViewById (R .id .messageTile );
116
+ if (message .getType () != MessageType .STREAM_MESSAGE ) {
117
+ messageTile .setBackgroundColor (mDefaultHuddleMessageColor );
90
118
} else {
91
- instance .setVisibility (View .GONE );
92
- sep .setVisibility (View .GONE );
119
+ messageTile .setBackgroundColor (mDefaultStreamMessageColor );
93
120
}
94
121
95
122
TextView senderName = (TextView ) tile .findViewById (R .id .senderName );
@@ -151,18 +178,6 @@ public void onClick(View view) {
151
178
task .loadBitmap (context , url , gravatar , message .getSender ());
152
179
}
153
180
154
- int color ;
155
-
156
- if (message .getType () != MessageType .STREAM_MESSAGE ) {
157
- color = context .getResources ().getColor (R .color .huddle_body );
158
- } else {
159
- color = context .getResources ().getColor (R .color .stream_body );
160
- }
161
-
162
- LinearLayout messageTile = (LinearLayout ) tile
163
- .findViewById (R .id .messageTile );
164
- messageTile .setBackgroundColor (color );
165
-
166
181
tile .setTag (R .id .messageID , message .getID ());
167
182
168
183
return tile ;
0 commit comments