Commit 92c39b27 authored by Grigory Fedorov's avatar Grigory Fedorov

Chat message view: time and status icon are drawn outside of balloon.

Refactoring of ChatMessageAdapter and layouts.
parent 656dbb91
...@@ -19,7 +19,6 @@ import android.text.Spannable; ...@@ -19,7 +19,6 @@ import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.CharacterStyle; import android.text.style.CharacterStyle;
import android.text.style.ImageSpan;
import android.text.style.TextAppearanceSpan; import android.text.style.TextAppearanceSpan;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -174,33 +173,21 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -174,33 +173,21 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
view = activity.getLayoutInflater().inflate(layoutId, parent, false); view = activity.getLayoutInflater().inflate(layoutId, parent, false);
} }
final MessageItem messageItem = (MessageItem) getItem(position); return setUpMessageView((MessageItem) getItem(position), view);
final boolean incoming = ((MessageItem) getItem(position)).isIncoming(); }
final String resource = messageItem.getResource();
TextView textView = (TextView) view.findViewById(R.id.text);
textView.setTextAppearance(activity, appearanceStyle);
textView.getBackground().setAlpha(127); private View setUpMessageView(MessageItem messageItem, View view) {
final boolean incoming = messageItem.isIncoming();
Spannable text = messageItem.getSpannable();
String time = StringUtils.getSmartTimeText(messageItem.getTimestamp());
ChatAction action = messageItem.getAction(); ChatAction action = messageItem.getAction();
Spannable text = messageItem.getSpannable();
SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableStringBuilder builder = new SpannableStringBuilder();
final String resource = messageItem.getResource();
if (action == null) { if (action == null) {
int messageIcon = R.drawable.ic_done_white_18dp;
if (!incoming) { if (!incoming) {
if (messageItem.isError()) { setStatusIcon(messageItem, view);
messageIcon = R.drawable.ic_clear_white_18dp;
} else if (!messageItem.isSent()) {
messageIcon = R.drawable.ic_redo_white_18dp;
} else if (!messageItem.isDelivered()) {
messageIcon = R.drawable.ic_query_builder_white_18dp;
}
} }
if (isMUC) { if (isMUC) {
...@@ -228,35 +215,43 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -228,35 +215,43 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
} else { } else {
append(builder, text, new TextAppearanceSpan(activity, R.style.ChatRead)); append(builder, text, new TextAppearanceSpan(activity, R.style.ChatRead));
} }
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
if (!incoming) {
ImageSpan imageSpan = new ImageSpan(activity, messageIcon);
if (messageIcon == R.drawable.ic_query_builder_white_18dp) {
imageSpan.getDrawable().setAlpha(0);
}
append(builder, " ", imageSpan);
}
} else { } else {
text = Emoticons.newSpannable(action.getText(activity, resource, text.toString())); text = Emoticons.newSpannable(action.getText(activity, resource, text.toString()));
Emoticons.getSmiledText(activity.getApplication(), text); Emoticons.getSmiledText(activity.getApplication(), text);
append(builder, text, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
} }
TextView textView = (TextView) view.findViewById(R.id.message_text);
textView.setTextAppearance(activity, appearanceStyle);
textView.getBackground().setAlpha(127);
textView.setText(builder); textView.setText(builder);
textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMovementMethod(LinkMovementMethod.getInstance());
String time = StringUtils.getSmartTimeText(messageItem.getTimestamp());
((TextView)view.findViewById(R.id.message_time)).setText(time);
if (incoming) { if (incoming) {
setUpAvatar(messageItem, view); setUpAvatar(messageItem, view);
} }
return view; return view;
} }
private void setStatusIcon(MessageItem messageItem, View view) {
ImageView messageStatusIcon = (ImageView) view.findViewById(R.id.message_status_icon);
messageStatusIcon.setVisibility(View.VISIBLE);
int messageIcon = R.drawable.ic_done_white_18dp;
if (messageItem.isError()) {
messageIcon = R.drawable.ic_clear_white_18dp;
} else if (!messageItem.isSent()) {
messageIcon = R.drawable.ic_redo_white_18dp;
} else if (!messageItem.isDelivered()) {
messageStatusIcon.setVisibility(View.INVISIBLE);
}
messageStatusIcon.setImageResource(messageIcon);
}
private void append(SpannableStringBuilder builder, CharSequence text, CharacterStyle span) { private void append(SpannableStringBuilder builder, CharSequence text, CharacterStyle span) {
int start = builder.length(); int start = builder.length();
builder.append(text); builder.append(text);
......
app/src/main/res/drawable-hdpi/msg_in.9.png

957 Bytes | W: | H:

app/src/main/res/drawable-hdpi/msg_in.9.png

769 Bytes | W: | H:

app/src/main/res/drawable-hdpi/msg_in.9.png
app/src/main/res/drawable-hdpi/msg_in.9.png
app/src/main/res/drawable-hdpi/msg_in.9.png
app/src/main/res/drawable-hdpi/msg_in.9.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/drawable-mdpi/msg_in.9.png

669 Bytes | W: | H:

app/src/main/res/drawable-mdpi/msg_in.9.png

500 Bytes | W: | H:

app/src/main/res/drawable-mdpi/msg_in.9.png
app/src/main/res/drawable-mdpi/msg_in.9.png
app/src/main/res/drawable-mdpi/msg_in.9.png
app/src/main/res/drawable-mdpi/msg_in.9.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -17,27 +17,32 @@ ...@@ -17,27 +17,32 @@
android:id="@+id/chat_message_incoming" android:id="@+id/chat_message_incoming"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
<ImageView <ImageView
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="32dip" android:layout_width="32dip"
android:layout_height="32dip" android:layout_height="32dip"
android:src="@drawable/avatar_1_1"
android:layout_alignParentBottom="true" android:layout_marginTop="3dp"
android:layout_marginLeft="6dp"
android:layout_alignTop="@+id/message_text"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /> android:layout_alignParentStart="true"
android:src="@drawable/avatar_1_1"
/>
<TextView <TextView
android:id="@+id/text" android:id="@+id/message_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/avatar" android:layout_toRightOf="@id/avatar"
android:layout_toEndOf="@id/avatar" android:layout_toEndOf="@id/avatar"
android:minWidth="142dp"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingTop="6dp" android:paddingTop="6dp"
android:paddingBottom="6dp" android:paddingBottom="6dp"
...@@ -47,16 +52,24 @@ ...@@ -47,16 +52,24 @@
android:layout_marginRight="48dp" android:layout_marginRight="48dp"
android:layout_marginEnd="48dp" android:layout_marginEnd="48dp"
android:layout_marginTop="4dp" android:background="@drawable/msg_in"
android:layout_marginBottom="4dp"
android:text="Some text\n line \nrgregrere"
/>
<TextView
android:id="@+id/message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp" android:layout_toRightOf="@+id/avatar"
android:layout_marginLeft="4dp" android:layout_toEndOf="@+id/avatar"
android:layout_below="@id/message_text"
android:text="Some text\n line \nrgregrere" android:paddingLeft="16dp"
android:background="@drawable/msg_in" android:textAppearance="@style/ChatHeader.Time"
/>
android:text="Feb 19, 2015 4:39 PM"
/>
</RelativeLayout> </RelativeLayout>
...@@ -12,13 +12,12 @@ ...@@ -12,13 +12,12 @@
You should have received a copy of the GNU General Public License, You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/. along with this program. If not, see http://www.gnu.org/licenses/.
--> -->
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="4dip" android:padding="4dip">
>
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -30,6 +29,7 @@ ...@@ -30,6 +29,7 @@
android:divider="@null" android:divider="@null"
android:dividerHeight="0dp" android:dividerHeight="0dp"
android:layout_above="@+id/chat_input" android:layout_above="@+id/chat_input"
tools:listitem="@layout/chat_viewer_outgoing_message"
/> />
<EditText <EditText
......
...@@ -17,11 +17,10 @@ ...@@ -17,11 +17,10 @@
android:id="@+id/chat_message_incoming" android:id="@+id/chat_message_incoming"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
<TextView <TextView
android:id="@+id/text" android:id="@+id/message_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -34,16 +33,38 @@ ...@@ -34,16 +33,38 @@
android:layout_marginLeft="48dp" android:layout_marginLeft="48dp"
android:layout_marginStart="48dp" android:layout_marginStart="48dp"
android:layout_marginTop="4dp" android:minWidth="160dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:text="Some text\n line \nrgregrere" android:text="Some text\n line \nrgregrere"
android:background="@drawable/msg_out" android:background="@drawable/msg_out"
android:gravity="end"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" /> android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/message_text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:textAppearance="@style/ChatHeader.Time"
android:text="Feb 19, 2015 4:39 PM"
/>
<ImageView
android:id="@+id/message_status_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/message_time"
android:layout_toLeftOf="@+id/message_time"
android:src="@drawable/ic_done_white_18dp"
/>
</RelativeLayout> </RelativeLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment