Fixes & improvements but contact creation still fails...

This commit is contained in:
Sylvain Berfini 2018-12-06 17:49:08 +01:00
parent fdefb77925
commit 573bf2366a
7 changed files with 144 additions and 97 deletions

View file

@ -52,7 +52,6 @@ android {
versionName "4.1" versionName "4.1"
applicationId getPackageName() applicationId getPackageName()
multiDexEnabled true multiDexEnabled true
manifestPlaceholders = [absolutePackageName:getPackageName()]
} }
applicationVariants.all { variant -> applicationVariants.all { variant ->
@ -79,12 +78,20 @@ android {
minifyEnabled true minifyEnabled true
signingConfig signingConfigs.release signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "sync_account_type", getPackageName() + ".sync"
resValue "string", "file_provider", getPackageName() + ".provider"
resValue "string", "sync_mimetype", "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address"
} }
debug { debug {
applicationIdSuffix ".debug" applicationIdSuffix ".debug"
debuggable true debuggable true
jniDebuggable true jniDebuggable true
versionNameSuffix '-debug' versionNameSuffix '-debug'
resValue "string", "sync_account_type", getPackageName() + ".sync"
resValue "string", "file_provider", getPackageName() + ".provider"
resValue "string", "sync_mimetype", "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address"
} }
} }

View file

