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;
import android.content.Context;
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.View;
import android.view.ViewGroup;
......@@ -27,7 +23,6 @@ import android.widget.ImageView;
import android.widget.TextView;
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.AccountManager;
import com.xabber.android.data.extension.avatar.AvatarManager;
......@@ -65,11 +60,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
*/
private final int appearanceStyle;
/**
* Divider between header and body.
*/
private final String divider;
/**
* Text with extra information.
*/
......@@ -99,6 +89,9 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
public TextView messageText;
public TextView messageTime;
public TextView messageHeader;
public TextView messageUnencrypted;
public View messageBalloon;
MessageClickListener onClickListener;
......@@ -108,6 +101,9 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
messageText = (TextView) itemView.findViewById(R.id.message_text);
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);
}
......@@ -153,13 +149,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
isMUC = MUCManager.getInstance().hasRoom(account, user);
hint = null;
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
......@@ -249,35 +238,36 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
}
private void setUpMessage(MessageItem messageItem, Message message) {
SpannableStringBuilder builder = new SpannableStringBuilder();
final String resource = messageItem.getResource();
if (isMUC) {
append(builder, resource, new TextAppearanceSpan(context, R.style.ChatHeader_Time));
append(builder, divider, new TextAppearanceSpan(context, R.style.ChatHeader));
message.messageHeader.setText(messageItem.getResource());
message.messageHeader.setVisibility(View.VISIBLE);
} else {
message.messageHeader.setVisibility(View.GONE);
}
Date delayTimestamp = messageItem.getDelayTimestamp();
if (messageItem.isUnencypted()) {
append(builder, context.getString(R.string.otr_unencrypted_message),
new TextAppearanceSpan(context, R.style.ChatHeader_Delay));
append(builder, divider, new TextAppearanceSpan(context, R.style.ChatHeader));
message.messageUnencrypted.setVisibility(View.VISIBLE);
} else {
message.messageUnencrypted.setVisibility(View.GONE);
}
Spannable text = messageItem.getSpannable();
if (messageItem.getTag() == null) {
builder.append(text);
message.messageText.setTextAppearance(context, appearanceStyle);
String text = messageItem.getText().trim();
if (text.isEmpty()) {
message.itemView.setVisibility(View.GONE);
} 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.messageText.setText(builder);
message.messageText.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
message.messageBalloon.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
String time = StringUtils.getSmartTimeText(context, messageItem.getTimestamp());
Date delayTimestamp = messageItem.getDelayTimestamp();
if (delayTimestamp != null) {
String delay = context.getString(messageItem.isIncoming() ? R.string.chat_delay : R.string.chat_typed,
StringUtils.getSmartTimeText(context, delayTimestamp));
......@@ -302,12 +292,6 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
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) {
if (SettingsManager.chatsShowAvatars()) {
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 @@
android:src="@drawable/ic_avatar_1"
/>
<TextView
android:id="@+id/message_text"
<FrameLayout
android:id="@+id/message_balloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -49,6 +49,7 @@
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:autoLink="all"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
......@@ -56,10 +57,11 @@
android:layout_marginRight="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
android:id="@+id/message_time"
......@@ -68,11 +70,10 @@
android:layout_toRightOf="@+id/avatar"
android:layout_toEndOf="@+id/avatar"
android:layout_below="@id/message_text"
android:layout_below="@+id/message_balloon"
android:paddingLeft="16dp"
android:textAppearance="@style/ChatHeader.Time"
android:textSize="10sp"
android:text="Feb 19, 2015 4:39 PM"
......
......@@ -19,16 +19,14 @@
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/message_text"
<FrameLayout
android:id="@+id/message_balloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="48dp"
android:layout_marginStart="48dp"
......@@ -36,27 +34,30 @@
android:layout_marginRight="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:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
>
<include layout="@layout/chat_message"/>
</FrameLayout>
<TextView
android:id="@+id/message_time"
android:layout_width="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_alignParentEnd="true"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:textAppearance="@style/ChatHeader.Time"
android:textSize="10sp"
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