Fixing select and delete from list

This commit is contained in:
Erwan Croze 2017-10-05 17:05:43 +02:00
parent d05d107c23
commit 39380d754e
2 changed files with 27 additions and 8 deletions

View file

@ -119,8 +119,8 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
// We need to get all contacts not only sip // We need to get all contacts not only sip
for (String uri : savedInstanceState.getStringArrayList("contactsSelected")) { for (String uri : savedInstanceState.getStringArrayList("contactsSelected")) {
for (ContactAddress ca : searchAdapter.getContactsList()) { for (ContactAddress ca : searchAdapter.getContactsList()) {
if (ca.getAddress() == uri) { if (ca.getAddress().compareTo(uri) == 0) {
updateContactsClick(ca); updateContactsClick(ca, searchAdapter.getContactsSelectedList());
break; break;
} }
} }
@ -162,8 +162,16 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
} }
} }
private void updateContactsClick(ContactAddress ca) { private int getIndexOfCa(ContactAddress ca, List<ContactAddress> caList) {
ca.setSelect(!ca.isSelect()); 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<ContactAddress> caSelectedList) {
ca.setSelect((getIndexOfCa(ca, caSelectedList) == -1));
if(ca.isSelect()) { if(ca.isSelect()) {
ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance()); ContactSelectView csv = new ContactSelectView(LinphoneActivity.instance());
csv.setListener(this); csv.setListener(this);
@ -176,7 +184,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
ca.setView(viewContact); ca.setView(viewContact);
contactsSelectedLayout.addView(viewContact); contactsSelectedLayout.addView(viewContact);
} else { } else {
contactsSelected.remove(ca); contactsSelected.remove(getIndexOfCa(ca, contactsSelected));
contactsSelectedLayout.removeAllViews(); contactsSelectedLayout.removeAllViews();
for (ContactAddress contactAddress : contactsSelected) { for (ContactAddress contactAddress : contactsSelected) {
if (contactAddress.getView() != null) if (contactAddress.getView() != null)
@ -191,7 +199,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
for (ContactAddress ca : contactsSelected) { for (ContactAddress ca : contactsSelected) {
if (ca.getView() == v) { if (ca.getView() == v) {
ca.setSelect(false); 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) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// Get contact // Get contact
ContactAddress ca = searchAdapter.getContacts().get(i); ContactAddress ca = searchAdapter.getContacts().get(i);
updateContactsClick(ca); updateContactsClick(ca, searchAdapter.getContactsSelectedList());
updateList(); updateList();
updateListSelected(); updateListSelected();
} }

View file

@ -82,6 +82,13 @@ public class SearchContactsListAdapter extends BaseAdapter {
oldSize = 0; 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<ContactAddress> contactsList) { public void setContactsList(List<ContactAddress> contactsList) {
if (contactsList == null) { if (contactsList == null) {
contacts = getContactsList(); contacts = getContactsList();
@ -100,6 +107,10 @@ public class SearchContactsListAdapter extends BaseAdapter {
} }
} }
public List<ContactAddress> getContactsSelectedList() {
return contactsSelected;
}
public List<ContactAddress> getContactsList() { public List<ContactAddress> getContactsList() {
List<ContactAddress> list = new ArrayList<ContactAddress>(); List<ContactAddress> list = new ArrayList<ContactAddress>();
if(ContactsManager.getInstance().hasContacts()) { if(ContactsManager.getInstance().hasContacts()) {
@ -199,7 +210,7 @@ public class SearchContactsListAdapter extends BaseAdapter {
} }
} }
if (holder.isSelect != null) { if (holder.isSelect != null) {
if (contact.isSelect()) { if (contactIsSelected(contact)) {
holder.isSelect.setVisibility(View.VISIBLE); holder.isSelect.setVisibility(View.VISIBLE);
} else { } else {
holder.isSelect.setVisibility(View.INVISIBLE); holder.isSelect.setVisibility(View.INVISIBLE);