Create contact works
This commit is contained in:
parent
aec6a066e5
commit
4956bed080
3 changed files with 49 additions and 27 deletions
|
@ -121,28 +121,26 @@ public class ContactEditorFragment extends Fragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isNewContact) {
|
||||
boolean areAllFielsEmpty = true;
|
||||
for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
|
||||
if (nounoa.newNumberOrAddress != null && !nounoa.newNumberOrAddress.equals("")) {
|
||||
areAllFielsEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (areAllFielsEmpty) {
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
return;
|
||||
/*boolean areAllFielsEmpty = true;
|
||||
for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
|
||||
if (nounoa.newNumberOrAddress != null && !nounoa.newNumberOrAddress.equals("")) {
|
||||
areAllFielsEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (areAllFielsEmpty) {
|
||||
getFragmentManager().popBackStackImmediate();
|
||||
return;
|
||||
}*/
|
||||
contact = LinphoneContact.createAndroidContact();
|
||||
}
|
||||
contact.setFirstNameAndLastName(firstName.getText().toString(), lastName.getText().toString());
|
||||
if (photoToAdd != null) {
|
||||
contact.setPhoto(photoToAdd);
|
||||
}
|
||||
|
||||
contact.setFirstNameAndLastName(firstName.getText().toString(), lastName.getText().toString());
|
||||
|
||||
/*for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
||||
numberOrAddress.save();
|
||||
}*/
|
||||
|
||||
contact.save();
|
||||
|
||||
/*try {
|
||||
|
|
|
@ -49,7 +49,6 @@ public class ContactsManager extends ContentObserver {
|
|||
|
||||
private static ContactsManager instance;
|
||||
private List<LinphoneContact> contacts;
|
||||
//private Cursor contactCursor, sipContactCursor;
|
||||
private Account mAccount;
|
||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
||||
private ContentResolver contentResolver;
|
||||
|
@ -88,7 +87,6 @@ public class ContactsManager extends ContentObserver {
|
|||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
Log.e("############################################ OnChange ############################################");
|
||||
List<LinphoneContact> contacts = fetchContactsAsync();
|
||||
Message msg = handler.obtainMessage();
|
||||
msg.what = CONTACTS_UPDATED;
|
||||
|
|
|
@ -65,17 +65,26 @@ public class LinphoneContact implements Serializable {
|
|||
public void setFirstNameAndLastName(String fn, String ln) {
|
||||
if (fn.length() == 0 && ln.length() == 0) return;
|
||||
|
||||
if (isAndroidContact() && (!firstName.equals(fn) || !lastName.equals(ln))) {
|
||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'";
|
||||
String[] args = new String[]{ getAndroidId() };
|
||||
|
||||
changesToCommit.add(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()
|
||||
);
|
||||
if (isAndroidContact()) {
|
||||
if ((firstName != null && !firstName.equals(fn)) || (lastName != null && !lastName.equals(ln))) {
|
||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'";
|
||||
String[] args = new String[]{ getAndroidId() };
|
||||
|
||||
changesToCommit.add(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()
|
||||
);
|
||||
} else {
|
||||
changesToCommit.add(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());
|
||||
}
|
||||
}
|
||||
firstName = fn;
|
||||
lastName = ln;
|
||||
|
@ -120,6 +129,12 @@ public class LinphoneContact implements Serializable {
|
|||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
} else {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
String id = findDataId(getAndroidId());
|
||||
|
@ -249,6 +264,17 @@ public class LinphoneContact implements Serializable {
|
|||
|
||||
return contact;
|
||||
}
|
||||
|
||||
public static LinphoneContact createAndroidContact() {
|
||||
LinphoneContact contact = new LinphoneContact();
|
||||
contact.changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
||||
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
||||
.build());
|
||||
contact.setAndroidId("0");
|
||||
return contact;
|
||||
}
|
||||
|
||||
private Uri getContactUri(String id) {
|
||||
Uri person = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id);
|
||||
|
|
Loading…
Reference in a new issue