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; ...@@ -25,7 +25,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
...@@ -139,65 +138,51 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -139,65 +138,51 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
final int type = getItemViewType(position); 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) { if (type == TYPE_EMPTY) {
((TextView) view.findViewById(R.id.text)).setTextAppearance(activity, appearanceStyle); if (convertView == null) {
} return activity.getLayoutInflater().inflate(R.layout.chat_viewer_empty, parent, false);
} else { } else {
view = convertView; return convertView;
} }
if (type == TYPE_EMPTY) {
return view;
} }
if (type == TYPE_HINT) { 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 textView = ((TextView) view.findViewById(R.id.info));
textView.setText(hint); textView.setText(hint);
textView.setTextAppearance(activity, R.style.ChatInfo_Warning); textView.setTextAppearance(activity, R.style.ChatInfo_Warning);
return view; return view;
} }
if (type != TYPE_MESSAGE) {
throw new IllegalStateException();
}
final MessageItem messageItem = (MessageItem) getItem(position); final MessageItem messageItem = (MessageItem) getItem(position);
final String name; final boolean incoming = ((MessageItem) getItem(position)).isIncoming();
final String account = messageItem.getChat().getAccount(); final String account = messageItem.getChat().getAccount();
final String user = messageItem.getChat().getUser(); final String user = messageItem.getChat().getUser();
final String resource = messageItem.getResource(); final String resource = messageItem.getResource();
final boolean incoming = messageItem.isIncoming();
if (isMUC) { final int layoutId;
name = resource;
} else {
if (incoming) { if (incoming) {
name = RosterManager.getInstance().getName(account, user); layoutId = R.layout.chat_viewer_message;
} else { } 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 (incoming) {
if (view.getBackground() == null) { view.findViewById(R.id.text).setBackgroundResource(R.drawable.chat_bg);
view.setBackgroundResource(R.drawable.chat_bg); view.findViewById(R.id.text).getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
}
view.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
} else {
view.setBackgroundDrawable(null);
} }
Spannable text = messageItem.getSpannable(); Spannable text = messageItem.getSpannable();
...@@ -223,7 +208,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -223,7 +208,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader)); append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time)); append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader)); 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)); append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
Date timeStamp = messageItem.getDelayTimestamp(); Date timeStamp = messageItem.getDelayTimestamp();
...@@ -248,15 +235,17 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -248,15 +235,17 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
} else { } else {
append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time)); append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader)); 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); Emoticons.getSmiledText(activity.getApplication(), text);
append(builder, text, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay)); append(builder, text, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
} }
textView.setText(builder); textView.setText(builder);
textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMovementMethod(LinkMovementMethod.getInstance());
if (incoming) {
if (SettingsManager.chatsShowAvatars()) { if (SettingsManager.chatsShowAvatars()) {
avatarView.setVisibility(View.VISIBLE); 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)); avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else { } else {
if (isMUC) { if (isMUC) {
...@@ -269,10 +258,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -269,10 +258,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
avatarView.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user)); avatarView.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
} }
} }
((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule(RelativeLayout.RIGHT_OF, R.id.avatar);
} else { } else {
avatarView.setVisibility(View.GONE); avatarView.setVisibility(View.GONE);
((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule(RelativeLayout.RIGHT_OF, 0); }
} }
return view; return view;
} }
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
android:stackFromBottom="true" android:stackFromBottom="true"
android:transcriptMode="normal" android:transcriptMode="normal"
android:smoothScrollbar="false" android:smoothScrollbar="false"
android:divider="@null"
android:dividerHeight="0dp"
/> />
<TextView <TextView
android:id="@+id/chat_page" android:id="@+id/chat_page"
......
...@@ -14,19 +14,22 @@ ...@@ -14,19 +14,22 @@
--> -->
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="4dip"
android:paddingBottom="4dip"
android:background="@drawable/chat_bg"> >
<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:layout_marginLeft="4dip"
android:src="@drawable/avatar_1_1" android:src="@drawable/avatar_1_1"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
/> />
<TextView <TextView
...@@ -34,7 +37,20 @@ ...@@ -34,7 +37,20 @@
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: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> </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