@ -151,13 +151,16 @@ public class ContactEditorFragment extends Fragment {
} }
mContact = LinphoneContact.createContact(); mContact = LinphoneContact.createContact();
} }
mContact.setFirstNameAndLastName( mContact.setFirstNameAndLastName(
mFirstName.getText().toString(), mFirstName.getText().toString(),
mLastName.getText().toString(), mLastName.getText().toString(),
true); true);
if (mPhotoToAdd != null) { if (mPhotoToAdd != null) {
mContact.setPhoto(mPhotoToAdd); mContact.setPhoto(mPhotoToAdd);
} }
for (LinphoneNumberOrAddress noa : mNumbersAndAddresses) { for (LinphoneNumberOrAddress noa : mNumbersAndAddresses) {
if (noa.isSIPAddress() && noa.getValue() != null) { if (noa.isSIPAddress() && noa.getValue() != null) {
noa.setValue( noa.setValue(
@ -165,7 +168,11 @@ public class ContactEditorFragment extends Fragment {
} }
mContact.addOrUpdateNumberOrAddress(noa); mContact.addOrUpdateNumberOrAddress(noa);
} }
mContact.setOrganization(mOrganization.getText().toString(), true);
if (mIsNewContact && !mOrganization.getText().toString().isEmpty()) {
mContact.setOrganization(mOrganization.getText().toString(), true);
}
mContact.save(); mContact.save();
getFragmentManager().popBackStackImmediate(); getFragmentManager().popBackStackImmediate();
} }

View file

@ -59,7 +59,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
private transient Uri mPhotoUri, mThumbnailUri; private transient Uri mPhotoUri, mThumbnailUri;
private List<LinphoneNumberOrAddress> mAddresses; private List<LinphoneNumberOrAddress> mAddresses;
private transient ArrayList<ContentProviderOperation> mChangesToCommit; private transient ArrayList<ContentProviderOperation> mChangesToCommit;
private transient ArrayList<ContentProviderOperation> mChangesToCommit2;
private boolean mHasSipAddress; private boolean mHasSipAddress;
public LinphoneContact() { public LinphoneContact() {
@ -69,7 +68,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
mThumbnailUri = null; mThumbnailUri = null;
mPhotoUri = null; mPhotoUri = null;
mChangesToCommit = new ArrayList<>(); mChangesToCommit = new ArrayList<>();
mChangesToCommit2 = new ArrayList<>();
mHasSipAddress = false; mHasSipAddress = false;
} }
@ -84,7 +82,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
} }
private void createAndroidContact() { private void createAndroidContact() {
mChangesToCommit.add( addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
@ -92,7 +90,50 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE,
ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT) ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
.build()); .build());
setAndroidId("0"); mAndroidId = "0";
if (LinphoneManager.getInstance()
.getContext()
.getResources()
.getBoolean(R.bool.use_linphone_tag)) {
mAndroidTagId = "0";
addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(
ContactsContract.RawContacts.ACCOUNT_TYPE,
ContactsManager.getInstance()
.getString(R.string.sync_account_type))
.withValue(
ContactsContract.RawContacts.ACCOUNT_NAME,
ContactsManager.getInstance()
.getString(R.string.sync_account_name))
.withValue(
ContactsContract.RawContacts.AGGREGATION_MODE,
ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
.build());
addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName
.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
getFullName())
.build());
addChangesToCommit(
ContentProviderOperation.newUpdate(
ContactsContract.AggregationExceptions.CONTENT_URI)
.withValue(
ContactsContract.AggregationExceptions.TYPE,
ContactsContract.AggregationExceptions.TYPE_KEEP_TOGETHER)
.withValue(
ContactsContract.AggregationExceptions.RAW_CONTACT_ID1,
mAndroidRawId)
.withValueBackReference(
ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0)
.build());
}
} }
private void createFriend() { private void createFriend() {
@ -144,13 +185,9 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
return (this.compareTo(contact) == 0); return (this.compareTo(contact) == 0);
} }
private void addChangesToCommit( private void addChangesToCommit(ContentProviderOperation operation) {
ContentProviderOperation operation, boolean doItAfterAccountCreation) { Log.e("Added operation " + operation);
if (doItAfterAccountCreation) { mChangesToCommit.add(operation);
mChangesToCommit2.add(operation);
} else {
mChangesToCommit.add(operation);
}
} }
public String getFullName() { public String getFullName() {
@ -165,51 +202,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
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 (isAndroidContact() && commitChanges) {
if (mFirstName != null || mLastName != null) {
String select =
ContactsContract.Data.CONTACT_ID
+ "=? AND "
+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
+ "'";
String[] args = new String[] {getAndroidId()};
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(),
false);
} else {
addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.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(),
false);
}
}
mFirstName = fn; mFirstName = fn;
mLastName = ln; mLastName = ln;
if (mFullName == null) { if (mFullName == null) {
@ -224,6 +216,69 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
mFullName = mLastName; mFullName = mLastName;
} }
} }
if (commitChanges) {
if (mFirstName != null || mLastName != null) {
if (!isAndroidContact() || "0".equals(getAndroidId())) {
addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName
.CONTENT_ITEM_TYPE)
.build());
addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName
.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.StructuredName
.DISPLAY_NAME,
mFullName)
.withValue(
ContactsContract.CommonDataKinds.StructuredName
.GIVEN_NAME,
fn)
.withValue(
ContactsContract.CommonDataKinds.StructuredName
.FAMILY_NAME,
ln)
.build());
} else {
String select =
ContactsContract.Data.CONTACT_ID
+ "=? AND "
+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.StructuredName
.CONTENT_ITEM_TYPE
+ "'";
String[] args = new String[] {getAndroidId()};
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());
}
}
}
} }
public String getFirstName() { public String getFirstName() {
@ -263,8 +318,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
.withValue( .withValue(
ContactsContract.CommonDataKinds.Organization.COMPANY, ContactsContract.CommonDataKinds.Organization.COMPANY,
org) org)
.build(), .build());
false);
} else { } else {
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
@ -276,8 +330,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
.withValue( .withValue(
ContactsContract.CommonDataKinds.Organization.COMPANY, ContactsContract.CommonDataKinds.Organization.COMPANY,
org) org)
.build(), .build());
false);
} }
} else { } else {
addChangesToCommit( addChangesToCommit(
@ -289,8 +342,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
.CONTENT_ITEM_TYPE) .CONTENT_ITEM_TYPE)
.withValue( .withValue(
ContactsContract.CommonDataKinds.Organization.COMPANY, org) ContactsContract.CommonDataKinds.Organization.COMPANY, org)
.build(), .build());
false);
} }
} }
@ -333,8 +385,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo) .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
.withValue(ContactsContract.Data.IS_PRIMARY, 1) .withValue(ContactsContract.Data.IS_PRIMARY, 1)
.withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1) .withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1)
.build(), .build());
false);
} else { } else {
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
@ -344,8 +395,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsContract.CommonDataKinds.Photo ContactsContract.CommonDataKinds.Photo
.CONTENT_ITEM_TYPE) .CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo) .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
.build(), .build());
false);
} }
} }
} }
@ -409,8 +459,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI) ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
.withSelection(select, args) .withSelection(select, args)
.build(), .build());
false);
} else { } else {
String select; String select;
if (noa.isSIPAddress()) { if (noa.isSIPAddress()) {
@ -440,8 +489,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI) ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
.withSelection(select, args) .withSelection(select, args)
.build(), .build());
false);
} }
} }
@ -492,8 +540,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsManager.getInstance() ContactsManager.getInstance()
.getString(R.string.app_name)) .getString(R.string.app_name))
.withValue(ContactsContract.Data.DATA3, noa.getValue()) .withValue(ContactsContract.Data.DATA3, noa.getValue())
.build(), .build());
false);
} else { } else {
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newInsert( ContentProviderOperation.newInsert(
@ -510,8 +557,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsManager.getInstance() ContactsManager.getInstance()
.getString(R.string.app_name)) .getString(R.string.app_name))
.withValue(ContactsContract.Data.DATA3, noa.getValue()) .withValue(ContactsContract.Data.DATA3, noa.getValue())
.build(), .build());
true);
} }
} else { } else {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -551,8 +597,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data.RAW_CONTACT_ID,
mAndroidRawId) mAndroidRawId)
.withValues(values) .withValues(values)
.build(), .build());
false);
} else { } else {
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newInsert( ContentProviderOperation.newInsert(
@ -560,8 +605,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
.withValueBackReference( .withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID, 0) ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValues(values) .withValues(values)
.build(), .build());
false);
} }
} }
} else { } else {
@ -586,8 +630,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsManager.getInstance() ContactsManager.getInstance()
.getString(R.string.app_name)) .getString(R.string.app_name))
.withValue(ContactsContract.Data.DATA3, noa.getValue()) .withValue(ContactsContract.Data.DATA3, noa.getValue())
.build(), .build());
false);
} else { } else {
addChangesToCommit( addChangesToCommit(
ContentProviderOperation.newInsert( ContentProviderOperation.newInsert(
@ -604,8 +647,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsManager.getInstance() ContactsManager.getInstance()
.getString(R.string.app_name)) .getString(R.string.app_name))
.withValue(ContactsContract.Data.DATA3, noa.getValue()) .withValue(ContactsContract.Data.DATA3, noa.getValue())
.build(), .build());
true);
} }
} else { } else {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -652,8 +694,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsContract.Data.CONTENT_URI) ContactsContract.Data.CONTENT_URI)
.withSelection(select, args) .withSelection(select, args)
.withValues(values) .withValues(values)
.build(), .build());
false);
} }
} }
} }
@ -781,7 +822,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
Log.e(e); Log.e(e);
} finally { } finally {
mChangesToCommit = new ArrayList<>(); mChangesToCommit = new ArrayList<>();
mChangesToCommit2 = new ArrayList<>();
} }
} }
@ -1125,10 +1165,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0) ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0)
.build()); .build());
if (mChangesToCommit2.size() > 0) {
batch.addAll(mChangesToCommit2);
}
try { try {
LinphoneService.instance() LinphoneService.instance()
.getContentResolver() .getContentResolver()

View file

@ -4,9 +4,6 @@
<!-- Global --> <!-- Global -->
<string name="default_domain">sip.linphone.org</string><!-- Set the default domain used for account creation/addresses --> <string name="default_domain">sip.linphone.org</string><!-- Set the default domain used for account creation/addresses -->
<string name="default_conference_factory_uri">sip:conference-factory@sip.linphone.org</string> <string name="default_conference_factory_uri">sip:conference-factory@sip.linphone.org</string>
<string name="file_provider">${absolutePackageName}.provider</string>
<string name="sync_account_type">${absolutePackageName}</string>
<string name="sync_mimetype">vnd.android.cursor.item/${absolutePackageName}.profile</string>
<string name="rls_uri">sip:rls@sip.linphone.org</string> <string name="rls_uri">sip:rls@sip.linphone.org</string>
<string name="user_agent">LinphoneAndroid</string> <string name="user_agent">LinphoneAndroid</string>
<bool name="orientation_portrait_only">false</bool> <bool name="orientation_portrait_only">false</bool>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android" <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="${absolutePackageName}" android:accountType="@string/sync_account_type"
android:icon="@drawable/linphone_logo" android:icon="@drawable/linphone_logo"
android:label="@string/app_name" android:label="@string/app_name"
android:smallIcon="@drawable/linphone_logo" /> android:smallIcon="@drawable/linphone_logo" />

View file

@ -5,7 +5,7 @@
android:detailColumn="data3" android:detailColumn="data3"
android:detailSocialSummary="true" android:detailSocialSummary="true"
android:icon="@drawable/linphone_logo" android:icon="@drawable/linphone_logo"
android:mimeType="vnd.android.cursor.item/${absolutePackageName}.profile" android:mimeType="@string/sync_mimetype"
android:summaryColumn="data2" /> android:summaryColumn="data2" />
</ContactsSource> </ContactsSource>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" <sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="${absolutePackageName}" android:accountType="@string/sync_account_name"
android:contentAuthority="com.android.contacts" android:contentAuthority="com.android.contacts"
android:supportsUploading="false" android:supportsUploading="false"
android:userVisible="false" /> android:userVisible="false" />