From f020b2e2c44919691f8370c83795033823dc8c52 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 3 Sep 2018 12:03:47 +0200 Subject: [PATCH] Hidden room unread count if 0 + fixed group chat icon + some cleanup --- .../linphone/chat/ChatBubbleViewHolder.java | 90 +++++++++---------- .../org/linphone/chat/ChatEventsAdapter.java | 10 +-- .../org/linphone/chat/ChatListFragment.java | 2 +- .../org/linphone/chat/ChatRoomsAdapter.java | 88 +++++++++--------- .../org/linphone/chat/GroupChatFragment.java | 6 +- .../org/linphone/chat/GroupInfoAdapter.java | 6 +- .../org/linphone/chat/GroupInfoFragment.java | 2 +- .../org/linphone/contacts/ContactAddress.java | 8 +- .../contacts/ContactsListAdapter.java | 14 +-- .../contacts/SearchContactsListAdapter.java | 20 ++--- 10 files changed, 121 insertions(+), 125 deletions(-) diff --git a/src/android/org/linphone/chat/ChatBubbleViewHolder.java b/src/android/org/linphone/chat/ChatBubbleViewHolder.java index cf5220753..c23cb7cf7 100644 --- a/src/android/org/linphone/chat/ChatBubbleViewHolder.java +++ b/src/android/org/linphone/chat/ChatBubbleViewHolder.java @@ -68,75 +68,75 @@ public class ChatBubbleViewHolder extends RecyclerView.ViewHolder implements Vie public ChatBubbleViewHolder(Context context, View view, ClickListener listener) { super(view); - this.mContext = context; + mContext = context; - this.eventLayout = view.findViewById(R.id.event); + eventLayout = view.findViewById(R.id.event); //eventTime = view.findViewById(R.id.event_date); - this.eventMessage = view.findViewById(R.id.event_text); + eventMessage = view.findViewById(R.id.event_text); - this.bubbleLayout = view.findViewById(R.id.bubble); - this.background = view.findViewById(R.id.background); - this.contactPicture = view.findViewById(R.id.contact_picture); - this.contactPictureMask = view.findViewById(R.id.mask); - this.contactName = view.findViewById(R.id.contact_header); + bubbleLayout = view.findViewById(R.id.bubble); + background = view.findViewById(R.id.background); + contactPicture = view.findViewById(R.id.contact_picture); + contactPictureMask = view.findViewById(R.id.mask); + contactName = view.findViewById(R.id.contact_header); - this.messageStatus = view.findViewById(R.id.status); - this.messageSendingInProgress = view.findViewById(R.id.inprogress); - this.imdmLayout = view.findViewById(R.id.imdmLayout); - this.imdmIcon = view.findViewById(R.id.imdmIcon); - this.imdmLabel = view.findViewById(R.id.imdmText); + messageStatus = view.findViewById(R.id.status); + messageSendingInProgress = view.findViewById(R.id.inprogress); + imdmLayout = view.findViewById(R.id.imdmLayout); + imdmIcon = view.findViewById(R.id.imdmIcon); + imdmLabel = view.findViewById(R.id.imdmText); - this.messageText = view.findViewById(R.id.message); - this.messageImage = view.findViewById(R.id.image); - this.separatorLayout = view.findViewById(R.id.separator); + messageText = view.findViewById(R.id.message); + messageImage = view.findViewById(R.id.image); + separatorLayout = view.findViewById(R.id.separator); - this.fileTransferLayout = view.findViewById(R.id.file_transfer_layout); - this.fileTransferProgressBar = view.findViewById(R.id.progress_bar); - this.fileTransferAction = view.findViewById(R.id.file_transfer_action); + fileTransferLayout = view.findViewById(R.id.file_transfer_layout); + fileTransferProgressBar = view.findViewById(R.id.progress_bar); + fileTransferAction = view.findViewById(R.id.file_transfer_action); - this.fileName = view.findViewById(R.id.file_name); - this.openFileButton = view.findViewById(R.id.open_file); + fileName = view.findViewById(R.id.file_name); + openFileButton = view.findViewById(R.id.open_file); - this.delete = view.findViewById(R.id.delete_message); + delete = view.findViewById(R.id.delete_message); - this.listener = listener; + listener = listener; view.setOnClickListener(this); } public ChatBubbleViewHolder(View view) { super(view); - this.eventLayout = view.findViewById(R.id.event); + eventLayout = view.findViewById(R.id.event); //eventTime = view.findViewById(R.id.event_date); - this.eventMessage = view.findViewById(R.id.event_text); + eventMessage = view.findViewById(R.id.event_text); - this.bubbleLayout = view.findViewById(R.id.bubble); - this.background = view.findViewById(R.id.background); - this.contactPicture = view.findViewById(R.id.contact_picture); - this.contactPictureMask = view.findViewById(R.id.mask); - this.contactName = view.findViewById(R.id.contact_header); + bubbleLayout = view.findViewById(R.id.bubble); + background = view.findViewById(R.id.background); + contactPicture = view.findViewById(R.id.contact_picture); + contactPictureMask = view.findViewById(R.id.mask); + contactName = view.findViewById(R.id.contact_header); - this.messageStatus = view.findViewById(R.id.status); - this.messageSendingInProgress = view.findViewById(R.id.inprogress); - this.imdmLayout = view.findViewById(R.id.imdmLayout); - this.imdmIcon = view.findViewById(R.id.imdmIcon); - this.imdmLabel = view.findViewById(R.id.imdmText); + messageStatus = view.findViewById(R.id.status); + messageSendingInProgress = view.findViewById(R.id.inprogress); + imdmLayout = view.findViewById(R.id.imdmLayout); + imdmIcon = view.findViewById(R.id.imdmIcon); + imdmLabel = view.findViewById(R.id.imdmText); - this.messageText = view.findViewById(R.id.message); - this.messageImage = view.findViewById(R.id.image); - this.separatorLayout = view.findViewById(R.id.separator); + messageText = view.findViewById(R.id.message); + messageImage = view.findViewById(R.id.image); + separatorLayout = view.findViewById(R.id.separator); - this.fileTransferLayout = view.findViewById(R.id.file_transfer_layout); - this.fileTransferProgressBar = view.findViewById(R.id.progress_bar); - this.fileTransferAction = view.findViewById(R.id.file_transfer_action); + fileTransferLayout = view.findViewById(R.id.file_transfer_layout); + fileTransferProgressBar = view.findViewById(R.id.progress_bar); + fileTransferAction = view.findViewById(R.id.file_transfer_action); - this.fileName = view.findViewById(R.id.file_name); - this.openFileButton = view.findViewById(R.id.open_file); + fileName = view.findViewById(R.id.file_name); + openFileButton = view.findViewById(R.id.open_file); - this.delete = view.findViewById(R.id.delete_message); + delete = view.findViewById(R.id.delete_message); } @Override public void onClick(View v) { - if(listener!=null) { + if (listener != null) { listener.onItemClicked(getAdapterPosition()); } } diff --git a/src/android/org/linphone/chat/ChatEventsAdapter.java b/src/android/org/linphone/chat/ChatEventsAdapter.java index 9fb0958ad..f0840fdb1 100644 --- a/src/android/org/linphone/chat/ChatEventsAdapter.java +++ b/src/android/org/linphone/chat/ChatEventsAdapter.java @@ -130,8 +130,8 @@ public class ChatEventsAdapter extends SelectableAdapter { @Override public ChatBubbleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()) - .inflate(this.mItemResource, parent, false); - ChatBubbleViewHolder VH = new ChatBubbleViewHolder(this.mContext,v, mClickListener); + .inflate(mItemResource, parent, false); + ChatBubbleViewHolder VH = new ChatBubbleViewHolder(mContext,v, mClickListener); //Allows onLongClick ContextMenu on bubbles mFragment.registerForContextMenu(v); @@ -141,7 +141,7 @@ public class ChatEventsAdapter extends SelectableAdapter { @Override public void onBindViewHolder(@NonNull ChatBubbleViewHolder holder, int position) { - final EventLog event = this.mHistory.get(position); + final EventLog event = mHistory.get(position); holder.eventLayout.setVisibility(View.GONE); holder.bubbleLayout.setVisibility(View.GONE); holder.delete.setVisibility(isEditionEnabled() ? View.VISIBLE : View.GONE); @@ -402,7 +402,7 @@ public class ChatEventsAdapter extends SelectableAdapter { @Override public int getItemCount() { - return this.mHistory.size(); + return mHistory.size(); } public void addToHistory(EventLog log) { @@ -430,7 +430,7 @@ public class ChatEventsAdapter extends SelectableAdapter { } public int getCount() { - return this.mHistory.size(); + return mHistory.size(); } public Object getItem(int i) { diff --git a/src/android/org/linphone/chat/ChatListFragment.java b/src/android/org/linphone/chat/ChatListFragment.java index 9d6f7e30b..988b74b7c 100644 --- a/src/android/org/linphone/chat/ChatListFragment.java +++ b/src/android/org/linphone/chat/ChatListFragment.java @@ -71,7 +71,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene super.onCreate(savedInstanceState); mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms())); - this.mContext = getActivity().getApplicationContext(); + mContext = getActivity().getApplicationContext(); View view = inflater.inflate(R.layout.chatlist, container, false); mChatRoomsList = view.findViewById(R.id.chatList); diff --git a/src/android/org/linphone/chat/ChatRoomsAdapter.java b/src/android/org/linphone/chat/ChatRoomsAdapter.java index 6f6a05538..674a8c99e 100644 --- a/src/android/org/linphone/chat/ChatRoomsAdapter.java +++ b/src/android/org/linphone/chat/ChatRoomsAdapter.java @@ -21,6 +21,7 @@ package org.linphone.chat; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -38,7 +39,6 @@ import org.linphone.contacts.LinphoneContact; import org.linphone.core.Address; import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoomCapabilities; -import org.linphone.core.ChatRoomListenerStub; import org.linphone.ui.SelectableAdapter; import org.linphone.ui.SelectableHelper; @@ -60,43 +60,43 @@ public class ChatRoomsAdapter extends SelectableAdapter mRooms; private static Bitmap mDefaultBitmap; - //private Bitmap mDefaultGroupBitmap; - private ChatRoomListenerStub mListener; - private int itemResource; - private ChatRoomViewHolder.ClickListener clickListener; + private static Bitmap mDefaultGroupBitmap; + private int mItemResource; + private ChatRoomViewHolder.ClickListener mClickListener; - public ChatRoomsAdapter(Context context, int itemResource, List mRooms, ChatRoomViewHolder.ClickListener clickListener, SelectableHelper helper) { + public ChatRoomsAdapter(Context context, int itemResource, List rooms, ChatRoomViewHolder.ClickListener clickListener, SelectableHelper helper) { super(helper); - this.clickListener = clickListener; - this.mRooms = mRooms; - this.mContext = context; - this.itemResource = itemResource; + mClickListener = clickListener; + mRooms = rooms; + mContext = context; + mItemResource = itemResource; mDefaultBitmap = ContactsManager.getInstance().getDefaultAvatarBitmap(); - //mDefaultGroupBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chat_group_avatar); + mDefaultGroupBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chat_group_avatar); } @Override public ChatRoomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) - .inflate(this.itemResource, parent, false); - return new ChatRoomViewHolder(this.mContext, view, clickListener); + .inflate(mItemResource, parent, false); + return new ChatRoomViewHolder(mContext, view, mClickListener); } @Override public void onBindViewHolder(ChatRoomViewHolder holder, int position) { - ChatRoom room = this.mRooms.get(position); - holder.delete.setVisibility(this.isEditionEnabled() == true ? View.VISIBLE : View.INVISIBLE); - holder.unreadMessages.setVisibility(this.isEditionEnabled() == false ? View.VISIBLE : View.INVISIBLE); - holder.delete.setChecked(isSelected(position) ? true : false); + ChatRoom room = mRooms.get(position); + holder.delete.setVisibility(isEditionEnabled() ? View.VISIBLE : View.INVISIBLE); + holder.unreadMessages.setVisibility(isEditionEnabled() ? View.INVISIBLE : (room.getUnreadMessagesCount() > 0 ? View.VISIBLE : View.INVISIBLE)); + holder.delete.setChecked(isSelected(position)); holder.bindChatRoom(room); } @@ -201,9 +202,6 @@ public class ChatRoomsAdapter extends SelectableAdapter items, boolean hideAdminFeatures, boolean isCreation) { mItems = items; @@ -84,11 +84,11 @@ public class GroupInfoAdapter extends RecyclerView.Adapter) getArguments().getSerializable("ContactAddress"); diff --git a/src/android/org/linphone/contacts/ContactAddress.java b/src/android/org/linphone/contacts/ContactAddress.java index 812cd2536..f6c54154b 100644 --- a/src/android/org/linphone/contacts/ContactAddress.java +++ b/src/android/org/linphone/contacts/ContactAddress.java @@ -118,10 +118,10 @@ public class ContactAddress implements Serializable { } private void init(LinphoneContact c, String a, String pn, boolean isLC) { - this.contact = c; - this.address = a; - this.phoneNumber = pn; - this.isLinphoneContact = isLC; + contact = c; + address = a; + phoneNumber = pn; + isLinphoneContact = isLC; } public ContactAddress(LinphoneContact c, String a, String pn, boolean isLC) { diff --git a/src/android/org/linphone/contacts/ContactsListAdapter.java b/src/android/org/linphone/contacts/ContactsListAdapter.java index b82ffc484..aacf71d7a 100644 --- a/src/android/org/linphone/contacts/ContactsListAdapter.java +++ b/src/android/org/linphone/contacts/ContactsListAdapter.java @@ -55,7 +55,7 @@ public class ContactsListAdapter extends SelectableAdapter contacts; private List contactsSelected; private ProgressBar progressBar; private boolean mOnlySipContact = false; - private ViewHolder.ClickListener listener; + private ViewHolder.ClickListener mListener; public List getContacts() { return contacts; @@ -92,11 +91,11 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter contactsList, ProgressBar pB, ViewHolder.ClickListener clickListener) { - this.listener=clickListener; + mListener = clickListener; progressBar = pB; setContactsSelectedList(null); setContactsList(contactsList); @@ -106,8 +105,7 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter