Contact deletion ok

This commit is contained in:
Sylvain Berfini 2016-03-18 10:50:28 +01:00 committed by Jehan Monnier
parent 1bbc54da96
commit 1d879f2bf2
3 changed files with 17 additions and 36 deletions

View file

@ -275,8 +275,8 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
private void removeContacts(){ private void removeContacts(){
int size = contactsList.getAdapter().getCount(); int size = contactsList.getAdapter().getCount();
for(int i=0; i<size; i++) { for (int i = size - 1; i >= 0; i--) {
if(contactsList.isItemChecked(i)){ if (contactsList.isItemChecked(i)) {
LinphoneContact contact = (LinphoneContact) contactsList.getAdapter().getItem(i); LinphoneContact contact = (LinphoneContact) contactsList.getAdapter().getItem(i);
contact.delete(); contact.delete();
} }
@ -412,6 +412,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
} }
public Object getItem(int position) { public Object getItem(int position) {
if (position >= getCount()) return null;
return contacts.get(position); return contacts.get(position);
} }

View file

@ -156,35 +156,17 @@ public class ContactsManager extends ContentObserver {
} }
return null; return null;
} }
public synchronized void removeContact(LinphoneContact linphoneContact) {
contacts.remove(linphoneContact);
}
public synchronized void setContacts(List<LinphoneContact> c) { public synchronized void setContacts(List<LinphoneContact> c) {
contacts = c; contacts = c;
} }
public synchronized void fetchContacts() { public synchronized void fetchContacts() {
contacts = new ArrayList<LinphoneContact>(); setContacts(fetchContactsAsync());
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
LinphoneContact contact = new LinphoneContact();
LinphoneAddress addr = friend.getAddress();
contact.setFullName(addr.getDisplayName());
contact.addNumberOrAddress(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
contacts.add(contact);
}
if (mAccount == null || !hasContactAccess) return;
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
if (c != null) {
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
LinphoneContact contact = new LinphoneContact();
contact.setAndroidId(id);
contact.refresh();
contacts.add(contact);
}
c.close();
}
} }
public List<LinphoneContact> fetchContactsAsync() { public List<LinphoneContact> fetchContactsAsync() {

View file

@ -25,7 +25,9 @@ import java.util.List;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneFriend; import org.linphone.core.LinphoneFriend;
import org.linphone.mediastream.Log;
import android.content.ContentProviderOperation;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentUris; import android.content.ContentUris;
import android.database.Cursor; import android.database.Cursor;
@ -123,23 +125,19 @@ public class LinphoneContact implements Serializable {
public void delete() { public void delete() {
if (isAndroidContact()) { if (isAndroidContact()) {
// TODO String select = ContactsContract.Data.CONTACT_ID + " = ?";
/*String select = ContactsContract.Data.CONTACT_ID + " = ?"; String[] args = new String[] { getAndroidId() };
String[] args = new String[] { contact.getID() };
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI) ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
.withSelection(select, args)
.build()
);
ContentResolver cr = ContactsManager.getInstance().getContentResolver();
try { try {
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); cr.applyBatch(ContactsContract.AUTHORITY, ops);
ContactsManager.getInstance().removeAllFriends(contact);
} catch (Exception e) { } catch (Exception e) {
Log.w(e.getMessage() + ":" + e.getStackTrace()); Log.e(e);
} }
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(), contact);*/ ContactsManager.getInstance().removeContact(this);
} }
if (friend != null) { if (friend != null) {
LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend); LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend);