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