From 39380d754ec9f0339779b53986965ae5259379b9 Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Thu, 5 Oct 2017 17:05:43 +0200 Subject: [PATCH] Fixing select and delete from list --- .../org/linphone/ChatCreationFragment.java | 22 +++++++++++++------ .../linphone/SearchContactsListAdapter.java | 13 ++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/android/org/linphone/ChatCreationFragment.java b/src/android/org/linphone/ChatCreationFragment.java index d4bb47672..a2d0a2565 100644 --- a/src/android/org/linphone/ChatCreationFragment.java +++ b/src/android/org/linphone/ChatCreationFragment.java @@ -119,8 +119,8 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen // We need to get all contacts not only sip for (String uri : savedInstanceState.getStringArrayList("contactsSelected")) { for (ContactAddress ca : searchAdapter.getContactsList()) { - if (ca.getAddress() == uri) { - updateContactsClick(ca); + if (ca.getAddress().compareTo(uri) == 0) { + updateContactsClick(ca, searchAdapter.getContactsSelectedList()); break; } } @@ -162,8 +162,16 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen } } - private void updateContactsClick(ContactAddress ca) { - ca.setSelect(!ca.isSelect()); + private int getIndexOfCa(ContactAddress ca, List caList) { + for (int i = 0 ; i < caList.size() ; i++) { + if (caList.get(i).getAddress().compareTo(ca.getAddress()) == 0) + return i; + } + return -1; + } + + private void updateContactsClick(ContactAddress ca, List caSelectedList) { + ca.setSelect((getIndexOfCa(ca, caSelectedList) == -1)); if(ca.isSelect()) { ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance()); csv.setListener(this); @@ -176,7 +184,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen ca.setView(viewContact); contactsSelectedLayout.addView(viewContact); } else { - contactsSelected.remove(ca); + contactsSelected.remove(getIndexOfCa(ca, contactsSelected)); contactsSelectedLayout.removeAllViews(); for (ContactAddress contactAddress : contactsSelected) { if (contactAddress.getView() != null) @@ -191,7 +199,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen for (ContactAddress ca : contactsSelected) { if (ca.getView() == v) { ca.setSelect(false); - updateContactsClick(ca); + updateContactsClick(ca, searchAdapter.getContactsSelectedList()); } } } @@ -245,7 +253,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen public void onItemClick(AdapterView adapterView, View view, int i, long l) { // Get contact ContactAddress ca = searchAdapter.getContacts().get(i); - updateContactsClick(ca); + updateContactsClick(ca, searchAdapter.getContactsSelectedList()); updateList(); updateListSelected(); } diff --git a/src/android/org/linphone/SearchContactsListAdapter.java b/src/android/org/linphone/SearchContactsListAdapter.java index 2612ce471..305d4b72d 100644 --- a/src/android/org/linphone/SearchContactsListAdapter.java +++ b/src/android/org/linphone/SearchContactsListAdapter.java @@ -82,6 +82,13 @@ public class SearchContactsListAdapter extends BaseAdapter { oldSize = 0; } + private boolean contactIsSelected(ContactAddress ca) { + for (ContactAddress c : contactsSelected) { + if (c.getAddress().compareTo(ca.getAddress()) == 0) return true; + } + return false; + } + public void setContactsList(List contactsList) { if (contactsList == null) { contacts = getContactsList(); @@ -100,6 +107,10 @@ public class SearchContactsListAdapter extends BaseAdapter { } } + public List getContactsSelectedList() { + return contactsSelected; + } + public List getContactsList() { List list = new ArrayList(); if(ContactsManager.getInstance().hasContacts()) { @@ -199,7 +210,7 @@ public class SearchContactsListAdapter extends BaseAdapter { } } if (holder.isSelect != null) { - if (contact.isSelect()) { + if (contactIsSelected(contact)) { holder.isSelect.setVisibility(View.VISIBLE); } else { holder.isSelect.setVisibility(View.INVISIBLE);