Commit 1681a8e3 authored by Grigory Fedorov's avatar Grigory Fedorov

Recent chats and contacts drawn with the same ContactItemInflater.

Background do not move while chat scrolling.
parent 9d903829
...@@ -129,6 +129,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -129,6 +129,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
viewPager = (ViewPager) findViewById(R.id.pager); viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(chatViewerAdapter); viewPager.setAdapter(chatViewerAdapter);
viewPager.setOnPageChangeListener(this); viewPager.setOnPageChangeListener(this);
viewPager.getBackground().setAlpha(30);
selectPage(account, user, false); selectPage(account, user, false);
} }
......
...@@ -125,8 +125,6 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -125,8 +125,6 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
} }
}); });
view.getBackground().setAlpha(40);
sendButton = (ImageButton) view.findViewById(R.id.button_send_message); sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp); sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
......
package com.xabber.android.ui.adapter; package com.xabber.android.ui.adapter;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater;
import android.view.View; 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.TextView;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -22,12 +16,11 @@ public class ChatListAdapter extends BaseAdapter { ...@@ -22,12 +16,11 @@ public class ChatListAdapter extends BaseAdapter {
private List<AbstractChat> chats; private List<AbstractChat> chats;
private final Context context; private final ContactItemInflater contactItemInflater;
public ChatListAdapter(Context context) { public ChatListAdapter(Context context) {
this.context = context;
chats = new ArrayList<>(); chats = new ArrayList<>();
contactItemInflater = new ContactItemInflater(context);
} }
public void updateChats(List<AbstractChat> chats) { public void updateChats(List<AbstractChat> chats) {
...@@ -53,33 +46,9 @@ public class ChatListAdapter extends BaseAdapter { ...@@ -53,33 +46,9 @@ public class ChatListAdapter extends BaseAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView == null) {
view = LayoutInflater.from(context).inflate(R.layout.chat_list_item, parent, false);
} else {
view = convertView;
}
final AbstractChat abstractChat = (AbstractChat) getItem(position); final AbstractChat abstractChat = (AbstractChat) getItem(position);
final AbstractContact abstractContact = RosterManager.getInstance() final AbstractContact abstractContact = RosterManager.getInstance()
.getBestContact(abstractChat.getAccount(), abstractChat.getUser()); .getBestContact(abstractChat.getAccount(), abstractChat.getUser());
return contactItemInflater.setUpContactView(convertView, parent, abstractContact);
((TextView) view.findViewById(R.id.name)).setText(abstractContact.getName());
((ImageView) view.findViewById(R.id.color)).setImageLevel(abstractContact.getColorLevel());
final ImageView avatarView = (ImageView) view.findViewById(R.id.avatar);
avatarView.setImageDrawable(abstractContact.getAvatar());
final TextView textView = (TextView) view.findViewById(R.id.text);
String statusText = MessageManager.getInstance().getLastText(
abstractContact.getAccount(), abstractContact.getUser());
textView.setText(statusText);
boolean newMessages = NotificationManager.getInstance()
.getNotificationMessageCount(abstractChat.getAccount(), abstractChat.getUser()) > 0;
textView.setTextAppearance(context, newMessages ? R.style.ChatList_Notification
: R.style.ChatList_Normal);
return view;
} }
} }
package com.xabber.android.ui.adapter;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
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.MessageManager;
import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.ui.ContactEditor;
import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R;
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;
public ContactItemInflater(Context context) {
this.context = context;
accountMainColors = context.getResources().getIntArray(R.array.account_action_bar);
}
public View setUpContactView(View convertView, ViewGroup parent, final AbstractContact abstractContact) {
final View view;
final ContactViewHolder viewHolder;
if (convertView == null) {
view = LayoutInflater.from(context).inflate(R.layout.base_contact_item, parent, false);
viewHolder = new ContactViewHolder(view);
view.setTag(viewHolder);
} else {
view = convertView;
viewHolder = (ContactViewHolder) view.getTag();
}
if (abstractContact.isConnected()) {
viewHolder.offlineShadow.setVisibility(View.GONE);
} else {
viewHolder.offlineShadow.setVisibility(View.VISIBLE);
}
int colorLevel = abstractContact.getColorLevel();
viewHolder.color.setImageDrawable(new ColorDrawable(accountMainColors[colorLevel]));
if (SettingsManager.contactsShowAvatars()) {
viewHolder.avatar.setVisibility(View.VISIBLE);
viewHolder.avatar.setImageDrawable(abstractContact.getAvatarForContactList());
} else {
viewHolder.avatar.setVisibility(View.GONE);
}
viewHolder.avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) {
context.startActivity(ContactViewer.createIntent(context,
abstractContact.getAccount(), abstractContact.getUser()));
} else {
context.startActivity(ContactEditor.createIntent(context,
abstractContact.getAccount(), abstractContact.getUser()));
}
}
});
viewHolder.name.setText(abstractContact.getName());
String statusText;
if (MessageManager.getInstance()
.hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) {
statusText = MessageManager.getInstance()
.getLastText(abstractContact.getAccount(), abstractContact.getUser());
} else {
statusText = abstractContact.getStatusText();
}
statusText = statusText.trim();
if ("".equals(statusText)) {
viewHolder.status.setVisibility(View.GONE);
} else {
viewHolder.status.setText(statusText);
viewHolder.status.setVisibility(View.VISIBLE);
}
viewHolder.statusMode.setImageLevel(abstractContact.getStatusMode().getStatusLevel());
ClientSoftware clientSoftware = abstractContact.getClientSoftware();
if (clientSoftware == ClientSoftware.unknown) {
viewHolder.clientSoftware.setVisibility(View.INVISIBLE);
} else {
viewHolder.clientSoftware.setVisibility(View.VISIBLE);
viewHolder.clientSoftware.setImageLevel(clientSoftware.ordinal());
}
if (MessageManager.getInstance().hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) {
view.setBackgroundColor(context.getResources().getColor(R.color.grey_50));
} else {
view.setBackgroundColor(context.getResources().getColor(R.color.grey_300));
}
return view;
}
}
...@@ -93,7 +93,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -93,7 +93,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
private final LayoutInflater layoutInflater; private final LayoutInflater layoutInflater;
private final Activity activity; private final Activity activity;
private int[] accountMainColors;
private int[] accountGroupColors; private int[] accountGroupColors;
private final int[] accountSubgroupColors; private final int[] accountSubgroupColors;
private final int activeChatsColor; private final int activeChatsColor;
...@@ -101,6 +101,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -101,6 +101,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;
public GroupedContactAdapter(Activity activity, OnClickListener onClickListener) { public GroupedContactAdapter(Activity activity, OnClickListener onClickListener) {
this.activity = activity; this.activity = activity;
...@@ -109,11 +110,13 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -109,11 +110,13 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
Resources resources = activity.getResources(); Resources resources = activity.getResources();
accountMainColors = resources.getIntArray(R.array.account_action_bar);
accountGroupColors = resources.getIntArray(R.array.account_200); accountGroupColors = resources.getIntArray(R.array.account_200);
accountSubgroupColors = resources.getIntArray(R.array.account_50); accountSubgroupColors = resources.getIntArray(R.array.account_50);
activeChatsColor = resources.getColor(R.color.color_primary_light); activeChatsColor = resources.getColor(R.color.color_primary_light);
contactItemInflater = new ContactItemInflater(activity);
this.onClickListener = onClickListener; this.onClickListener = onClickListener;
} }
...@@ -351,85 +354,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -351,85 +354,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
} }
private View getContactView(int position, View convertView, ViewGroup parent) { private View getContactView(int position, View convertView, ViewGroup parent) {
final View view;
final ContactViewHolder viewHolder;
if (convertView == null) {
view = layoutInflater.inflate(R.layout.base_contact_item, parent, false);
viewHolder = new ContactViewHolder(view);
view.setTag(viewHolder);
} else {
view = convertView;
viewHolder = (ContactViewHolder) view.getTag();
}
final AbstractContact abstractContact = (AbstractContact) getItem(position); final AbstractContact abstractContact = (AbstractContact) getItem(position);
return contactItemInflater.setUpContactView(convertView, parent, abstractContact);
if (abstractContact.isConnected()) {
viewHolder.offlineShadow.setVisibility(View.GONE);
} else {
viewHolder.offlineShadow.setVisibility(View.VISIBLE);
}
int colorLevel = abstractContact.getColorLevel();
viewHolder.color.setImageDrawable(new ColorDrawable(accountMainColors[colorLevel]));
if (SettingsManager.contactsShowAvatars()) {
viewHolder.avatar.setVisibility(View.VISIBLE);
viewHolder.avatar.setImageDrawable(abstractContact.getAvatarForContactList());
} else {
viewHolder.avatar.setVisibility(View.GONE);
}
viewHolder.avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) {
activity.startActivity(ContactViewer.createIntent(activity,
abstractContact.getAccount(), abstractContact.getUser()));
} else {
activity.startActivity(ContactEditor.createIntent(activity,
abstractContact.getAccount(), abstractContact.getUser()));
}
}
});
viewHolder.name.setText(abstractContact.getName());
String statusText;
if (MessageManager.getInstance()
.hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) {
statusText = MessageManager.getInstance()
.getLastText(abstractContact.getAccount(), abstractContact.getUser());
} else {
statusText = abstractContact.getStatusText();
}
statusText = statusText.trim();
if ("".equals(statusText)) {
viewHolder.status.setVisibility(View.GONE);
} else {
viewHolder.status.setText(statusText);
viewHolder.status.setVisibility(View.VISIBLE);
}
viewHolder.statusMode.setImageLevel(abstractContact.getStatusMode().getStatusLevel());
ClientSoftware clientSoftware = abstractContact.getClientSoftware();
if (clientSoftware == ClientSoftware.unknown) {
viewHolder.clientSoftware.setVisibility(View.INVISIBLE);
} else {
viewHolder.clientSoftware.setVisibility(View.VISIBLE);
viewHolder.clientSoftware.setImageLevel(clientSoftware.ordinal());
}
if (MessageManager.getInstance().hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) {
view.setBackgroundColor(activity.getResources().getColor(R.color.grey_50));
} else {
view.setBackgroundColor(activity.getResources().getColor(R.color.grey_300));
}
return view;
} }
/** /**
...@@ -620,27 +546,6 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -620,27 +546,6 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
onChange(); onChange();
} }
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);
}
}
/** /**
* Holder for views in contact list group. * Holder for views in contact list group.
*/ */
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
>
...@@ -10,7 +11,7 @@ ...@@ -10,7 +11,7 @@
android:id="@+id/pager" android:id="@+id/pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/chat_background_repeat"
/> />
<LinearLayout <LinearLayout
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/contact_list_item_height" android:layout_height="@dimen/contact_list_item_height"
android:elevation="1dp" android:elevation="1dp"
android:background="@color/grey_300" >
>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
<?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/.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingTop="4dip"
android:paddingRight="6dip"
android:paddingBottom="4dip"
android:gravity="center_vertical"
>
<ImageView
android:id="@+id/color"
android:layout_width="wrap_content"
android:layout_height="32dip"
android:visibility="gone"
android:src="@android:color/transparent"
/>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/avatar"
android:layout_width="@dimen/avatar_size_toolbar"
android:layout_height="@dimen/avatar_size_toolbar"
android:layout_toRightOf="@id/color"
android:src="@drawable/ic_avatar_1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dip"
android:orientation="vertical"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textStyle="bold"
android:singleLine="true"
android:ellipsize="marquee"
android:text="name"
android:textColor="?android:attr/textColorPrimary"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:singleLine="true"
android:ellipsize="marquee"
android:text="message"
android:textColor="?android:attr/textColorSecondary"
/>
</LinearLayout>
</LinearLayout>
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/chat_background_repeat"
> >
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/chat_background_repeat" android:background="@color/grey_300"
> >
<include layout="@layout/toolbar_default" /> <include layout="@layout/toolbar_default" />
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@android:id/list" android:id="@android:id/list"
android:layout_marginTop="15dp" android:layout_marginTop="20dp"
android:divider="@null"
android:dividerHeight="0dp"
/> />
</LinearLayout> </LinearLayout>
\ No newline at end of file
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