Commit 3cb5ec88 authored by Grigory Fedorov's avatar Grigory Fedorov

Same layout for account group, contact and active chat. New client icons.

parent 7a8b27e9
...@@ -111,6 +111,8 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -111,6 +111,8 @@ public abstract class AbstractChat extends BaseEntity {
protected Date creationTime = new Date(); protected Date creationTime = new Date();
private boolean isLastMessageIncoming;
protected AbstractChat(final String account, final String user) { protected AbstractChat(final String account, final String user) {
super(account, user); super(account, user);
threadId = StringUtils.randomString(12); threadId = StringUtils.randomString(12);
...@@ -341,8 +343,7 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -341,8 +343,7 @@ public abstract class AbstractChat extends BaseEntity {
* @param action * @param action
*/ */
public void newAction(String resource, String text, ChatAction action) { public void newAction(String resource, String text, ChatAction action) {
newMessage(resource, text, action, null, true, false, false, false, newMessage(resource, text, action, null, true, false, false, false, true);
true);
} }
/** /**
...@@ -451,10 +452,9 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -451,10 +452,9 @@ public abstract class AbstractChat extends BaseEntity {
for (int index = messages.size() - 1; index >= 0; index--) { for (int index = messages.size() - 1; index >= 0; index--) {
MessageItem messageItem = messages.get(index); MessageItem messageItem = messages.get(index);
if (messageItem.getAction() == null) { if (messageItem.getAction() == null) {
String lastMessage = messageItem.getText(); lastText = messageItem.getText();
lastText = messageItem.isIncoming() ? "< " + lastMessage : "> " + lastMessage;
lastTime = messageItem.getTimestamp(); lastTime = messageItem.getTimestamp();
isLastMessageIncoming = messageItem.isIncoming();
return; return;
} }
} }
...@@ -516,7 +516,7 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -516,7 +516,7 @@ public abstract class AbstractChat extends BaseEntity {
* @return Last incoming message's text. Empty string if last message is * @return Last incoming message's text. Empty string if last message is
* outgoing. * outgoing.
*/ */
protected String getLastText() { public String getLastText() {
return lastText; return lastText;
} }
...@@ -684,4 +684,8 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -684,4 +684,8 @@ public abstract class AbstractChat extends BaseEntity {
public void updateCreationTime() { public void updateCreationTime() {
creationTime.setTime(System.currentTimeMillis()); creationTime.setTime(System.currentTimeMillis());
} }
public boolean isLastMessageIncoming() {
return isLastMessageIncoming;
}
} }
...@@ -2,15 +2,15 @@ package com.xabber.android.ui.adapter; ...@@ -2,15 +2,15 @@ package com.xabber.android.ui.adapter;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.extension.capability.ClientSoftware; import com.xabber.android.data.extension.capability.ClientSoftware;
import com.xabber.android.data.extension.muc.MUCManager; import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.ui.ContactEditor; import com.xabber.android.ui.ContactEditor;
...@@ -18,62 +18,48 @@ import com.xabber.android.ui.ContactViewer; ...@@ -18,62 +18,48 @@ import com.xabber.android.ui.ContactViewer;
import com.xabber.android.utils.StringUtils; import com.xabber.android.utils.StringUtils;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Date;
public class ContactItemInflater { public class ContactItemInflater {
static class ContactViewHolder {
final ImageView color;
final ImageView avatar;
final TextView name;
final TextView status;
final ImageView offlineShadow;
final ImageView statusMode;
final ImageView clientSoftware;
public ContactViewHolder(View view) {
color = (ImageView) view.findViewById(R.id.color);
avatar = (ImageView) view.findViewById(R.id.avatar);
name = (TextView) view.findViewById(R.id.name);
status = (TextView) view.findViewById(R.id.status);
offlineShadow = (ImageView) view.findViewById(R.id.offline_shadow);
statusMode = (ImageView) view.findViewById(R.id.status_icon);
clientSoftware = (ImageView) view.findViewById(R.id.client_software);
}
}
final Context context; final Context context;
private int[] accountMainColors; private int[] accountMainColors;
private final int elevation;
public ContactItemInflater(Context context) { public ContactItemInflater(Context context) {
this.context = context; this.context = context;
accountMainColors = context.getResources().getIntArray(R.array.account_action_bar); accountMainColors = context.getResources().getIntArray(R.array.account_action_bar);
elevation = context.getResources().getDimensionPixelSize(R.dimen.contact_elevation);
} }
public View setUpContactView(View convertView, ViewGroup parent, final AbstractContact abstractContact) { public View setUpContactView(View convertView, ViewGroup parent, final AbstractContact contact) {
final View view; final View view;
final ContactViewHolder viewHolder; final ContactListItemViewHolder viewHolder;
if (convertView == null) { if (convertView == null) {
view = LayoutInflater.from(context).inflate(R.layout.base_contact_item, parent, false); view = LayoutInflater.from(context).inflate(R.layout.contact_list_item, parent, false);
viewHolder = new ContactViewHolder(view); viewHolder = new ContactListItemViewHolder(view);
viewHolder.statusIconSeparator.setVisibility(View.INVISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setElevation(elevation);
}
view.setTag(viewHolder); view.setTag(viewHolder);
} else { } else {
view = convertView; view = convertView;
viewHolder = (ContactViewHolder) view.getTag(); viewHolder = (ContactListItemViewHolder) view.getTag();
} }
if (abstractContact.isConnected()) { if (contact.isConnected()) {
viewHolder.offlineShadow.setVisibility(View.GONE); viewHolder.offlineShadow.setVisibility(View.GONE);
} else { } else {
viewHolder.offlineShadow.setVisibility(View.VISIBLE); viewHolder.offlineShadow.setVisibility(View.VISIBLE);
} }
int colorLevel = abstractContact.getColorLevel(); int colorLevel = contact.getColorLevel();
viewHolder.color.setImageDrawable(new ColorDrawable(accountMainColors[colorLevel])); viewHolder.color.setImageDrawable(new ColorDrawable(accountMainColors[colorLevel]));
viewHolder.color.setVisibility(View.VISIBLE);
if (SettingsManager.contactsShowAvatars()) { if (SettingsManager.contactsShowAvatars()) {
viewHolder.avatar.setVisibility(View.VISIBLE); viewHolder.avatar.setVisibility(View.VISIBLE);
viewHolder.avatar.setImageDrawable(abstractContact.getAvatarForContactList()); viewHolder.avatar.setImageDrawable(contact.getAvatarForContactList());
} else { } else {
viewHolder.avatar.setVisibility(View.GONE); viewHolder.avatar.setVisibility(View.GONE);
} }
...@@ -81,50 +67,54 @@ public class ContactItemInflater { ...@@ -81,50 +67,54 @@ public class ContactItemInflater {
viewHolder.avatar.setOnClickListener(new View.OnClickListener() { viewHolder.avatar.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onAvatarClick(abstractContact); onAvatarClick(contact);
} }
}); });
viewHolder.name.setText(abstractContact.getName()); viewHolder.name.setText(contact.getName());
String statusText; String statusText;
if (MessageManager.getInstance() viewHolder.outgoingMessageIndicator.setVisibility(View.GONE);
.hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) {
String lastMessage = MessageManager.getInstance()
.getLastText(abstractContact.getAccount(), abstractContact.getUser());
Date lastTime = MessageManager.getInstance()
.getLastTime(abstractContact.getAccount(), abstractContact.getUser());
statusText = StringUtils.getSmartTimeText(context, lastTime) + " " + lastMessage;
} else { ClientSoftware clientSoftware = contact.getClientSoftware();
statusText = abstractContact.getStatusText();
}
statusText = statusText.trim(); MessageManager messageManager = MessageManager.getInstance();
if ("".equals(statusText)) { if (messageManager.hasActiveChat(contact.getAccount(), contact.getUser())) {
viewHolder.status.setVisibility(View.GONE);
} else {
viewHolder.status.setText(statusText);
viewHolder.status.setVisibility(View.VISIBLE);
}
viewHolder.statusMode.setImageLevel(abstractContact.getStatusMode().getStatusLevel()); AbstractChat chat = messageManager.getChat(contact.getAccount(), contact.getUser());
ClientSoftware clientSoftware = abstractContact.getClientSoftware(); statusText = chat.getLastText();
if (clientSoftware == ClientSoftware.unknown) {
viewHolder.clientSoftware.setVisibility(View.INVISIBLE); viewHolder.smallRightText.setText(StringUtils.getSmartTimeText(context, chat.getLastTime()));
} else { viewHolder.smallRightText.setVisibility(View.VISIBLE);
viewHolder.clientSoftware.setVisibility(View.VISIBLE);
viewHolder.clientSoftware.setImageLevel(clientSoftware.ordinal());
}
if (MessageManager.getInstance().hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) { if (!chat.isLastMessageIncoming()) {
viewHolder.outgoingMessageIndicator.setText(context.getString(R.string.sender_is_you) + ": ");
viewHolder.outgoingMessageIndicator.setVisibility(View.VISIBLE);
viewHolder.outgoingMessageIndicator.setTextColor(accountMainColors[colorLevel]);
}
view.setBackgroundColor(context.getResources().getColor(R.color.grey_50)); view.setBackgroundColor(context.getResources().getColor(R.color.grey_50));
viewHolder.smallRightIcon.setImageResource(R.drawable.ic_client_small);
viewHolder.smallRightIcon.setVisibility(View.VISIBLE);
viewHolder.smallRightIcon.setImageLevel(clientSoftware.ordinal());
viewHolder.largeClientIcon.setVisibility(View.GONE);
} else { } else {
statusText = contact.getStatusText().trim();
if (statusText.isEmpty()) {
statusText = context.getString(contact.getStatusMode().getStringID());
}
viewHolder.smallRightText.setVisibility(View.GONE);
view.setBackgroundColor(context.getResources().getColor(R.color.grey_300)); view.setBackgroundColor(context.getResources().getColor(R.color.grey_300));
viewHolder.smallRightIcon.setVisibility(View.GONE);
viewHolder.largeClientIcon.setVisibility(View.VISIBLE);
viewHolder.largeClientIcon.setImageLevel(clientSoftware.ordinal());
} }
viewHolder.secondLineMessage.setText(statusText.trim());
viewHolder.statusIcon.setImageLevel(contact.getStatusMode().getStatusLevel());
return view; return view;
} }
......
package com.xabber.android.ui.adapter;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.xabber.androiddev.R;
class ContactListItemViewHolder {
final ImageView color;
final ImageView avatar;
final TextView name;
final TextView outgoingMessageIndicator;
final TextView secondLineMessage;
final TextView smallRightText;
final ImageView smallRightIcon;
final ImageView largeClientIcon;
final View statusIconSeparator;
final ImageView statusIcon;
final ImageView offlineShadow;
public ContactListItemViewHolder(View view) {
color = (ImageView) view.findViewById(R.id.account_color_indicator);
avatar = (ImageView) view.findViewById(R.id.avatar);
name = (TextView) view.findViewById(R.id.contact_list_item_name);
outgoingMessageIndicator = (TextView) view.findViewById(R.id.outgoing_message_indicator);
secondLineMessage = (TextView) view.findViewById(R.id.second_line_message);
smallRightIcon = (ImageView) view.findViewById(R.id.small_right_icon);
smallRightText = (TextView) view.findViewById(R.id.small_right_text);
largeClientIcon = (ImageView) view.findViewById(R.id.client_icon_large);
statusIconSeparator = view.findViewById(R.id.status_icon_separator);
statusIcon = (ImageView) view.findViewById(R.id.contact_list_item_status_icon);
offlineShadow = (ImageView) view.findViewById(R.id.offline_shadow);
}
}
...@@ -18,6 +18,7 @@ import android.app.Activity; ...@@ -18,6 +18,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -31,14 +32,10 @@ import com.xabber.android.data.account.AccountManager; ...@@ -31,14 +32,10 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode; import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.avatar.AvatarManager; import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.extension.capability.ClientSoftware;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.Group; import com.xabber.android.data.roster.Group;
import com.xabber.android.data.roster.GroupManager; import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.ShowOfflineMode; import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.android.ui.ContactEditor;
import com.xabber.android.ui.ContactViewer; import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -102,6 +99,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -102,6 +99,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
final ArrayList<BaseEntity> baseEntities = new ArrayList<>(); final ArrayList<BaseEntity> baseEntities = new ArrayList<>();
protected Locale locale = Locale.getDefault(); protected Locale locale = Locale.getDefault();
private final ContactItemInflater contactItemInflater; private final ContactItemInflater contactItemInflater;
private final int accountElevation;
public GroupedContactAdapter(Activity activity, OnClickListener onClickListener) { public GroupedContactAdapter(Activity activity, OnClickListener onClickListener) {
this.activity = activity; this.activity = activity;
...@@ -117,6 +115,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -117,6 +115,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
contactItemInflater = new ContactItemInflater(activity); contactItemInflater = new ContactItemInflater(activity);
accountElevation = activity.getResources().getDimensionPixelSize(R.dimen.account_group_elevation);
this.onClickListener = onClickListener; this.onClickListener = onClickListener;
} }
...@@ -226,15 +226,22 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -226,15 +226,22 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
private View getAccountView(int position, View convertView, ViewGroup parent) { private View getAccountView(int position, View convertView, ViewGroup parent) {
final View view; final View view;
final AccountViewHolder viewHolder; final ContactListItemViewHolder viewHolder;
if (convertView == null) { if (convertView == null) {
view = layoutInflater.inflate(R.layout.account_group_item, parent, false); view = layoutInflater.inflate(R.layout.contact_list_item, parent, false);
viewHolder = new ContactListItemViewHolder(view);
viewHolder.outgoingMessageIndicator.setVisibility(View.GONE);
viewHolder.color.setVisibility(View.INVISIBLE);
viewHolder.largeClientIcon.setVisibility(View.GONE);
viewHolder = new AccountViewHolder(view); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setElevation(accountElevation);
}
view.setTag(viewHolder); view.setTag(viewHolder);
} else { } else {
view = convertView; view = convertView;
viewHolder = (AccountViewHolder) view.getTag(); viewHolder = (ContactListItemViewHolder) view.getTag();
} }
final AccountConfiguration configuration = (AccountConfiguration) getItem(position); final AccountConfiguration configuration = (AccountConfiguration) getItem(position);
...@@ -251,8 +258,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -251,8 +258,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
final int level = AccountManager.getInstance().getColorLevel(account); final int level = AccountManager.getInstance().getColorLevel(account);
view.setBackgroundDrawable(new ColorDrawable(accountGroupColors[level])); view.setBackgroundDrawable(new ColorDrawable(accountGroupColors[level]));
viewHolder.jid.setText(GroupManager.getInstance().getGroupName(account, configuration.getUser())); viewHolder.name.setText(GroupManager.getInstance().getGroupName(account, configuration.getUser()));
viewHolder.contactCounter.setText(configuration.getOnline() + "/" + configuration.getTotal()); viewHolder.smallRightText.setText(configuration.getOnline() + "/" + configuration.getTotal());
AccountItem accountItem = AccountManager.getInstance().getAccount(account); AccountItem accountItem = AccountManager.getInstance().getAccount(account);
String statusText = accountItem.getStatusText().trim(); String statusText = accountItem.getStatusText().trim();
...@@ -261,7 +268,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -261,7 +268,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
statusText = activity.getString(accountItem.getDisplayStatusMode().getStringID()); statusText = activity.getString(accountItem.getDisplayStatusMode().getStringID());
} }
viewHolder.status.setText(statusText); viewHolder.secondLineMessage.setText(statusText);
if (SettingsManager.contactsShowAvatars()) { if (SettingsManager.contactsShowAvatars()) {
viewHolder.avatar.setVisibility(View.VISIBLE); viewHolder.avatar.setVisibility(View.VISIBLE);
...@@ -288,7 +295,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -288,7 +295,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
} }
} }
viewHolder.offlineContactsIndicator.setImageLevel(showOfflineMode.ordinal()); viewHolder.smallRightIcon.setImageLevel(showOfflineMode.ordinal());
StatusMode statusMode = AccountManager.getInstance().getAccount(configuration.getAccount()).getDisplayStatusMode(); StatusMode statusMode = AccountManager.getInstance().getAccount(configuration.getAccount()).getDisplayStatusMode();
...@@ -563,29 +571,6 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -563,29 +571,6 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
} }
} }
private static class AccountViewHolder {
final TextView jid;
final TextView status;
final TextView contactCounter;
final ImageView statusIcon;
final ImageView avatar;
final ImageView offlineContactsIndicator;
final ImageView offlineShadow;
public AccountViewHolder(View view) {
jid = (TextView) view.findViewById(R.id.account_jid);
status = (TextView) view.findViewById(R.id.account_status);
contactCounter = (TextView) view.findViewById(R.id.contact_counter);
statusIcon = (ImageView) view.findViewById(R.id.account_status_icon);
avatar = (ImageView) view.findViewById(R.id.avatar);
offlineContactsIndicator = (ImageView) view.findViewById(R.id.offline_contacts_indicator);
offlineShadow = (ImageView) view.findViewById(R.id.offline_shadow);
}
}
public interface OnClickListener { public interface OnClickListener {
void onAccountMenuClick(View view, String account); void onAccountMenuClick(View view, String account);
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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