Display contact's initials as avatar if available
This commit is contained in:
parent
b6e4dc4740
commit
54933523c3
18 changed files with 193 additions and 214 deletions
5
res/drawable/generated_avatar_bg.xml
Normal file
5
res/drawable/generated_avatar_bg.xml
Normal 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>
|
|
@ -31,29 +31,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<RelativeLayout
|
||||
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>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -31,28 +31,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<RelativeLayout
|
||||
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>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
|
|
|
@ -31,28 +31,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<RelativeLayout
|
||||
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>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
|
|
|
@ -32,24 +32,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<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"
|
||||
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"/>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -19,24 +19,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<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"
|
||||
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"/>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -32,28 +32,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<RelativeLayout
|
||||
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>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
|
|
33
res/layout/contact_avatar.xml
Normal file
33
res/layout/contact_avatar.xml
Normal 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>
|
|
@ -39,24 +39,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<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"
|
||||
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"/>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -70,24 +70,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<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"
|
||||
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"/>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -13,24 +13,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<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"
|
||||
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"/>
|
||||
<include layout="@layout/contact_avatar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.linphone.contacts.LinphoneContact;
|
|||
import org.linphone.core.Address;
|
||||
import org.linphone.core.Call;
|
||||
import org.linphone.core.CallLog;
|
||||
import org.linphone.ui.ContactAvatar;
|
||||
import org.linphone.ui.SelectableAdapter;
|
||||
import org.linphone.ui.SelectableHelper;
|
||||
|
||||
|
@ -55,6 +56,7 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
public CheckBox select;
|
||||
public ImageView callDirection;
|
||||
public ImageView contactPicture;
|
||||
public TextView generatedAvatar;
|
||||
public RelativeLayout CallContact;
|
||||
public LinearLayout separator;
|
||||
public TextView separatorText;
|
||||
|
@ -67,6 +69,7 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
select = view.findViewById(R.id.delete);
|
||||
callDirection = view.findViewById(R.id.icon);
|
||||
contactPicture = view.findViewById(R.id.contact_picture);
|
||||
generatedAvatar = view.findViewById(R.id.generated_avatar);
|
||||
CallContact = view.findViewById(R.id.history_click);
|
||||
separator = view.findViewById(R.id.separator);
|
||||
separatorText = view.findViewById(R.id.separator_text);
|
||||
|
@ -167,19 +170,22 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address);
|
||||
String displayName = null;
|
||||
final String sipUri = (address != null) ? address.asString() : "";
|
||||
|
||||
if (c != null) {
|
||||
displayName = c.getFullName();
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, c.getThumbnailUri());
|
||||
} else {
|
||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
}
|
||||
|
||||
if (displayName == null) {
|
||||
holder.contact.setText(LinphoneUtils.getAddressDisplayName(sipUri));
|
||||
} else {
|
||||
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.setOnClickListener(!isEditionEnabled() ?
|
||||
new View.OnClickListener() {
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.linphone.core.ChatMessage;
|
|||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.ChatRoomCapabilities;
|
||||
import org.linphone.core.Content;
|
||||
import org.linphone.ui.ContactAvatar;
|
||||
|
||||
public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
private Bitmap mDefaultBitmap;
|
||||
|
@ -51,6 +52,7 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.
|
|||
public TextView unreadMessages;
|
||||
public CheckBox delete;
|
||||
public ImageView contactPicture;
|
||||
public TextView generatedAvatar;
|
||||
public ImageView lastMessageFileTransfer;
|
||||
public Context mContext;
|
||||
public ChatRoom mRoom;
|
||||
|
@ -70,6 +72,7 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.
|
|||
unreadMessages = itemView.findViewById(R.id.unreadMessages);
|
||||
delete = itemView.findViewById(R.id.delete_chatroom);
|
||||
contactPicture = itemView.findViewById(R.id.contact_picture);
|
||||
generatedAvatar = itemView.findViewById(R.id.generated_avatar);
|
||||
lastMessageFileTransfer = itemView.findViewById(R.id.lastMessageFileTransfer);
|
||||
mListener = listener;
|
||||
|
||||
|
@ -153,14 +156,20 @@ public class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.
|
|||
}
|
||||
|
||||
public void getAvatar(ChatRoom mRoom) {
|
||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress());
|
||||
if (contact != null) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), contactPicture, ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress()).getThumbnailUri());
|
||||
if (mRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mRoom.getPeerAddress());
|
||||
if (contact != null) {
|
||||
ContactAvatar.displayAvatar(contact, contactPicture, generatedAvatar);
|
||||
} else {
|
||||
String username = mRoom.getPeerAddress().getDisplayName();
|
||||
if (username == null) {
|
||||
username = mRoom.getPeerAddress().getUsername();
|
||||
}
|
||||
ContactAvatar.displayAvatar(username, generatedAvatar);
|
||||
}
|
||||
} else {
|
||||
if (mRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()))
|
||||
contactPicture.setImageBitmap(mDefaultBitmap);
|
||||
else
|
||||
contactPicture.setImageBitmap(mDefaultGroupBitmap);
|
||||
contactPicture.setImageBitmap(mDefaultGroupBitmap);
|
||||
generatedAvatar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.linphone.contacts.ContactAddress;
|
|||
import org.linphone.contacts.LinphoneContact;
|
||||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.Participant;
|
||||
import org.linphone.ui.ContactAvatar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -44,6 +45,7 @@ public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.View
|
|||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView name;
|
||||
public ImageView avatar;
|
||||
public TextView generatedAvatar;
|
||||
public ImageView delete;
|
||||
public LinearLayout isAdmin;
|
||||
public LinearLayout isNotAdmin;
|
||||
|
@ -52,6 +54,7 @@ public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.View
|
|||
super(view);
|
||||
name = view.findViewById(R.id.name);
|
||||
avatar = view.findViewById(R.id.contact_picture);
|
||||
generatedAvatar = view.findViewById(R.id.generated_avatar);
|
||||
delete = view.findViewById(R.id.delete);
|
||||
isAdmin = view.findViewById(R.id.isAdminLayout);
|
||||
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) {
|
||||
final ContactAddress ca = (ContactAddress) getItem(position);
|
||||
LinphoneContact c = ca.getContact();
|
||||
ImageView avatar = holder.avatar;
|
||||
|
||||
holder.name.setText((c.getFullName() != null) ? c.getFullName() :
|
||||
(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() {
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.linphone.core.ChatMessageListenerStub;
|
|||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.core.ParticipantImdnState;
|
||||
import org.linphone.ui.ContactAvatar;
|
||||
|
||||
public class ImdnFragment extends Fragment {
|
||||
private LayoutInflater mInflater;
|
||||
|
@ -205,13 +206,15 @@ public class ImdnFragment extends Fragment {
|
|||
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
|
||||
|
||||
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);
|
||||
((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);
|
||||
if (participantContact != null && participantContact.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri());
|
||||
if (participantContact != null) {
|
||||
ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
|
||||
} else {
|
||||
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
|
||||
}
|
||||
|
||||
mRead.addView(v);
|
||||
|
@ -228,13 +231,15 @@ public class ImdnFragment extends Fragment {
|
|||
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
|
||||
|
||||
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);
|
||||
((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);
|
||||
if (participantContact != null && participantContact.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri());
|
||||
if (participantContact != null) {
|
||||
ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
|
||||
} else {
|
||||
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
|
||||
}
|
||||
|
||||
mDelivered.addView(v);
|
||||
|
@ -251,13 +256,15 @@ public class ImdnFragment extends Fragment {
|
|||
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
|
||||
|
||||
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);
|
||||
((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);
|
||||
if (participantContact != null && participantContact.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri());
|
||||
if (participantContact != null) {
|
||||
ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
|
||||
} else {
|
||||
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
|
||||
}
|
||||
|
||||
mSent.addView(v);
|
||||
|
@ -274,12 +281,14 @@ public class ImdnFragment extends Fragment {
|
|||
String participantDisplayName = participantContact != null ? participantContact.getFullName() : LinphoneUtils.getAddressDisplayName(address);
|
||||
|
||||
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);
|
||||
((TextView) v.findViewById(R.id.name)).setText(participantDisplayName);
|
||||
if (participantContact != null && participantContact.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(getActivity(), ((ImageView) v.findViewById(R.id.contact_picture)), participantContact.getThumbnailUri());
|
||||
if (participantContact != null) {
|
||||
ContactAvatar.displayAvatar(participantContact, contactPicture, generatedAvatar);
|
||||
} else {
|
||||
((ImageView) v.findViewById(R.id.contact_picture)).setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
ContactAvatar.displayAvatar(participantDisplayName, generatedAvatar);
|
||||
}
|
||||
|
||||
mUndelivered.addView(v);
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.linphone.LinphoneUtils;
|
|||
import org.linphone.R;
|
||||
import org.linphone.activities.LinphoneActivity;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.ContactAvatar;
|
||||
import org.linphone.ui.SelectableAdapter;
|
||||
import org.linphone.ui.SelectableHelper;
|
||||
|
||||
|
@ -52,6 +53,7 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
public LinearLayout separator;
|
||||
public TextView separatorText;
|
||||
public ImageView contactPicture;
|
||||
public TextView generatedAvatar;
|
||||
public TextView organization;
|
||||
//public ImageView friendStatus;
|
||||
private ClickListener mListener;
|
||||
|
@ -65,6 +67,7 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
separator = view.findViewById(R.id.separator);
|
||||
separatorText = view.findViewById(R.id.separator_text);
|
||||
contactPicture = view.findViewById(R.id.contact_picture);
|
||||
generatedAvatar = view.findViewById(R.id.generated_avatar);
|
||||
organization = view.findViewById(R.id.contactOrganization);
|
||||
//friendStatus = view.findViewById(R.id.friendStatus);
|
||||
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.linphoneFriend.setVisibility(contact.isInFriendList() ? View.VISIBLE : View.GONE);
|
||||
|
||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
if (contact.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri());
|
||||
}
|
||||
ContactAvatar.displayAvatar(contact, holder.contactPicture, holder.generatedAvatar);
|
||||
|
||||
boolean isOrgVisible = mContext.getResources().getBoolean(R.bool.display_contact_organization);
|
||||
String org = contact.getOrganization();
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.linphone.core.PresenceModel;
|
|||
import org.linphone.core.ProxyConfig;
|
||||
import org.linphone.core.SearchResult;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.ContactAvatar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -53,6 +54,7 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
|
|||
public ImageView linphoneContact;
|
||||
public ImageView isSelect;
|
||||
public ImageView avatar;
|
||||
public TextView generatedAvatar;
|
||||
|
||||
private ClickListener mListener;
|
||||
|
||||
|
@ -63,6 +65,7 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
|
|||
linphoneContact = view.findViewById(R.id.contact_linphone);
|
||||
isSelect = view.findViewById(R.id.contact_is_select);
|
||||
avatar = view.findViewById(R.id.contact_picture);
|
||||
generatedAvatar = view.findViewById(R.id.generated_avatar);
|
||||
mListener = listener;
|
||||
view.setOnClickListener(this);
|
||||
}
|
||||
|
@ -120,11 +123,6 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
|
|||
final String a = (contact.getAddressAsDisplayableString().isEmpty()) ? contact.getPhoneNumber() : contact.getAddressAsDisplayableString();
|
||||
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();
|
||||
if (c != null && c.getFullName() != null) {
|
||||
if (address == null)
|
||||
|
@ -146,6 +144,13 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
|
|||
} else {
|
||||
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);
|
||||
if (holder.linphoneContact != null) {
|
||||
if (contact.isLinphoneContact() && c != null && c.isInFriendList() && address != null) {
|
||||
|
|
76
src/android/org/linphone/ui/ContactAvatar.java
Normal file
76
src/android/org/linphone/ui/ContactAvatar.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue