Commit 1a820d39 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatMessageAdapter: chat messaged redesigned: outgoing messages are drawn to the right.

Name is not drawn.
parent 4ace1632
......@@ -25,7 +25,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.xabber.android.data.SettingsManager;
......@@ -139,65 +138,51 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int type = getItemViewType(position);
final View view;
if (convertView == null) {
final int resource;
switch (type) {
case TYPE_MESSAGE:
resource = R.layout.chat_viewer_message;
break;
case TYPE_HINT:
resource = R.layout.chat_viewer_info;
break;
case TYPE_EMPTY:
resource = R.layout.chat_viewer_empty;
break;
default:
throw new IllegalStateException();
}
view = activity.getLayoutInflater().inflate(resource, parent, false);
if (type == TYPE_MESSAGE) {
((TextView) view.findViewById(R.id.text)).setTextAppearance(activity, appearanceStyle);
}
if (type == TYPE_EMPTY) {
if (convertView == null) {
return activity.getLayoutInflater().inflate(R.layout.chat_viewer_empty, parent, false);
} else {
view = convertView;
return convertView;
}
if (type == TYPE_EMPTY) {
return view;
}
if (type == TYPE_HINT) {
View view = convertView;
if (convertView == null) {
view = activity.getLayoutInflater().inflate(R.layout.chat_viewer_info, parent, false);
}
TextView textView = ((TextView) view.findViewById(R.id.info));
textView.setText(hint);
textView.setTextAppearance(activity, R.style.ChatInfo_Warning);
return view;
}
if (type != TYPE_MESSAGE) {
throw new IllegalStateException();
}
final MessageItem messageItem = (MessageItem) getItem(position);
final String name;
final boolean incoming = ((MessageItem) getItem(position)).isIncoming();
final String account = messageItem.getChat().getAccount();
final String user = messageItem.getChat().getUser();
final String resource = messageItem.getResource();
final boolean incoming = messageItem.isIncoming();
if (isMUC) {
name = resource;
} else {
final int layoutId;
if (incoming) {
name = RosterManager.getInstance().getName(account, user);
layoutId = R.layout.chat_viewer_message;
} else {
name = AccountManager.getInstance().getNickName(account);
}
layoutId = R.layout.chat_viewer_message_own;
}
View view = activity.getLayoutInflater().inflate(layoutId, parent, false);
((TextView) view.findViewById(R.id.text)).setTextAppearance(activity, appearanceStyle);
if (incoming) {
if (view.getBackground() == null) {
view.setBackgroundResource(R.drawable.chat_bg);
}
view.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
} else {
view.setBackgroundDrawable(null);
view.findViewById(R.id.text).setBackgroundResource(R.drawable.chat_bg);
view.findViewById(R.id.text).getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
}
Spannable text = messageItem.getSpannable();
......@@ -223,7 +208,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
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));
append(builder, name, new TextAppearanceSpan(activity, R.style.ChatHeader_Name));
if (isMUC) {
append(builder, resource, new TextAppearanceSpan(activity, R.style.ChatHeader_Name));
}
append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
Date timeStamp = messageItem.getDelayTimestamp();
......@@ -248,15 +235,17 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
} else {
append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
text = Emoticons.newSpannable(action.getText(activity, name, text.toString()));
text = Emoticons.newSpannable(action.getText(activity, resource, text.toString()));
Emoticons.getSmiledText(activity.getApplication(), text);
append(builder, text, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
}
textView.setText(builder);
textView.setMovementMethod(LinkMovementMethod.getInstance());
if (incoming) {
if (SettingsManager.chatsShowAvatars()) {
avatarView.setVisibility(View.VISIBLE);
if (!incoming || (isMUC && MUCManager.getInstance().getNickname(account, user).equalsIgnoreCase(resource))) {
if ((isMUC && MUCManager.getInstance().getNickname(account, user).equalsIgnoreCase(resource))) {
avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
if (isMUC) {
......@@ -269,10 +258,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
avatarView.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
}
}
((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule(RelativeLayout.RIGHT_OF, R.id.avatar);
} else {
avatarView.setVisibility(View.GONE);
((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule(RelativeLayout.RIGHT_OF, 0);
}
}
return view;
}
......
......@@ -32,6 +32,8 @@
android:stackFromBottom="true"
android:transcriptMode="normal"
android:smoothScrollbar="false"
android:divider="@null"
android:dividerHeight="0dp"
/>
<TextView
android:id="@+id/chat_page"
......
......@@ -14,19 +14,22 @@
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:id="@+id/chat_message_incoming"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:paddingBottom="4dip"
android:background="@drawable/chat_bg">
>
<ImageView
android:id="@+id/avatar"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_marginLeft="4dip"
android:src="@drawable/avatar_1_1"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
/>
<TextView
......@@ -34,7 +37,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/avatar"
android:paddingLeft="4dip"
android:layout_toEndOf="@id/avatar"
android:padding="4dp"
android:layout_marginRight="48dp"
android:layout_marginEnd="48dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:text="Some text\n line \nrgregrere"
android:background="@drawable/chat_bg"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013, Redsolution LTD. All rights reserved.
This file is part of Xabber project; you can redistribute it and/or
modify it under the terms of the GNU General Public License, Version 3.
Xabber is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chat_message_incoming"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_marginLeft="48dp"
android:layout_marginStart="48dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:text="Some text\n line \nrgregrere"
android:background="@color/grey_600"
android:gravity="end"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</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