Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 5b9067f

Browse files
committed
Clean up look and feel of messages in thread
1 parent 3da7421 commit 5b9067f

File tree

3 files changed

+116
-81
lines changed

3 files changed

+116
-81
lines changed

app/src/main/java/com/zulip/android/MessageAdapter.java

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import android.graphics.Bitmap;
1313
import android.graphics.Color;
1414
import android.graphics.drawable.Drawable;
15+
import android.support.annotation.ColorInt;
1516
import android.support.v4.app.FragmentManager;
17+
import android.support.v4.content.ContextCompat;
1618
import android.text.Html;
1719
import android.text.Spanned;
1820
import android.text.format.DateUtils;
@@ -25,6 +27,7 @@
2527
import android.widget.ImageView;
2628
import android.widget.LinearLayout;
2729
import android.widget.TextView;
30+
import android.widget.Toast;
2831

2932
/**
3033
* Adapter which stores Messages in a view, and generates LinearLayouts for
@@ -34,8 +37,17 @@ public class MessageAdapter extends ArrayAdapter<Message> {
3437

3538
private static final HTMLSchema schema = new HTMLSchema();
3639

40+
private @ColorInt int mDefaultStreamHeaderColor;
41+
private @ColorInt int mDefaultHuddleHeaderColor;
42+
private @ColorInt int mDefaultStreamMessageColor;
43+
private @ColorInt int mDefaultHuddleMessageColor;
44+
3745
public MessageAdapter(Context context, List<Message> objects) {
3846
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);
3951
}
4052

4153
public View getView(int position, View convertView, ViewGroup group) {
@@ -44,52 +56,67 @@ public View getView(int position, View convertView, ViewGroup group) {
4456
final Message message = getItem(position);
4557
LinearLayout tile;
4658

47-
if (convertView == null
48-
|| !(convertView.getClass().equals(LinearLayout.class))) {
59+
if (convertView == null || !(convertView.getClass().equals(LinearLayout.class))) {
4960
// We didn't get passed a tile, so construct a new one.
5061
// 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);
5564
} else {
5665
tile = (LinearLayout) convertView;
5766
}
5867

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);
6670

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);
7173
} 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);
7377
}
7478

7579
if (message.getType() != MessageType.STREAM_MESSAGE) {
7680
display_recipient.setText(context.getString(R.string.huddle_text, message.getDisplayRecipient(context.app)));
7781
display_recipient.setTextColor(Color.WHITE);
82+
display_recipient.setOnClickListener(null);
7883
} else {
7984
display_recipient.setText(message.getDisplayRecipient(context.app));
8085
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+
});
8193
}
8294

8395
TextView sep = (TextView) tile.findViewById(R.id.sep);
8496
TextView instance = (TextView) tile.findViewById(R.id.instance);
8597

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 {
87103
instance.setVisibility(View.VISIBLE);
88104
sep.setVisibility(View.VISIBLE);
89105
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);
90118
} else {
91-
instance.setVisibility(View.GONE);
92-
sep.setVisibility(View.GONE);
119+
messageTile.setBackgroundColor(mDefaultStreamMessageColor);
93120
}
94121

95122
TextView senderName = (TextView) tile.findViewById(R.id.senderName);
@@ -151,18 +178,6 @@ public void onClick(View view) {
151178
task.loadBitmap(context, url, gravatar, message.getSender());
152179
}
153180

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-
166181
tile.setTag(R.id.messageID, message.getID());
167182

168183
return tile;
Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,110 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:id="@+id/messageTile"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:background="@android:color/background_light"
7-
android:orientation="vertical" >
8+
android:orientation="vertical"
9+
>
810

911
<LinearLayout
1012
android:id="@+id/envelopeTile"
1113
android:layout_width="match_parent"
12-
android:layout_height="wrap_content" >
14+
android:layout_height="wrap_content"
15+
android:padding="8dp"
16+
tools:background="@android:color/holo_purple"
17+
>
1318

1419
<TextView
1520
android:id="@+id/displayRecipient"
1621
android:layout_width="wrap_content"
1722
android:layout_height="wrap_content"
1823
android:gravity="center_horizontal"
19-
android:paddingBottom="5dp"
20-
android:paddingLeft="10dp"
21-
android:paddingRight="10dp"
22-
android:paddingTop="5dp"
23-
android:text="Stream"
24-
android:textStyle="bold" />
24+
android:text="@string/stream_txt"
25+
android:textStyle="bold"
26+
tools:text="Stream"
27+
/>
2528

2629
<TextView
2730
android:id="@+id/sep"
2831
android:layout_width="wrap_content"
2932
android:layout_height="wrap_content"
30-
android:text=" &#x276f; " />
33+
android:paddingStart="8dp"
34+
android:paddingEnd="8dp"
35+
android:text="@string/arrow" />
3136

3237
<TextView
3338
android:id="@+id/instance"
3439
android:layout_width="wrap_content"
3540
android:layout_height="wrap_content"
36-
android:paddingBottom="5dp"
37-
android:paddingLeft="10dp"
38-
android:paddingRight="10dp"
39-
android:paddingTop="5dp"
40-
android:text="Subject" />
41+
android:text="@string/subject" />
4142

4243
</LinearLayout>
4344

4445
<RelativeLayout
45-
android:id="@+id/senderTile"
4646
android:layout_width="match_parent"
47-
android:layout_height="wrap_content" >
48-
49-
<TextView
50-
android:id="@+id/timestamp"
51-
android:layout_width="wrap_content"
52-
android:layout_height="wrap_content"
53-
android:layout_alignBaseline="@+id/senderName"
54-
android:layout_alignBottom="@+id/senderName"
55-
android:layout_alignParentRight="true"
56-
android:layout_marginRight="14dp"
57-
android:text="timestamp"
58-
android:textColor="@android:color/darker_gray" />
59-
47+
android:layout_height="wrap_content"
48+
android:paddingTop="8dp"
49+
android:paddingStart="8dp"
50+
android:paddingLeft="8dp"
51+
android:paddingEnd="8dp"
52+
android:paddingRight="8dp"
53+
>
6054
<ImageView
6155
android:id="@+id/gravatar"
6256
android:layout_width="45dp"
6357
android:layout_height="37dp"
64-
android:paddingLeft="10dp"
65-
android:paddingTop="2dp"
6658
android:scaleType="centerInside"
6759
android:src="@android:drawable/presence_online" />
6860

61+
62+
<LinearLayout
63+
android:id="@+id/senderTile"
64+
android:layout_width="match_parent"
65+
android:layout_height="wrap_content"
66+
android:orientation="horizontal"
67+
android:gravity="center_vertical"
68+
android:layout_toEndOf="@id/gravatar"
69+
android:layout_toRightOf="@id/gravatar"
70+
android:paddingStart="8dp"
71+
android:paddingLeft="8dp"
72+
tools:background="#FFF"
73+
>
74+
6975
<TextView
7076
android:id="@+id/senderName"
77+
android:layout_weight="1"
78+
android:layout_width="0dp"
79+
android:layout_height="wrap_content"
80+
android:textStyle="bold"
81+
tools:text="Sender &lt;[email protected]&gt;"
82+
/>
83+
84+
<TextView
85+
android:id="@+id/timestamp"
7186
android:layout_width="wrap_content"
7287
android:layout_height="wrap_content"
73-
android:layout_alignParentTop="true"
74-
android:layout_toRightOf="@+id/gravatar"
75-
android:paddingBottom="5dp"
76-
android:paddingLeft="10dp"
77-
android:paddingRight="10dp"
78-
android:paddingTop="5dp"
79-
android:text="Sender &lt;[email protected]>"
80-
android:textStyle="bold" />
88+
android:textColor="@android:color/darker_gray"
89+
tools:text="17:45"/>
8190

82-
</RelativeLayout>
8391

84-
<TextView
85-
android:id="@+id/contentView"
86-
android:layout_width="match_parent"
87-
android:layout_height="wrap_content"
88-
android:paddingBottom="10dp"
89-
android:paddingLeft="10dp"
90-
android:paddingRight="10dp"
91-
android:paddingTop="0dp"
92-
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mollis pretium purus, faucibus accumsan enim placerat non. " />
92+
</LinearLayout>
93+
<TextView
94+
android:id="@+id/contentView"
95+
android:layout_width="match_parent"
96+
android:layout_height="wrap_content"
97+
android:layout_toEndOf="@id/gravatar"
98+
android:layout_toRightOf="@id/gravatar"
99+
android:layout_below="@id/senderTile"
100+
android:layout_marginTop="4dp"
101+
android:layout_marginBottom="8dp"
102+
android:paddingStart="8dp"
103+
android:paddingLeft="8dp"
104+
android:paddingEnd="16dp"
105+
android:paddingRight="16dp"
106+
tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mollis pretium purus, faucibus accumsan enim placerat non. " />
107+
108+
</RelativeLayout>
93109

94110
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@
3232
<string name="reply_to_private_message">Reply to Private Message</string>
3333
<string name="narrow_to_this_conversation">Narrow to this conversation</string>
3434
<string name="copy_message">Copy Message</string>
35+
<string name="stream_txt">Stream</string>
36+
<string name="arrow">❯</string>
37+
<string name="subject">Subject</string>
38+
<string name="timestamp">timestamp</string>
3539

3640
</resources>

0 commit comments

Comments
 (0)