Display contact's initials as avatar if available

This commit is contained in:
Sylvain Berfini 2018-10-22 17:43:42 +02:00
parent b6e4dc4740
commit 54933523c3
18 changed files with 193 additions and 214 deletions

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/colorD"/>
<size android:width="35dp" android:height="35dp"/>
</shape>

View file

@ -31,29 +31,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<RelativeLayout <include layout="@layout/contact_avatar"/>
android:id="@+id/avatar_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -31,28 +31,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<RelativeLayout <include layout="@layout/contact_avatar"/>
android:id="@+id/avatar_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/date" android:id="@+id/date"

View file

@ -31,28 +31,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<RelativeLayout <include layout="@layout/contact_avatar"/>
android:id="@+id/avatar_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/date" android:id="@+id/date"

View file

@ -32,24 +32,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<ImageView <include layout="@layout/contact_avatar"/>
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
</RelativeLayout> </RelativeLayout>

View file

@ -19,24 +19,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<ImageView <include layout="@layout/contact_avatar"/>
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
</RelativeLayout> </RelativeLayout>

View file

@ -32,28 +32,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<RelativeLayout <include layout="@layout/contact_avatar"/>
android:id="@+id/avatar_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/date" android:id="@+id/date"

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/avatar_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/generated_avatar"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/generated_avatar_bg"
style="@style/font25"
android:gravity="center"
android:maxLines="1"/>
</RelativeLayout>

View file

@ -39,24 +39,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<ImageView <include layout="@layout/contact_avatar"/>
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
</RelativeLayout> </RelativeLayout>

View file

@ -70,24 +70,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<ImageView <include layout="@layout/contact_avatar"/>
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
</RelativeLayout> </RelativeLayout>

View file

@ -13,24 +13,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">
<ImageView <include layout="@layout/contact_avatar"/>
android:id="@+id/contact_picture"
android:src="@drawable/avatar"
android:contentDescription="@string/content_description_contact_picture"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
<ImageView
android:id="@+id/mask"
android:src="@drawable/avatar_mask"
android:layout_width="35dp"
android:layout_height="35dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"/>
</RelativeLayout> </RelativeLayout>

View file

