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