More work on contacts, starting edition/removal
This commit is contained in:
parent
55c1ac4ba0
commit
46319c6e20
3 changed files with 144 additions and 23 deletions
|
@ -87,7 +87,10 @@ class AndroidContact implements Serializable {
|
|||
ContentResolver contentResolver = LinphoneService.instance().getContentResolver();
|
||||
ContentProviderResult[] results =
|
||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, mChangesToCommit);
|
||||
if (results != null && results.length > 0 && results[0] != null) {
|
||||
if (results != null
|
||||
&& results.length > 0
|
||||
&& results[0] != null
|
||||
&& results[0].uri != null) {
|
||||
String rawId = String.valueOf(ContentUris.parseId(results[0].uri));
|
||||
if (mAndroidId == null) {
|
||||
Log.i("[Contact] Contact created with RAW ID " + rawId);
|
||||
|
@ -196,7 +199,29 @@ class AndroidContact implements Serializable {
|
|||
+ ln
|
||||
+ " to existing contact "
|
||||
+ mAndroidId);
|
||||
// TODO
|
||||
String select =
|
||||
ContactsContract.Data.CONTACT_ID
|
||||
+ "=? AND "
|
||||
+ ContactsContract.Data.MIMETYPE
|
||||
+ "=?";
|
||||
String[] args =
|
||||
new String[] {
|
||||
getAndroidId(),
|
||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
|
||||
};
|
||||
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.withValue(
|
||||
ContactsContract.Data.MIMETYPE,
|
||||
ContactsContract.CommonDataKinds.StructuredName
|
||||
.CONTENT_ITEM_TYPE)
|
||||
.withValue(
|
||||
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, fn)
|
||||
.withValue(
|
||||
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, ln)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,31 +281,65 @@ class AndroidContact implements Serializable {
|
|||
+ value
|
||||
+ " to existing contact "
|
||||
+ mAndroidId);
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeNumberOrAddress(String noa) {
|
||||
protected void removeNumberOrAddress(String noa, boolean isSIP) {
|
||||
if (noa == null || noa.isEmpty()) {
|
||||
Log.e("[Contact] Can't remove null or empty number or address.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mAndroidId == null) {
|
||||
Log.i("[Contact] Removing number or address " + noa + " from new contact.");
|
||||
// TODO
|
||||
Log.e("[Contact] Can't remove a number or address from non existing contact");
|
||||
return;
|
||||
} else {
|
||||
Log.i(
|
||||
"[Contact] Removing number or address "
|
||||
+ noa
|
||||
+ " from existing contact "
|
||||
+ mAndroidId);
|
||||
// TODO
|
||||
if (isSIP) {
|
||||
String select =
|
||||
ContactsContract.Data.CONTACT_ID
|
||||
+ "=? AND "
|
||||
+ ContactsContract.Data.MIMETYPE
|
||||
+ "=? AND data1=?";
|
||||
String[] args =
|
||||
new String[] {
|
||||
mAndroidId,
|
||||
ContactsManager.getInstance()
|
||||
.getString(R.string.linphone_address_mime_type),
|
||||
noa
|
||||
};
|
||||
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build());
|
||||
} else {
|
||||
String select =
|
||||
ContactsContract.Data.CONTACT_ID
|
||||
+ "=? AND "
|
||||
+ ContactsContract.Data.MIMETYPE
|
||||
+ "=? AND data1=?";
|
||||
String[] args =
|
||||
new String[] {
|
||||
mAndroidId,
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
|
||||
noa
|
||||
};
|
||||
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setOrganization(String org) {
|
||||
protected void setOrganization(String org, String previousValue) {
|
||||
if (org == null || org.isEmpty()) {
|
||||
if (mAndroidId == null) {
|
||||
Log.e("[Contact] Can't set organization to null or empty for new contact");
|
||||
|
@ -297,8 +356,53 @@ class AndroidContact implements Serializable {
|
|||
.withValue(CommonDataKinds.Organization.COMPANY, org)
|
||||
.build());
|
||||
} else {
|
||||
Log.i("[Contact] Setting organization " + org + " to existing contact " + mAndroidId);
|
||||
// TODO
|
||||
if (previousValue != null) {
|
||||
String select =
|
||||
ContactsContract.Data.CONTACT_ID
|
||||
+ "=? AND "
|
||||
+ ContactsContract.Data.MIMETYPE
|
||||
+ "=? AND "
|
||||
+ ContactsContract.CommonDataKinds.Organization.COMPANY
|
||||
+ "=?";
|
||||
String[] args =
|
||||
new String[] {
|
||||
getAndroidId(),
|
||||
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE,
|
||||
previousValue
|
||||
};
|
||||
|
||||
Log.i(
|
||||
"[Contact] Updating organization "
|
||||
+ org
|
||||
+ " to existing contact "
|
||||
+ mAndroidId);
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.withValue(
|
||||
ContactsContract.Data.MIMETYPE,
|
||||
ContactsContract.CommonDataKinds.Organization
|
||||
.CONTENT_ITEM_TYPE)
|
||||
.withValue(
|
||||
ContactsContract.CommonDataKinds.Organization.COMPANY, org)
|
||||
.build());
|
||||
} else {
|
||||
Log.i(
|
||||
"[Contact] Setting organization "
|
||||
+ org
|
||||
+ " to existing contact "
|
||||
+ mAndroidId);
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, mAndroidRawId)
|
||||
.withValue(
|
||||
ContactsContract.Data.MIMETYPE,
|
||||
ContactsContract.CommonDataKinds.Organization
|
||||
.CONTENT_ITEM_TYPE)
|
||||
.withValue(
|
||||
ContactsContract.CommonDataKinds.Organization.COMPANY, org)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,7 +427,11 @@ class AndroidContact implements Serializable {
|
|||
.getContext()
|
||||
.getResources()
|
||||
.getBoolean(R.bool.use_linphone_tag)) {
|
||||
// TODO
|
||||
String linphoneRawId = findLinphoneRawContactId();
|
||||
if (linphoneRawId != null) {
|
||||
mAndroidRawId = linphoneRawId;
|
||||
isAndroidRawIdLinphone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -163,14 +163,27 @@ public class ContactEditorFragment extends Fragment {
|
|||
}
|
||||
|
||||
for (LinphoneNumberOrAddress noa : mNumbersAndAddresses) {
|
||||
if (noa.isSIPAddress() && noa.getValue() != null) {
|
||||
noa.setValue(
|
||||
LinphoneUtils.getFullAddressFromUsername(noa.getValue()));
|
||||
if (noa.getValue() == null || noa.getValue().isEmpty()) {
|
||||
if (noa.getOldValue() != null && !noa.getOldValue().isEmpty()) {
|
||||
mContact.removeNumberOrAddress(noa);
|
||||
}
|
||||
} else {
|
||||
if (noa.getOldValue() != null
|
||||
&& !noa.getOldValue().isEmpty()
|
||||
&& noa.getOldValue().equals(noa.getValue())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (noa.isSIPAddress()) {
|
||||
noa.setValue(
|
||||
LinphoneUtils.getFullAddressFromUsername(
|
||||
noa.getValue()));
|
||||
}
|
||||
mContact.addOrUpdateNumberOrAddress(noa);
|
||||
}
|
||||
mContact.addOrUpdateNumberOrAddress(noa);
|
||||
}
|
||||
|
||||
if (mIsNewContact && !mOrganization.getText().toString().isEmpty()) {
|
||||
if (!mOrganization.getText().toString().isEmpty() || !mIsNewContact) {
|
||||
mContact.setOrganization(mOrganization.getText().toString(), true);
|
||||
}
|
||||
|
||||
|
@ -559,7 +572,7 @@ public class ContactEditorFragment extends Fragment {
|
|||
if (mIsNewContact || mNewSipOrNumberToAdd != null) {
|
||||
tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP);
|
||||
} else {
|
||||
tempNounoa = new LinphoneNumberOrAddress(null, isSIP, numberOrAddress);
|
||||
tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP, numberOrAddress);
|
||||
}
|
||||
final LinphoneNumberOrAddress nounoa = tempNounoa;
|
||||
mNumbersAndAddresses.add(nounoa);
|
||||
|
|
|
@ -119,6 +119,10 @@ public class LinphoneContact extends AndroidContact
|
|||
if (fn != null && fn.length() == 0 && ln != null && ln.length() == 0) return;
|
||||
if (fn != null && fn.equals(mFirstName) && ln != null && ln.equals(mLastName)) return;
|
||||
|
||||
if (commitChanges) {
|
||||
setName(fn, ln);
|
||||
}
|
||||
|
||||
mFirstName = fn;
|
||||
mLastName = ln;
|
||||
if (mFullName == null) {
|
||||
|
@ -133,10 +137,6 @@ public class LinphoneContact extends AndroidContact
|
|||
mFullName = mLastName;
|
||||
}
|
||||
}
|
||||
|
||||
if (commitChanges) {
|
||||
setName(mFirstName, mLastName);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
|
@ -159,7 +159,7 @@ public class LinphoneContact extends AndroidContact
|
|||
if (org != null && org.equals(mOrganization)) return;
|
||||
|
||||
if (commitChanges) {
|
||||
setOrganization(org);
|
||||
setOrganization(org, mOrganization);
|
||||
}
|
||||
|
||||
mOrganization = org;
|
||||
|
@ -241,7 +241,7 @@ public class LinphoneContact extends AndroidContact
|
|||
public void removeNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||
if (noa != null && noa.getOldValue() != null) {
|
||||
|
||||
removeNumberOrAddress(noa.getOldValue());
|
||||
removeNumberOrAddress(noa.getOldValue(), noa.isSIPAddress());
|
||||
|
||||
if (isFriend()) {
|
||||
if (noa.isSIPAddress()) {
|
||||
|
|
Loading…
Reference in a new issue