@ -40,6 +40,7 @@ import org.linphone.contacts.LinphoneContact;
import org.linphone.core.Address; import org.linphone.core.Address;
import org.linphone.core.Call; import org.linphone.core.Call;
import org.linphone.core.CallLog; import org.linphone.core.CallLog;
import org.linphone.ui.ContactAvatar;
import org.linphone.ui.SelectableAdapter; import org.linphone.ui.SelectableAdapter;
import org.linphone.ui.SelectableHelper; import org.linphone.ui.SelectableHelper;
@ -55,6 +56,7 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
public CheckBox select; public CheckBox select;
public ImageView callDirection; public ImageView callDirection;
public ImageView contactPicture; public ImageView contactPicture;
public TextView generatedAvatar;
public RelativeLayout CallContact; public RelativeLayout CallContact;
public LinearLayout separator; public LinearLayout separator;
public TextView separatorText; public TextView separatorText;
@ -67,6 +69,7 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
select = view.findViewById(R.id.delete); select = view.findViewById(R.id.delete);
callDirection = view.findViewById(R.id.icon); callDirection = view.findViewById(R.id.icon);
contactPicture = view.findViewById(R.id.contact_picture); contactPicture = view.findViewById(R.id.contact_picture);
generatedAvatar = view.findViewById(R.id.generated_avatar);
CallContact = view.findViewById(R.id.history_click); CallContact = view.findViewById(R.id.history_click);
separator = view.findViewById(R.id.separator); separator = view.findViewById(R.id.separator);
separatorText = view.findViewById(R.id.separator_text); separatorText = view.findViewById(R.id.separator_text);
@ -167,19 +170,22 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address); LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address);
String displayName = null; String displayName = null;
final String sipUri = (address != null) ? address.asString() : ""; final String sipUri = (address != null) ? address.asString() : "";
if (c != null) { if (c != null) {
displayName = c.getFullName(); displayName = c.getFullName();
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, c.getThumbnailUri());
} else {
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
} }
if (displayName == null) { if (displayName == null) {
holder.contact.setText(LinphoneUtils.getAddressDisplayName(sipUri)); holder.contact.setText(LinphoneUtils.getAddressDisplayName(sipUri));
} else { } else {
holder.contact.setText(displayName); holder.contact.setText(displayName);
} }
if (c != null) {
ContactAvatar.displayAvatar(c, holder.contactPicture, holder.generatedAvatar);
} else {
ContactAvatar.displayAvatar(displayName, holder.generatedAvatar);
}
holder.detail.setVisibility(isEditionEnabled() ? View.INVISIBLE : View.VISIBLE); holder.detail.setVisibility(isEditionEnabled() ? View.INVISIBLE : View.VISIBLE);
holder.detail.setOnClickListener(!isEditionEnabled() ? holder.detail.setOnClickListener(!isEditionEnabled() ?
new View.OnClickListener() { new View.OnClickListener() {

View file

@ -39,6 +39,7 @@ import org.linphone.core.ChatMessage;
import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomCapabilities; import org.linphone.core.ChatRoomCapabilities;
import org.linphone.core.Content; import org.linphone.core.Content;
import org.linphone.ui.ContactAvatar;
public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private Bitmap mDefaultBitmap; private Bitmap mDefaultBitmap;
@ -51,6 +52,7 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.
public TextView unreadMessages; public TextView unreadMessages;
public CheckBox delete; public CheckBox delete;
public ImageView contactPicture; public ImageView contactPicture;
public TextView generatedAvatar;
public ImageView lastMessageFileTransfer; public ImageView lastMessageFileTransfer;
public Context mContext; public Context mContext;
public ChatRoom mRoom; public ChatRoom mRoom;
@ -70,6 +72,7 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.
unreadMessages = itemView.findViewById(R.id.unreadMessages); unreadMessages = itemView.findViewById(R.id.unreadMessages);
delete = itemView.findViewById(R.id.delete_chatroom); delete = itemView.findViewById(R.id.delete_chatroom);
contactPicture = itemView.findViewById(R.id.contact_picture); contactPicture = itemView.findViewById(R.id.contact_picture);
generatedAvatar = itemView.findViewById(R.id.generated_avatar);
lastMessageFileTransfer = itemView.findViewById(R.id.lastMessageFileTransfer); lastMessageFileTransfer = itemView.findViewById(R.id.lastMessageFileTransfer);
mListener = listener; mListener = listener;
@ -153,14 +156,20 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.
} }
public void getAvatar(ChatRoom mRoom) { public void getAvatar(ChatRoom mRoom) {
if (mRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress()); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress());
if (contact != null) { if (contact != null) {
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), contactPicture, ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress()).getThumbnailUri()); ContactAvatar.displayAvatar(contact, contactPicture, generatedAvatar);
} else {
String username = mRoom.getPeerAddress().getDisplayName();
if (username == null) {
username = mRoom.getPeerAddress().getUsername();
}
ContactAvatar.displayAvatar(username, generatedAvatar);
}
} else { } else {
if (mRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()))
contactPicture.setImageBitmap(mDefaultBitmap);
else
contactPicture.setImageBitmap(mDefaultGroupBitmap); contactPicture.setImageBitmap(mDefaultGroupBitmap);
generatedAvatar.setVisibility(View.GONE);
} }
} }

View file

