Commit 09db9468 authored by Grigory Fedorov's avatar Grigory Fedorov

Chat messages layout changed: 3 text views instead of one. separated header...

Chat messages layout changed: 3 text views instead of one. separated header and unencrypted message.
parent 237894da
...@@ -16,10 +16,6 @@ package com.xabber.android.ui.adapter; ...@@ -16,10 +16,6 @@ package com.xabber.android.ui.adapter;
import android.content.Context; import android.content.Context;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.CharacterStyle;
import android.text.style.TextAppearanceSpan;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -27,7 +23,6 @@ import android.widget.ImageView; ...@@ -27,7 +23,6 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.SettingsManager.ChatsDivide;
import com.xabber.android.data.account.AccountItem; import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.avatar.AvatarManager; import com.xabber.android.data.extension.avatar.AvatarManager;
...@@ -65,11 +60,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo ...@@ -65,11 +60,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
*/ */
private final int appearanceStyle; private final int appearanceStyle;
/**
* Divider between header and body.
*/
private final String divider;
/** /**
* Text with extra information. * Text with extra information.
*/ */
...@@ -99,6 +89,9 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo ...@@ -99,6 +89,9 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
public TextView messageText; public TextView messageText;
public TextView messageTime; public TextView messageTime;
public TextView messageHeader;
public TextView messageUnencrypted;
public View messageBalloon;
MessageClickListener onClickListener; MessageClickListener onClickListener;
...@@ -108,6 +101,9 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo ...@@ -108,6 +101,9 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
messageText = (TextView) itemView.findViewById(R.id.message_text); messageText = (TextView) itemView.findViewById(R.id.message_text);
messageTime = (TextView) itemView.findViewById(R.id.message_time); messageTime = (TextView) itemView.findViewById(R.id.message_time);
messageHeader = (TextView) itemView.findViewById(R.id.message_header);
messageUnencrypted = (TextView) itemView.findViewById(R.id.message_unencrypted);
messageBalloon = itemView.findViewById(R.id.message_balloon);
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
} }
...@@ -153,13 +149,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo ...@@ -153,13 +149,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
isMUC = MUCManager.getInstance().hasRoom(account, user); isMUC = MUCManager.getInstance().hasRoom(account, user);
hint = null; hint = null;
appearanceStyle = SettingsManager.chatsAppearanceStyle(); appearanceStyle = SettingsManager.chatsAppearanceStyle();
ChatsDivide chatsDivide = SettingsManager.chatsDivide();
if (chatsDivide == ChatsDivide.always || (chatsDivide == ChatsDivide.portial
&& !context.getResources().getBoolean(R.bool.landscape))) {
divider = "\n";
} else {
divider = " ";
}
} }
@Override @Override
...@@ -249,35 +238,36 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo ...@@ -249,35 +238,36 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
} }
private void setUpMessage(MessageItem messageItem, Message message) { private void setUpMessage(MessageItem messageItem, Message message) {
SpannableStringBuilder builder = new SpannableStringBuilder();
final String resource = messageItem.getResource();
if (isMUC) { if (isMUC) {
append(builder, resource, new TextAppearanceSpan(context, R.style.ChatHeader_Time)); message.messageHeader.setText(messageItem.getResource());
append(builder, divider, new TextAppearanceSpan(context, R.style.ChatHeader)); message.messageHeader.setVisibility(View.VISIBLE);
} else {
message.messageHeader.setVisibility(View.GONE);
} }
Date delayTimestamp = messageItem.getDelayTimestamp();
if (messageItem.isUnencypted()) { if (messageItem.isUnencypted()) {
append(builder, context.getString(R.string.otr_unencrypted_message), message.messageUnencrypted.setVisibility(View.VISIBLE);
new TextAppearanceSpan(context, R.style.ChatHeader_Delay)); } else {
append(builder, divider, new TextAppearanceSpan(context, R.style.ChatHeader)); message.messageUnencrypted.setVisibility(View.GONE);
} }
Spannable text = messageItem.getSpannable(); message.messageText.setTextAppearance(context, appearanceStyle);
if (messageItem.getTag() == null) {
builder.append(text); String text = messageItem.getText().trim();
if (text.isEmpty()) {
message.itemView.setVisibility(View.GONE);
} else { } else {
append(builder, text, new TextAppearanceSpan(context, R.style.ChatRead)); message.itemView.setVisibility(View.VISIBLE);
message.messageText.setText(text);
} }
message.messageText.setTextAppearance(context, appearanceStyle); message.messageBalloon.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
message.messageText.setText(builder);
message.messageText.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
String time = StringUtils.getSmartTimeText(context, messageItem.getTimestamp()); String time = StringUtils.getSmartTimeText(context, messageItem.getTimestamp());
Date delayTimestamp = messageItem.getDelayTimestamp();
if (delayTimestamp != null) { if (delayTimestamp != null) {
String delay = context.getString(messageItem.isIncoming() ? R.string.chat_delay : R.string.chat_typed, String delay = context.getString(messageItem.isIncoming() ? R.string.chat_delay : R.string.chat_typed,
StringUtils.getSmartTimeText(context, delayTimestamp)); StringUtils.getSmartTimeText(context, delayTimestamp));
...@@ -302,12 +292,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo ...@@ -302,12 +292,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
message.statusIcon.setImageResource(messageIcon); message.statusIcon.setImageResource(messageIcon);
} }
private void append(SpannableStringBuilder builder, CharSequence text, CharacterStyle span) {
int start = builder.length();
builder.append(text);
builder.setSpan(span, start, start + text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private void setUpAvatar(MessageItem messageItem, IncomingMessage message) { private void setUpAvatar(MessageItem messageItem, IncomingMessage message) {
if (SettingsManager.chatsShowAvatars()) { if (SettingsManager.chatsShowAvatars()) {
final String account = messageItem.getChat().getAccount(); final String account = messageItem.getChat().getAccount();
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/message_layout"
tools:showIn="@layout/chat_viewer_outgoing_message">
<TextView
android:id="@+id/message_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="nickname@example.com"
android:textSize="12sp" />
<TextView
android:id="@+id/message_unencrypted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="11sp"
android:text="@string/otr_unencrypted_message" />
<TextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="160dp"
android:text="Some text\n line \nrgregrere" />
</LinearLayout>
\ No newline at end of file
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
android:src="@drawable/ic_avatar_1" android:src="@drawable/ic_avatar_1"
/> />
<TextView <FrameLayout
android:id="@+id/message_text" android:id="@+id/message_balloon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:autoLink="all"
android:layout_marginLeft="6dp" android:layout_marginLeft="6dp"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
...@@ -56,10 +57,11 @@ ...@@ -56,10 +57,11 @@
android:layout_marginRight="48dp" android:layout_marginRight="48dp"
android:layout_marginEnd="48dp" android:layout_marginEnd="48dp"
android:background="@drawable/message_incoming" android:background="@drawable/message_incoming">
android:text="Some text\n line \nrgregrere" <include layout="@layout/chat_message"/>
/>
</FrameLayout>
<TextView <TextView
android:id="@+id/message_time" android:id="@+id/message_time"
...@@ -68,11 +70,10 @@ ...@@ -68,11 +70,10 @@
android:layout_toRightOf="@+id/avatar" android:layout_toRightOf="@+id/avatar"
android:layout_toEndOf="@+id/avatar" android:layout_toEndOf="@+id/avatar"
android:layout_below="@id/message_text" android:layout_below="@+id/message_balloon"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:textAppearance="@style/ChatHeader.Time"
android:textSize="10sp" android:textSize="10sp"
android:text="Feb 19, 2015 4:39 PM" android:text="Feb 19, 2015 4:39 PM"
......
...@@ -19,16 +19,14 @@ ...@@ -19,16 +19,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
<TextView <FrameLayout
android:id="@+id/message_text" android:id="@+id/message_balloon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="12dp" android:layout_alignParentTop="true"
android:paddingTop="8dp" android:layout_alignParentRight="true"
android:paddingBottom="8dp" android:layout_alignParentEnd="true"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:layout_marginLeft="48dp" android:layout_marginLeft="48dp"
android:layout_marginStart="48dp" android:layout_marginStart="48dp"
...@@ -36,27 +34,30 @@ ...@@ -36,27 +34,30 @@
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:paddingLeft="12dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:minWidth="160dp"
android:text="Some text\n line \nrgregrere"
android:background="@drawable/message_outgoing_states" android:background="@drawable/message_outgoing_states"
android:layout_alignParentTop="true" >
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" /> <include layout="@layout/chat_message"/>
</FrameLayout>
<TextView <TextView
android:id="@+id/message_time" android:id="@+id/message_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/message_text" android:layout_below="@+id/message_balloon"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:paddingRight="16dp" android:paddingRight="16dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:textAppearance="@style/ChatHeader.Time"
android:textSize="10sp" android:textSize="10sp"
android:text="Feb 19, 2015 4:39 PM" android:text="Feb 19, 2015 4:39 PM"
......
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