Skip to content

Commit

Permalink
Moved ContactId from Internal field to Public field
Browse files Browse the repository at this point in the history
  • Loading branch information
tamir7 committed May 22, 2017
1 parent 7cfa0a7 commit 6b6c58f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.3.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface AbstractField {
}

public enum Field implements AbstractField {
ContactId(null, ContactsContract.RawContacts.CONTACT_ID),
DisplayName(null, ContactsContract.Data.DISPLAY_NAME),
GivenName(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE,
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME),
Expand Down Expand Up @@ -122,7 +123,6 @@ public String getMimeType() {
}

enum InternalField implements AbstractField {
ContactId(null, ContactsContract.RawContacts.CONTACT_ID),
MimeType(null, ContactsContract.Data.MIMETYPE);

private final String column;
Expand Down
105 changes: 57 additions & 48 deletions contacts/src/main/java/com/github/tamir7/contacts/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,58 +276,67 @@ private void updateContact(Contact contact, CursorHelper helper) {
}

String mimeType = helper.getMimeType();
if (mimeType.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
PhoneNumber phoneNumber = helper.getPhoneNumber();
if (phoneNumber != null) {
contact.addPhoneNumber(phoneNumber);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
Email email = helper.getEmail();
if (email != null) {
contact.addEmail(email);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)) {
Event event = helper.getEvent();
if (event != null) {
contact.addEvent(event);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)) {
String givenName = helper.getGivenName();
if (givenName != null) {
contact.addGivenName(givenName);
}
switch (mimeType) {
case ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE:
PhoneNumber phoneNumber = helper.getPhoneNumber();
if (phoneNumber != null) {
contact.addPhoneNumber(phoneNumber);
}
break;
case ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE:
Email email = helper.getEmail();
if (email != null) {
contact.addEmail(email);
}
break;
case ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE:
Event event = helper.getEvent();
if (event != null) {
contact.addEvent(event);
}
break;
case ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE:
String givenName = helper.getGivenName();
if (givenName != null) {
contact.addGivenName(givenName);
}

String familyName = helper.getFamilyName();
if (familyName != null) {
contact.addFamilyName(familyName);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)) {
String companyName = helper.getCompanyName();
String familyName = helper.getFamilyName();
if (familyName != null) {
contact.addFamilyName(familyName);
}
break;
case ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE:
String companyName = helper.getCompanyName();

if (companyName != null) {
contact.addCompanyName(companyName);
}
if (companyName != null) {
contact.addCompanyName(companyName);
}

String companyTitle = helper.getCompanyTitle();
String companyTitle = helper.getCompanyTitle();

if (companyTitle != null) {
contact.addCompanyTitle(companyTitle);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE)) {
String website = helper.getWebsite();
if (website != null) {
contact.addWebsite(website);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE)) {
String note = helper.getNote();
if (note != null) {
contact.addNote(note);
}
} else if (mimeType.equals(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Address address = helper.getAddress();
if (address != null) {
contact.addAddress(address);
}
if (companyTitle != null) {
contact.addCompanyTitle(companyTitle);
}
break;
case ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE:
String website = helper.getWebsite();
if (website != null) {
contact.addWebsite(website);
}
break;
case ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE:
String note = helper.getNote();
if (note != null) {
contact.addNote(note);
}
break;
case ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE:
Address address = helper.getAddress();
if (address != null) {
contact.addAddress(address);
}
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.github.tamir7.contacts.Contact;
import com.github.tamir7.contacts.Contacts;
import com.github.tamir7.contacts.Query;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,21 +37,21 @@ private void queryContacts() {
@Override
public Void call() throws Exception {
Query q = Contacts.getQuery();
q.include(Contact.Field.DisplayName, Contact.Field.PhoneNumber, Contact.Field.PhoneNormalizedNumber, Contact.Field.Email);
q.include(Contact.Field.ContactId, Contact.Field.DisplayName, Contact.Field.PhoneNumber, Contact.Field.PhoneNormalizedNumber, Contact.Field.Email);
Query q1 = Contacts.getQuery();
q1.whereEqualTo(Contact.Field.DisplayName, "Tamir Shomer");
q1.hasPhoneNumber();

Query q2 = Contacts.getQuery();
q2.whereStartsWith(Contact.Field.DisplayName, "Guy");
q2.whereStartsWith(Contact.Field.ContactId, "791");
q2.hasPhoneNumber();
List<Query> queries = new ArrayList<>();
queries.add(q1);
queries.add(q2);
q.or(queries);

List<Contact> contacts = q.find();
Log.e(TAG, new Gson().toJson(contacts));
Log.e(TAG, new GsonBuilder().setPrettyPrinting().create().toJson(contacts));
return null;
}
}).continueWith(new Continuation<Void, Void>() {
Expand Down

0 comments on commit 6b6c58f

Please sign in to comment.