@ -35,6 +35,7 @@ import org.linphone.contacts.ContactAddress;
import org.linphone.contacts.LinphoneContact; import org.linphone.contacts.LinphoneContact;
import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoom;
import org.linphone.core.Participant; import org.linphone.core.Participant;
import org.linphone.ui.ContactAvatar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -44,6 +45,7 @@ public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.View
public static class ViewHolder extends RecyclerView.ViewHolder { public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView name; public TextView name;
public ImageView avatar; public ImageView avatar;
public TextView generatedAvatar;
public ImageView delete; public ImageView delete;
public LinearLayout isAdmin; public LinearLayout isAdmin;
public LinearLayout isNotAdmin; public LinearLayout isNotAdmin;
@ -52,6 +54,7 @@ public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.View
super(view); super(view);
name = view.findViewById(R.id.name); name = view.findViewById(R.id.name);
avatar = view.findViewById(R.id.contact_picture); avatar = view.findViewById(R.id.contact_picture);
generatedAvatar = view.findViewById(R.id.generated_avatar);
delete = view.findViewById(R.id.delete); delete = view.findViewById(R.id.delete);
isAdmin = view.findViewById(R.id.isAdminLayout); isAdmin = view.findViewById(R.id.isAdminLayout);
isNotAdmin = view.findViewById(R.id.isNotAdminLayout); isNotAdmin = view.findViewById(R.id.isNotAdminLayout);
@ -79,11 +82,14 @@ public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.View
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) { public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
final ContactAddress ca = (ContactAddress) getItem(position); final ContactAddress ca = (ContactAddress) getItem(position);
LinphoneContact c = ca.getContact(); LinphoneContact c = ca.getContact();
ImageView avatar = holder.avatar;
holder.name.setText((c.getFullName() != null) ? c.getFullName() : holder.name.setText((c.getFullName() != null) ? c.getFullName() :
(ca.getDisplayName() != null) ? ca.getDisplayName() : ca.getUsername()); (ca.getDisplayName() != null) ? ca.getDisplayName() : ca.getUsername());
if (c.hasPhoto()) {
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), avatar, c.getThumbnailUri()); if (c != null) {
ContactAvatar.displayAvatar(c, holder.avatar, holder.generatedAvatar);
} else {
ContactAvatar.displayAvatar(holder.name.getText().toString(), holder.generatedAvatar);
} }
holder.delete.setOnClickListener(new View.OnClickListener() { holder.delete.setOnClickListener(new View.OnClickListener() {

View file

@ -45,6 +45,7 @@ import org.linphone.core.ChatMessageListenerStub;
import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoom;
import org.linphone.core.Core; import org.linphone.core.Core;
import org.linphone.core.ParticipantImdnState; import org.linphone.core.ParticipantImdnState;
import org.linphone.ui.ContactAvatar;
public class ImdnFragment extends Fragment { public class ImdnFragment extends Fragment {
private LayoutInflater mInflater; private LayoutInflater mInflater;
@ -205,13 +206,15 @@ public class ImdnFragment extends Fragment {
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address); String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false); View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false);
ImageView contactPicture = v.findViewById(R.id.contact_picture);
TextView generatedAvatar = v.findViewById(R.id.generated_avatar);
v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE); v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE);
((TextView) v.findViewById(R.id.time)).setText(LinphoneUtils.timestampToHumanDate(getActivity(), participant.getStateChangeTime(), R.string.messages_date_format)); ((TextView) v.findViewById(R.id.time)).setText(LinphoneUtils.timestampToHumanDate(getActivity(), participant.getStateChangeTime(), R.string.messages_date_format));
((TextView) v.findViewById(R.id.name)).setText(participantDisplayName); ((TextView) v.findViewById(R.id.name)).setText(participantDisplayName);
if (participantContact != null && participantContact.hasPhoto()) { if (participantContact != null) {
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri()); ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
} else { } else {
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
} }
mRead.addView(v); mRead.addView(v);
@ -228,13 +231,15 @@ public class ImdnFragment extends Fragment {
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address); String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false); View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false);
ImageView contactPicture = v.findViewById(R.id.contact_picture);
TextView generatedAvatar = v.findViewById(R.id.generated_avatar);
v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE); v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE);
((TextView) v.findViewById(R.id.time)).setText(LinphoneUtils.timestampToHumanDate(getActivity(), participant.getStateChangeTime(), R.string.messages_date_format)); ((TextView) v.findViewById(R.id.time)).setText(LinphoneUtils.timestampToHumanDate(getActivity(), participant.getStateChangeTime(), R.string.messages_date_format));
((TextView) v.findViewById(R.id.name)).setText(participantDisplayName); ((TextView) v.findViewById(R.id.name)).setText(participantDisplayName);
if (participantContact != null && participantContact.hasPhoto()) { if (participantContact != null) {
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri()); ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
} else { } else {
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
} }
mDelivered.addView(v); mDelivered.addView(v);
@ -251,13 +256,15 @@ public class ImdnFragment extends Fragment {
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address); String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false); View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false);
ImageView contactPicture = v.findViewById(R.id.contact_picture);
TextView generatedAvatar = v.findViewById(R.id.generated_avatar);
v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE); v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE);
((TextView) v.findViewById(R.id.time)).setText(LinphoneUtils.timestampToHumanDate(getActivity(), participant.getStateChangeTime(), R.string.messages_date_format)); ((TextView) v.findViewById(R.id.time)).setText(LinphoneUtils.timestampToHumanDate(getActivity(), participant.getStateChangeTime(), R.string.messages_date_format));
((TextView) v.findViewById(R.id.name)).setText(participantDisplayName); ((TextView) v.findViewById(R.id.name)).setText(participantDisplayName);
if (participantContact != null && participantContact.hasPhoto()) { if (participantContact != null) {
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri()); ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
} else { } else {
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
} }
mSent.addView(v); mSent.addView(v);
@ -274,12 +281,14 @@ public class ImdnFragment extends Fragment {
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address); String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false); View v = mInflater.inflate(R.layout.chat_imdn_cell, mContainer, false);
ImageView contactPicture = v.findViewById(R.id.contact_picture);
TextView generatedAvatar = v.findViewById(R.id.generated_avatar);
v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE); v.findViewById(R.id.separator).setVisibility(first ? View.GONE : View.VISIBLE);
((TextView) v.findViewById(R.id.name)).setText(participantDisplayName); ((TextView) v.findViewById(R.id.name)).setText(participantDisplayName);
if (participantContact != null && participantContact.hasPhoto()) { if (participantContact != null) {
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri()); ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
} else { } else {
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
} }
mUndelivered.addView(v); mUndelivered.addView(v);

