Commit fdc5c2da authored by Grigory Fedorov's avatar Grigory Fedorov

ChatMessageAdapter: time and icon moved after text. refactoring.

parent bca36b8c
...@@ -165,8 +165,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -165,8 +165,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
final MessageItem messageItem = (MessageItem) getItem(position); final MessageItem messageItem = (MessageItem) getItem(position);
final boolean incoming = ((MessageItem) getItem(position)).isIncoming(); 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 String resource = messageItem.getResource();
final int layoutId; final int layoutId;
...@@ -177,41 +176,37 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -177,41 +176,37 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
} }
View view = activity.getLayoutInflater().inflate(layoutId, parent, false); View view = activity.getLayoutInflater().inflate(layoutId, parent, false);
TextView textView = (TextView) view.findViewById(R.id.text);
((TextView) view.findViewById(R.id.text)).setTextAppearance(activity, appearanceStyle); textView.setTextAppearance(activity, appearanceStyle);
if (incoming) { if (incoming) {
view.findViewById(R.id.text).setBackgroundResource(R.drawable.chat_bg); textView.setBackgroundResource(R.drawable.chat_bg);
view.findViewById(R.id.text).getBackground().setLevel(AccountManager.getInstance().getColorLevel(account)); textView.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
} }
Spannable text = messageItem.getSpannable(); Spannable text = messageItem.getSpannable();
TextView textView = (TextView) view.findViewById(R.id.text);
ImageView avatarView = (ImageView) view.findViewById(R.id.avatar);
ChatAction action = messageItem.getAction();
String time = StringUtils.getSmartTimeText(messageItem.getTimestamp()); String time = StringUtils.getSmartTimeText(messageItem.getTimestamp());
ChatAction action = messageItem.getAction();
SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableStringBuilder builder = new SpannableStringBuilder();
if (action == null) { if (action == null) {
int messageResource = R.drawable.ic_message_delivered; int messageIcon = R.drawable.ic_message_delivered;
if (!incoming) { if (!incoming) {
if (messageItem.isError()) { if (messageItem.isError()) {
messageResource = R.drawable.ic_message_has_error; messageIcon = R.drawable.ic_message_has_error;
} else if (!messageItem.isSent()) { } else if (!messageItem.isSent()) {
messageResource = R.drawable.ic_message_not_sent; messageIcon = R.drawable.ic_message_not_sent;
} else if (!messageItem.isDelivered()) { } else if (!messageItem.isDelivered()) {
messageResource = R.drawable.ic_message_not_delivered; messageIcon = R.drawable.ic_message_not_delivered;
} }
} }
append(builder, " ", new ImageSpan(activity, messageResource));
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 (isMUC) { if (isMUC) {
append(builder, resource, new TextAppearanceSpan(activity, R.style.ChatHeader_Name)); 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();
...@@ -221,6 +216,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -221,6 +216,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
append(builder, delay, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay)); append(builder, delay, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader)); append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
} }
if (messageItem.isUnencypted()) { if (messageItem.isUnencypted()) {
append(builder, activity.getString(R.string.otr_unencrypted_message), append(builder, activity.getString(R.string.otr_unencrypted_message),
new TextAppearanceSpan(activity, R.style.ChatHeader_Delay)); new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
...@@ -232,37 +228,56 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -232,37 +228,56 @@ 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));
} }
} else {
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));
if (!incoming) {
append(builder, " ", new ImageSpan(activity, messageIcon));
}
} 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, 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.setText(builder); textView.setText(builder);
textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMovementMethod(LinkMovementMethod.getInstance());
if (incoming) { if (incoming) {
if (SettingsManager.chatsShowAvatars()) { setUpAvatar(messageItem, view);
avatarView.setVisibility(View.VISIBLE); }
if ((isMUC && MUCManager.getInstance().getNickname(account, user).equalsIgnoreCase(resource))) { return view;
avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account)); }
} else {
if (isMUC) { private void setUpAvatar(MessageItem messageItem, View view) {
if ("".equals(resource)) { ImageView avatarView = (ImageView) view.findViewById(R.id.avatar);
avatarView.setImageDrawable(AvatarManager.getInstance().getRoomAvatar(user));
} else { if (SettingsManager.chatsShowAvatars()) {
avatarView.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(user + "/" + resource)); final String account = messageItem.getChat().getAccount();
} final String user = messageItem.getChat().getUser();
final String resource = messageItem.getResource();
avatarView.setVisibility(View.VISIBLE);
if ((isMUC && MUCManager.getInstance().getNickname(account, user).equalsIgnoreCase(resource))) {
avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
if (isMUC) {
if ("".equals(resource)) {
avatarView.setImageDrawable(AvatarManager.getInstance().getRoomAvatar(user));
} else { } else {
avatarView.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user)); avatarView.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(user + "/" + resource));
} }
} else {
avatarView.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
} }
} else {
avatarView.setVisibility(View.GONE);
} }
} else {
avatarView.setVisibility(View.GONE);
} }
return view;
} }
public String getAccount() { public String getAccount() {
......
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