Fixes & improvements but contact creation still fails...
This commit is contained in:
parent
fdefb77925
commit
573bf2366a
7 changed files with 144 additions and 97 deletions
|
@ -52,7 +52,6 @@ android {
|
|||
versionName "4.1"
|
||||
applicationId getPackageName()
|
||||
multiDexEnabled true
|
||||
manifestPlaceholders = [absolutePackageName:getPackageName()]
|
||||
}
|
||||
|
||||
applicationVariants.all { variant ->
|
||||
|
@ -79,12 +78,20 @@ android {
|
|||
minifyEnabled true
|
||||
signingConfig signingConfigs.release
|
||||
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 {
|
||||
applicationIdSuffix ".debug"
|
||||
debuggable true
|
||||
jniDebuggable true
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,13 +151,16 @@ public class ContactEditorFragment extends Fragment {
|
|||
}
|
||||
mContact = LinphoneContact.createContact();
|
||||
}
|
||||
|
||||
mContact.setFirstNameAndLastName(
|
||||
mFirstName.getText().toString(),
|
||||
mLastName.getText().toString(),
|
||||
true);
|
||||
|
||||
if (mPhotoToAdd != null) {
|
||||
mContact.setPhoto(mPhotoToAdd);
|
||||
}
|
||||
|
||||
for (LinphoneNumberOrAddress noa : mNumbersAndAddresses) {
|
||||
if (noa.isSIPAddress() && noa.getValue() != null) {
|
||||
noa.setValue(
|
||||
|
@ -165,7 +168,11 @@ public class ContactEditorFragment extends Fragment {
|
|||
}
|
||||
mContact.addOrUpdateNumberOrAddress(noa);
|
||||
}
|
||||
mContact.setOrganization(mOrganization.getText().toString(), true);
|
||||
|
||||
if (mIsNewContact && !mOrganization.getText().toString().isEmpty()) {
|
||||
mContact.setOrganization(mOrganization.getText().toString(), true);
|
||||
}
|
||||
|
||||
mContact.save();
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
private transient Uri mPhotoUri, mThumbnailUri;
|
||||
private List<LinphoneNumberOrAddress> mAddresses;
|
||||
private transient ArrayList<ContentProviderOperation> mChangesToCommit;
|
||||
private transient ArrayList<ContentProviderOperation> mChangesToCommit2;
|
||||
private boolean mHasSipAddress;
|
||||
|
||||
public LinphoneContact() {
|
||||
|
@ -69,7 +68,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
mThumbnailUri = null;
|
||||
mPhotoUri = null;
|
||||
mChangesToCommit = new ArrayList<>();
|
||||
mChangesToCommit2 = new ArrayList<>();
|
||||
mHasSipAddress = false;
|
||||
}
|
||||
|
||||
|
@ -84,7 +82,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
}
|
||||
|
||||
private void createAndroidContact() {
|
||||
mChangesToCommit.add(
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, 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_DEFAULT)
|
||||
.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() {
|
||||
|
@ -144,13 +185,9 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
return (this.compareTo(contact) == 0);
|
||||
}
|
||||
|
||||
private void addChangesToCommit(
|
||||
ContentProviderOperation operation, boolean doItAfterAccountCreation) {
|
||||
if (doItAfterAccountCreation) {
|
||||
mChangesToCommit2.add(operation);
|
||||
} else {
|
||||
mChangesToCommit.add(operation);
|
||||
}
|
||||
private void addChangesToCommit(ContentProviderOperation operation) {
|
||||
Log.e("Added operation " + operation);
|
||||
mChangesToCommit.add(operation);
|
||||
}
|
||||
|
||||
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.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;
|
||||
mLastName = ln;
|
||||
if (mFullName == null) {
|
||||
|
@ -224,6 +216,69 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
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() {
|
||||
|
@ -263,8 +318,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
.withValue(
|
||||
ContactsContract.CommonDataKinds.Organization.COMPANY,
|
||||
org)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
} else {
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
|
@ -276,8 +330,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
.withValue(
|
||||
ContactsContract.CommonDataKinds.Organization.COMPANY,
|
||||
org)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
addChangesToCommit(
|
||||
|
@ -289,8 +342,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
.CONTENT_ITEM_TYPE)
|
||||
.withValue(
|
||||
ContactsContract.CommonDataKinds.Organization.COMPANY, org)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,8 +385,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.withValue(ContactsContract.Data.IS_PRIMARY, 1)
|
||||
.withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
} else {
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
|
@ -344,8 +395,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsContract.CommonDataKinds.Photo
|
||||
.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -409,8 +459,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
addChangesToCommit(
|
||||
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
} else {
|
||||
String select;
|
||||
if (noa.isSIPAddress()) {
|
||||
|
@ -440,8 +489,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
addChangesToCommit(
|
||||
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,8 +540,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsManager.getInstance()
|
||||
.getString(R.string.app_name))
|
||||
.withValue(ContactsContract.Data.DATA3, noa.getValue())
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
} else {
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(
|
||||
|
@ -510,8 +557,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsManager.getInstance()
|
||||
.getString(R.string.app_name))
|
||||
.withValue(ContactsContract.Data.DATA3, noa.getValue())
|
||||
.build(),
|
||||
true);
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
|
@ -551,8 +597,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsContract.Data.RAW_CONTACT_ID,
|
||||
mAndroidRawId)
|
||||
.withValues(values)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
} else {
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(
|
||||
|
@ -560,8 +605,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
.withValueBackReference(
|
||||
ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValues(values)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -586,8 +630,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsManager.getInstance()
|
||||
.getString(R.string.app_name))
|
||||
.withValue(ContactsContract.Data.DATA3, noa.getValue())
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
} else {
|
||||
addChangesToCommit(
|
||||
ContentProviderOperation.newInsert(
|
||||
|
@ -604,8 +647,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsManager.getInstance()
|
||||
.getString(R.string.app_name))
|
||||
.withValue(ContactsContract.Data.DATA3, noa.getValue())
|
||||
.build(),
|
||||
true);
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
|
@ -652,8 +694,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.withValues(values)
|
||||
.build(),
|
||||
false);
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -781,7 +822,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
Log.e(e);
|
||||
} finally {
|
||||
mChangesToCommit = new ArrayList<>();
|
||||
mChangesToCommit2 = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1125,10 +1165,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0)
|
||||
.build());
|
||||
|
||||
if (mChangesToCommit2.size() > 0) {
|
||||
batch.addAll(mChangesToCommit2);
|
||||
}
|
||||
|
||||
try {
|
||||
LinphoneService.instance()
|
||||
.getContentResolver()
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
<!-- Global -->
|
||||
<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="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="user_agent">LinphoneAndroid</string>
|
||||
<bool name="orientation_portrait_only">false</bool>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<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:label="@string/app_name"
|
||||
android:smallIcon="@drawable/linphone_logo" />
|
|
@ -5,7 +5,7 @@
|
|||
android:detailColumn="data3"
|
||||
android:detailSocialSummary="true"
|
||||
android:icon="@drawable/linphone_logo"
|
||||
android:mimeType="vnd.android.cursor.item/${absolutePackageName}.profile"
|
||||
android:mimeType="@string/sync_mimetype"
|
||||
android:summaryColumn="data2" />
|
||||
|
||||
</ContactsSource>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<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:supportsUploading="false"
|
||||
android:userVisible="false" />
|
||||
|
|
Loading…
Reference in a new issue