View file

@ -35,6 +35,7 @@ import org.linphone.LinphoneUtils;
import org.linphone.R; import org.linphone.R;
import org.linphone.activities.LinphoneActivity; import org.linphone.activities.LinphoneActivity;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.ui.ContactAvatar;
import org.linphone.ui.SelectableAdapter; import org.linphone.ui.SelectableAdapter;
import org.linphone.ui.SelectableHelper; import org.linphone.ui.SelectableHelper;
@ -52,6 +53,7 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
public LinearLayout separator; public LinearLayout separator;
public TextView separatorText; public TextView separatorText;
public ImageView contactPicture; public ImageView contactPicture;
public TextView generatedAvatar;
public TextView organization; public TextView organization;
//public ImageView friendStatus; //public ImageView friendStatus;
private ClickListener mListener; private ClickListener mListener;
@ -65,6 +67,7 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
separator = view.findViewById(R.id.separator); separator = view.findViewById(R.id.separator);
separatorText = view.findViewById(R.id.separator_text); separatorText = view.findViewById(R.id.separator_text);
contactPicture = view.findViewById(R.id.contact_picture); contactPicture = view.findViewById(R.id.contact_picture);
generatedAvatar = view.findViewById(R.id.generated_avatar);
organization = view.findViewById(R.id.contactOrganization); organization = view.findViewById(R.id.contactOrganization);
//friendStatus = view.findViewById(R.id.friendStatus); //friendStatus = view.findViewById(R.id.friendStatus);
mListener = listener; mListener = listener;
@ -130,10 +133,7 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
holder.separator.setVisibility(mIsSearchMode || (!mIsSearchMode && getPositionForSection(getSectionForPosition(position)) != position) ? View.GONE : View.VISIBLE); holder.separator.setVisibility(mIsSearchMode || (!mIsSearchMode && getPositionForSection(getSectionForPosition(position)) != position) ? View.GONE : View.VISIBLE);
holder.linphoneFriend.setVisibility(contact.isInFriendList() ? View.VISIBLE : View.GONE); holder.linphoneFriend.setVisibility(contact.isInFriendList() ? View.VISIBLE : View.GONE);
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); ContactAvatar.displayAvatar(contact, holder.contactPicture, holder.generatedAvatar);
if (contact.hasPhoto()) {
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
}
boolean isOrgVisible = mContext.getResources().getBoolean(R.bool.display_contact_organization); boolean isOrgVisible = mContext.getResources().getBoolean(R.bool.display_contact_organization);
String org = contact.getOrganization(); String org = contact.getOrganization();

View file

