Added thin object layer around contact data
This refactoring abstracts out the need to directly
refer to Contacts database columns throughout the code. Instead,
all of this information is retained in getter/setter methods
within the Contact, RawContact, and DataItem classes and
sub-classes.
ContactLoader.Result class has been pulled to the top level as
the Contact class.
The Entity class has been removed and replaced with a RawContact
class, with getters/setters to raw contact information.
Renamed EntityDelta to RawContactDelta for better understandability
as well as adding getters/setters for specific fields in the
ValuesDelta nested class within EntityDelta. EntityDeltaList
and EntityModifier have been renamed to RawContactDeltaList and
RawContactModifier with the methods using the RawContact class
directly rather than the Entity class.
Data items for a raw contact are represented by a DataItem object
with specialized getters/setters for subclasses of DataItem.
(e.g., EmailDataItem, PhoneDataItem. etc.). DataItem is a wrapper
around ContentValues. This abstracts away the ContactsContract
column fields into getters/setters.
The above refactoring is accompanied with changes throughout the
codebase to use the new Contact, RawContact, and DataItem classes.
Change-Id: I31c1dccd724e9652f9d0af78ca81feb6c5acd71d
diff --git a/src/com/android/contacts/ContactSaveService.java b/src/com/android/contacts/ContactSaveService.java
index 3acc34c..4333aa4 100644
--- a/src/com/android/contacts/ContactSaveService.java
+++ b/src/com/android/contacts/ContactSaveService.java
@@ -47,10 +47,10 @@
import android.widget.Toast;
import com.android.contacts.model.AccountTypeManager;
-import com.android.contacts.model.AccountWithDataSet;
-import com.android.contacts.model.EntityDelta;
-import com.android.contacts.model.EntityDeltaList;
-import com.android.contacts.model.EntityModifier;
+import com.android.contacts.model.RawContactModifier;
+import com.android.contacts.model.RawContactDelta;
+import com.android.contacts.model.RawContactDeltaList;
+import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.util.CallerInfoCacheUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -289,7 +289,7 @@
* @param rawContactId identifies a writable raw-contact whose photo is to be updated.
* @param updatedPhotoPath denotes a temporary file containing the contact's new photo.
*/
- public static Intent createSaveContactIntent(Context context, EntityDeltaList state,
+ public static Intent createSaveContactIntent(Context context, RawContactDeltaList state,
String saveModeExtraKey, int saveMode, boolean isProfile,
Class<? extends Activity> callbackActivity, String callbackAction, long rawContactId,
String updatedPhotoPath) {
@@ -306,7 +306,7 @@
* Contact Editor.
* @param updatedPhotos maps each raw-contact's ID to the file-path of the new photo.
*/
- public static Intent createSaveContactIntent(Context context, EntityDeltaList state,
+ public static Intent createSaveContactIntent(Context context, RawContactDeltaList state,
String saveModeExtraKey, int saveMode, boolean isProfile,
Class<? extends Activity> callbackActivity, String callbackAction,
Bundle updatedPhotos) {
@@ -332,13 +332,13 @@
}
private void saveContact(Intent intent) {
- EntityDeltaList state = intent.getParcelableExtra(EXTRA_CONTACT_STATE);
+ RawContactDeltaList state = intent.getParcelableExtra(EXTRA_CONTACT_STATE);
boolean isProfile = intent.getBooleanExtra(EXTRA_SAVE_IS_PROFILE, false);
Bundle updatedPhotos = intent.getParcelableExtra(EXTRA_UPDATED_PHOTOS);
// Trim any empty fields, and RawContacts, before persisting
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this);
- EntityModifier.trimEmpty(state, accountTypes);
+ RawContactModifier.trimEmpty(state, accountTypes);
Uri lookupUri = null;
@@ -427,16 +427,16 @@
throw new IllegalStateException("Version consistency failed for a new contact");
}
- final EntityDeltaList newState = EntityDeltaList.fromQuery(
+ final RawContactDeltaList newState = RawContactDeltaList.fromQuery(
isProfile
? RawContactsEntity.PROFILE_CONTENT_URI
: RawContactsEntity.CONTENT_URI,
resolver, sb.toString(), null, null);
- state = EntityDeltaList.mergeAfter(newState, state);
+ state = RawContactDeltaList.mergeAfter(newState, state);
// Update the new state to use profile URIs if appropriate.
if (isProfile) {
- for (EntityDelta delta : state) {
+ for (RawContactDelta delta : state) {
delta.setProfileQueryUri();
}
}
@@ -518,7 +518,7 @@
/**
* Find the ID of an existing or newly-inserted raw-contact. If none exists, return -1.
*/
- private long getRawContactId(EntityDeltaList state,
+ private long getRawContactId(RawContactDeltaList state,
final ArrayList<ContentProviderOperation> diff,
final ContentProviderResult[] results) {
long existingRawContactId = state.findRawContactId();