From b4acb1b7948e1d429d01cfb16e9ed7c46e774017 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 2 Nov 2017 10:52:22 +0100 Subject: [PATCH] UI fixes & improvements --- src/android/org/linphone/LinphoneUtils.java | 19 +++++---- .../org/linphone/chat/ChatEventsAdapter.java | 22 ++-------- .../org/linphone/chat/GroupChatFragment.java | 42 ++++++------------- 3 files changed, 26 insertions(+), 57 deletions(-) diff --git a/src/android/org/linphone/LinphoneUtils.java b/src/android/org/linphone/LinphoneUtils.java index 2a86c83be..e4667eab0 100644 --- a/src/android/org/linphone/LinphoneUtils.java +++ b/src/android/org/linphone/LinphoneUtils.java @@ -136,16 +136,17 @@ public final class LinphoneUtils { return getAddressDisplayName(lAddress); } - public static String getAddressDisplayName(Address address){ - if(address.getDisplayName() != null) { - return address.getDisplayName(); - } else { - if(address.getUsername() != null){ - return address.getUsername(); - } else { - return address.asStringUriOnly(); - } + public static String getAddressDisplayName(Address address) { + if (address == null) return null; + + String displayName = address.getDisplayName(); + if (displayName == null || displayName.isEmpty()) { + displayName = address.getUsername(); } + if (displayName == null || displayName.isEmpty()) { + displayName = address.asStringUriOnly(); + } + return displayName; } public static String getUsernameFromAddress(String address) { diff --git a/src/android/org/linphone/chat/ChatEventsAdapter.java b/src/android/org/linphone/chat/ChatEventsAdapter.java index 3631aade6..9c009190f 100644 --- a/src/android/org/linphone/chat/ChatEventsAdapter.java +++ b/src/android/org/linphone/chat/ChatEventsAdapter.java @@ -157,10 +157,7 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene String displayName; if (message.isOutgoing()) { - displayName = remoteSender.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - displayName = remoteSender.getUsername(); - } + displayName = LinphoneUtils.getAddressDisplayName(remoteSender); if (status == ChatMessage.State.InProgress) { holder.messageSendingInProgress.setVisibility(View.VISIBLE); @@ -207,10 +204,7 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene if (contact.getFullName() != null) { displayName = contact.getFullName(); } else { - displayName = remoteSender.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - displayName = remoteSender.getUsername(); - } + displayName = LinphoneUtils.getAddressDisplayName(remoteSender); } holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); @@ -218,11 +212,7 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, contact.getThumbnailUri()); } } else { - displayName = remoteSender.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - displayName = remoteSender.getUsername(); - } - + displayName = LinphoneUtils.getAddressDisplayName(remoteSender); holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap()); } @@ -312,14 +302,10 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene if (contact != null) { displayName = contact.getFullName(); } else { - displayName = address.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - displayName = address.getUsername(); - } + displayName = LinphoneUtils.getAddressDisplayName(address); } } - //TODO switch (event.getType()) { case ConferenceCreated: holder.eventMessage.setText(mContext.getString(R.string.conference_created)); diff --git a/src/android/org/linphone/chat/GroupChatFragment.java b/src/android/org/linphone/chat/GroupChatFragment.java index b8c80c7e5..3f56ba862 100644 --- a/src/android/org/linphone/chat/GroupChatFragment.java +++ b/src/android/org/linphone/chat/GroupChatFragment.java @@ -146,12 +146,8 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(a); if (c == null) { c = new LinphoneContact(); - String displayName = a.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - c.setFullName(a.getUsername()); - } else { - c.setFullName(displayName); - } + String displayName = LinphoneUtils.getAddressDisplayName(a); + c.setFullName(displayName); } ContactAddress ca = new ContactAddress(c, a.asString(), c.isFriend()); participants.add(ca); @@ -307,7 +303,6 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con } else if (fileToUploadPath.contains("com.android.contacts/contacts/")) { fileToUploadPath = getCVSPathFromLookupUri(fileToUploadPath).toString(); } - Log.e("FILE PATH IS " + fileToUploadPath); addFileToPendingList(fileToUploadPath); } } else { @@ -389,16 +384,13 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con mParticipants.add(c); participantsLabel.append(c.getFullName()); } else { - String displayName = p.getAddress().getDisplayName(); - if (displayName != null && !displayName.isEmpty()) { - participantsLabel.append(displayName); - } else { - participantsLabel.append(p.getAddress().getUsername()); - } + String displayName = LinphoneUtils.getAddressDisplayName(p.getAddress()); + participantsLabel.append(displayName); } index++; - if (index != mChatRoom.getNbParticipants()) participantsLabel.append(";"); + if (index != mChatRoom.getNbParticipants()) participantsLabel.append(", "); } + mParticipantsLabel.setText(participantsLabel.toString()); } else { LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(mRemoteSipAddress); if (c != null) { @@ -441,6 +433,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con mGroupInfosButton.setVisibility(View.VISIBLE); mRoomLabel.setText(mChatRoom.getSubject()); mParticipantsLabel.setVisibility(View.VISIBLE); + } else { mCallButton.setVisibility(View.VISIBLE); mGroupInfosButton.setVisibility(View.GONE); @@ -448,12 +441,8 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con if (mParticipants.size() == 0) { // Contact not found - String displayName = mRemoteSipAddress.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - mRoomLabel.setText(mRemoteSipAddress.getUsername()); - } else { - mRoomLabel.setText(displayName); - } + String displayName = LinphoneUtils.getAddressDisplayName(mRemoteSipAddress); + mRoomLabel.setText(displayName); } else { mRoomLabel.setText(mParticipants.get(0).getFullName()); } @@ -699,12 +688,8 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con } } if (!found) { - String displayName = a.getDisplayName(); - if (displayName != null && !displayName.isEmpty()) { - composing.add(displayName); - } else { - composing.add(a.getUsername()); - } + String displayName = LinphoneUtils.getAddressDisplayName(a); + composing.add(displayName); } } @@ -732,10 +717,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con if (mParticipants.size() > 0) { displayName = mParticipants.get(0).getFullName(); } else { - displayName = remoteAddr.getDisplayName(); - if (displayName == null || displayName.isEmpty()) { - displayName = remoteAddr.getUsername(); - } + displayName = LinphoneUtils.getAddressDisplayName(remoteAddr); } mRemoteComposing.setText(getString(R.string.remote_composing_single).replace("%s", displayName)); mRemoteComposing.setVisibility(View.VISIBLE);