@ -39,6 +39,7 @@ import org.linphone.core.PresenceModel;
import org.linphone.core.ProxyConfig; import org.linphone.core.ProxyConfig;
import org.linphone.core.SearchResult; import org.linphone.core.SearchResult;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.ui.ContactAvatar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -53,6 +54,7 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
public ImageView linphoneContact; public ImageView linphoneContact;
public ImageView isSelect; public ImageView isSelect;
public ImageView avatar; public ImageView avatar;
public TextView generatedAvatar;
private ClickListener mListener; private ClickListener mListener;
@ -63,6 +65,7 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
linphoneContact = view.findViewById(R.id.contact_linphone); linphoneContact = view.findViewById(R.id.contact_linphone);
isSelect = view.findViewById(R.id.contact_is_select); isSelect = view.findViewById(R.id.contact_is_select);
avatar = view.findViewById(R.id.contact_picture); avatar = view.findViewById(R.id.contact_picture);
generatedAvatar = view.findViewById(R.id.generated_avatar);
mListener = listener; mListener = listener;
view.setOnClickListener(this); view.setOnClickListener(this);
} }
@ -120,11 +123,6 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
final String a = (contact.getAddressAsDisplayableString().isEmpty()) ? contact.getPhoneNumber() : contact.getAddressAsDisplayableString(); final String a = (contact.getAddressAsDisplayableString().isEmpty()) ? contact.getPhoneNumber() : contact.getAddressAsDisplayableString();
LinphoneContact c = contact.getContact(); LinphoneContact c = contact.getContact();
holder.avatar.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
if (c != null && c.hasPhoto()) {
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.avatar, c.getThumbnailUri());
}
String address = contact.getAddressAsDisplayableString(); String address = contact.getAddressAsDisplayableString();
if (c != null && c.getFullName() != null) { if (c != null && c.getFullName() != null) {
if (address == null) if (address == null)
@ -146,6 +144,13 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
} else { } else {
holder.name.setVisibility(View.GONE); holder.name.setVisibility(View.GONE);
} }
if (c != null) {
ContactAvatar.displayAvatar(c, holder.avatar, holder.generatedAvatar);
} else {
ContactAvatar.displayAvatar(holder.name.getText().toString(), holder.generatedAvatar);
}
holder.address.setText(a); holder.address.setText(a);
if (holder.linphoneContact != null) { if (holder.linphoneContact != null) {
if (contact.isLinphoneContact() && c != null && c.isInFriendList() && address != null) { if (contact.isLinphoneContact() && c != null && c.isInFriendList() && address != null) {

View file

@ -0,0 +1,76 @@
package org.linphone.ui;
/*
ContactAvatar.java
Copyright (C) 2010-2018 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.linphone.LinphoneService;
import org.linphone.LinphoneUtils;
import org.linphone.contacts.LinphoneContact;
import org.linphone.mediastream.Log;
import java.io.IOException;
public class ContactAvatar {
private static String generateAvatar(String displayName) {
String[] names = displayName.split(" ");
String generatedAvatarText = "";
for (String name : names) {
generatedAvatarText += name.charAt(0);
}
return generatedAvatarText.toUpperCase();
}
public static void displayAvatar(String displayName, TextView generatedAvatarView) {
generatedAvatarView.setText(generateAvatar(displayName));
generatedAvatarView.setVisibility(View.VISIBLE);
}
public static void displayAvatar(LinphoneContact contact, ImageView contactPictureView, TextView generatedAvatarView) {
Bitmap bm = null;
if (contact.getThumbnailUri() != null && contact.getThumbnailUri().getScheme().startsWith("http")) {
bm = LinphoneUtils.downloadBitmap(contact.getThumbnailUri());
} else {
if (contact.getThumbnailUri() != null) {
try {
bm = MediaStore.Images.Media.getBitmap(LinphoneService.instance().getContentResolver(), contact.getThumbnailUri());
} catch (IOException e) {
Log.e(e);
}
}
}
if (bm != null) {
contactPictureView.setImageBitmap(bm);
contactPictureView.setVisibility(View.VISIBLE);
generatedAvatarView.setVisibility(View.GONE);
} else {
generatedAvatarView.setText(generateAvatar(contact.getFullName()));
generatedAvatarView.setVisibility(View.VISIBLE);
}
}
}