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();
|
ContentResolver contentResolver = LinphoneService.instance().getContentResolver();
|
||||||
ContentProviderResult[] results =
|
ContentProviderResult[] results =
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, mChangesToCommit);
|
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));
|
String rawId = String.valueOf(ContentUris.parseId(results[0].uri));
|
||||||
if (mAndroidId == null) {
|
if (mAndroidId == null) {
|
||||||
Log.i("[Contact] Contact created with RAW ID " + rawId);
|
Log.i("[Contact] Contact created with RAW ID " + rawId);
|
||||||
|
@ -196,7 +199,29 @@ class AndroidContact implements Serializable {
|
||||||
+ ln
|
+ ln
|
||||||
+ " to existing contact "
|
+ " to existing contact "
|
||||||
+ mAndroidId);
|
+ 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
|
+ value
|
||||||
+ " to existing contact "
|
+ " to existing contact "
|
||||||
+ mAndroidId);
|
+ mAndroidId);
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeNumberOrAddress(String noa) {
|
protected void removeNumberOrAddress(String noa, boolean isSIP) {
|
||||||
if (noa == null || noa.isEmpty()) {
|
if (noa == null || noa.isEmpty()) {
|
||||||
Log.e("[Contact] Can't remove null or empty number or address.");
|
Log.e("[Contact] Can't remove null or empty number or address.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mAndroidId == null) {
|
if (mAndroidId == null) {
|
||||||
Log.i("[Contact] Removing number or address " + noa + " from new contact.");
|
Log.e("[Contact] Can't remove a number or address from non existing contact");
|
||||||
// TODO
|
return;
|
||||||
} else {
|
} else {
|
||||||
Log.i(
|
Log.i(
|
||||||
"[Contact] Removing number or address "
|
"[Contact] Removing number or address "
|
||||||
+ noa
|
+ noa
|
||||||
+ " from existing contact "
|
+ " from existing contact "
|
||||||
+ mAndroidId);
|
+ 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 (org == null || org.isEmpty()) {
|
||||||
if (mAndroidId == null) {
|
if (mAndroidId == null) {
|
||||||
Log.e("[Contact] Can't set organization to null or empty for new contact");
|
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)
|
.withValue(CommonDataKinds.Organization.COMPANY, org)
|
||||||
.build());
|
.build());
|
||||||
} else {
|
} else {
|
||||||
Log.i("[Contact] Setting organization " + org + " to existing contact " + mAndroidId);
|
if (previousValue != null) {
|
||||||
// TODO
|
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()
|
.getContext()
|
||||||
.getResources()
|
.getResources()
|
||||||
.getBoolean(R.bool.use_linphone_tag)) {
|
.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) {
|
for (LinphoneNumberOrAddress noa : mNumbersAndAddresses) {
|
||||||
if (noa.isSIPAddress() && noa.getValue() != null) {
|
if (noa.getValue() == null || noa.getValue().isEmpty()) {
|
||||||
noa.setValue(
|
if (noa.getOldValue() != null && !noa.getOldValue().isEmpty()) {
|
||||||
LinphoneUtils.getFullAddressFromUsername(noa.getValue()));
|
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);
|
mContact.setOrganization(mOrganization.getText().toString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,7 +572,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
if (mIsNewContact || mNewSipOrNumberToAdd != null) {
|
if (mIsNewContact || mNewSipOrNumberToAdd != null) {
|
||||||
tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP);
|
tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP);
|
||||||
} else {
|
} else {
|
||||||
tempNounoa = new LinphoneNumberOrAddress(null, isSIP, numberOrAddress);
|
tempNounoa = new LinphoneNumberOrAddress(numberOrAddress, isSIP, numberOrAddress);
|
||||||
}
|
}
|
||||||
final LinphoneNumberOrAddress nounoa = tempNounoa;
|
final LinphoneNumberOrAddress nounoa = tempNounoa;
|
||||||
mNumbersAndAddresses.add(nounoa);
|
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.length() == 0 && ln != null && ln.length() == 0) return;
|
||||||
if (fn != null && fn.equals(mFirstName) && ln != null && ln.equals(mLastName)) return;
|
if (fn != null && fn.equals(mFirstName) && ln != null && ln.equals(mLastName)) return;
|
||||||
|
|
||||||
|
if (commitChanges) {
|
||||||
|
setName(fn, ln);
|
||||||
|
}
|
||||||
|
|
||||||
mFirstName = fn;
|
mFirstName = fn;
|
||||||
mLastName = ln;
|
mLastName = ln;
|
||||||
if (mFullName == null) {
|
if (mFullName == null) {
|
||||||
|
@ -133,10 +137,6 @@ public class LinphoneContact extends AndroidContact
|
||||||
mFullName = mLastName;
|
mFullName = mLastName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commitChanges) {
|
|
||||||
setName(mFirstName, mLastName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
|
@ -159,7 +159,7 @@ public class LinphoneContact extends AndroidContact
|
||||||
if (org != null && org.equals(mOrganization)) return;
|
if (org != null && org.equals(mOrganization)) return;
|
||||||
|
|
||||||
if (commitChanges) {
|
if (commitChanges) {
|
||||||
setOrganization(org);
|
setOrganization(org, mOrganization);
|
||||||
}
|
}
|
||||||
|
|
||||||
mOrganization = org;
|
mOrganization = org;
|
||||||
|
@ -241,7 +241,7 @@ public class LinphoneContact extends AndroidContact
|
||||||
public void removeNumberOrAddress(LinphoneNumberOrAddress noa) {
|
public void removeNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||||
if (noa != null && noa.getOldValue() != null) {
|
if (noa != null && noa.getOldValue() != null) {
|
||||||
|
|
||||||
removeNumberOrAddress(noa.getOldValue());
|
removeNumberOrAddress(noa.getOldValue(), noa.isSIPAddress());
|
||||||
|
|
||||||
if (isFriend()) {
|
if (isFriend()) {
|
||||||
if (noa.isSIPAddress()) {
|
if (noa.isSIPAddress()) {
|
||||||
|
|
Loading…
Reference in a new issue