Contact deletion ok
This commit is contained in:
parent
1bbc54da96
commit
1d879f2bf2
3 changed files with 17 additions and 36 deletions
|
@ -275,8 +275,8 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
|
||||
private void removeContacts(){
|
||||
int size = contactsList.getAdapter().getCount();
|
||||
for(int i=0; i<size; i++) {
|
||||
if(contactsList.isItemChecked(i)){
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
if (contactsList.isItemChecked(i)) {
|
||||
LinphoneContact contact = (LinphoneContact) contactsList.getAdapter().getItem(i);
|
||||
contact.delete();
|
||||
}
|
||||
|
@ -412,6 +412,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
if (position >= getCount()) return null;
|
||||
return contacts.get(position);
|
||||
}
|
||||
|
||||
|
|
|
@ -156,35 +156,17 @@ public class ContactsManager extends ContentObserver {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized void removeContact(LinphoneContact linphoneContact) {
|
||||
contacts.remove(linphoneContact);
|
||||
}
|
||||
|
||||
public synchronized void setContacts(List<LinphoneContact> c) {
|
||||
contacts = c;
|
||||
}
|
||||
|
||||
public synchronized void fetchContacts() {
|
||||
contacts = new ArrayList<LinphoneContact>();
|
||||
|
||||
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();
|
||||
}
|
||||
setContacts(fetchContactsAsync());
|
||||
}
|
||||
|
||||
public List<LinphoneContact> fetchContactsAsync() {
|
||||
|
|
|
@ -25,7 +25,9 @@ import java.util.List;
|
|||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.database.Cursor;
|
||||
|
@ -123,23 +125,19 @@ public class LinphoneContact implements Serializable {
|
|||
|
||||
public void delete() {
|
||||
if (isAndroidContact()) {
|
||||
// TODO
|
||||
/*String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
||||
String[] args = new String[] { contact.getID() };
|
||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
||||
String[] args = new String[] { getAndroidId() };
|
||||
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build()
|
||||
);
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
|
||||
|
||||
ContentResolver cr = ContactsManager.getInstance().getContentResolver();
|
||||
try {
|
||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
ContactsManager.getInstance().removeAllFriends(contact);
|
||||
cr.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
} 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) {
|
||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend);
|
||||
|
|
Loading…
Reference in a new issue