|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.engine.contactsync.NativeImporter
public class NativeImporter
The NativeImporter class is responsible for importing contacts from the native address book to the people database. To do so, it compares the native address book and the people database to find new changes and update the people database accordingly. Usage: - instantiate the class - call the tick() method until isDone() returns true - current progress can be obtained via getPosition() / getCount() - check the getResult() to get a status (OK, KO...)
Nested Class Summary | |
---|---|
private static class |
NativeImporter.NCCComparator
Native ContactChange Comparator class. |
Field Summary | |
---|---|
private java.lang.String |
GOOGLE_ACCOUNT_TYPE
|
private NativeContactsApi.Account[] |
mAccounts
The array of accounts from where to import the native contacts. |
private static int |
MAX_CONTACTS_OPERATION_COUNT
Number of contacts to be processed "per tick". |
private int |
mCurrentDeletedId
The index of the current deleted people id. |
private int |
mCurrentNativeId
The index of the current native id. |
private int |
mCurrentPeopleId
The index in the current people id. |
private DynamicArrayLong |
mDeletedIds
Array to store the people ids of contacts to delete. |
private boolean |
mIsFirstImportOn2X
Boolean that tracks if the first time Import for 2.X is ongoing. |
private NativeContactsApi |
mNativeContactsApi
Handler to the Native Contacts API. |
private long[] |
mNativeContactsIds
The list of native ids from the native side. |
private NativeImporter.NCCComparator |
mNCCC
Instance of a ContactChange comparator. |
private PeopleContactsApi |
mPeopleContactsApi
Handler to the People Contacts API. |
private long[] |
mPeopleNativeContactsIds
The list of native ids from the people side. |
private int |
mProcessedIds
The current count of processed ids. |
private int |
mResult
The result status. |
private int |
mState
The current state. |
private int |
mTotalIds
The total count of ids to process (native database + people database). |
static int |
RESULT_ERROR
The undefined result when the NativeImporter has not been run yet. |
static int |
RESULT_OK
The ok result when the NativeImporter has finished successfully. |
static int |
RESULT_UNDEFINED
The undefined result when the NativeImporter has not been run yet. |
private static int |
STATE_DONE
Internal state representing the task to perform: final state, nothing else to perform. |
private static int |
STATE_GET_IDS_LISTS
Internal state representing the task to perform: gets the list of native contacts ids and people contacts ids. |
private static int |
STATE_ITERATE_THROUGH_IDS
Internal state representing the task to perform: iterates through the list of ids to find differences (i.e. added contact, modified contact, deleted contact). |
private static int |
STATE_PROCESS_DELETED
Internal state representing the task to perform: process the list of deleted contacts (i.e. delete the contacts from the people database). |
Constructor Summary | |
---|---|
NativeImporter(PeopleContactsApi pca,
NativeContactsApi nca,
boolean firstTimeImport)
Constructor. |
Method Summary | |
---|---|
private void |
addNewContact(long nativeId)
Adds a new contact to the people database. |
private boolean |
areContactChangeValuesEqualsPlusFix(ContactChange[] masterChanges,
int masterIndex,
ContactChange[] newChanges,
int newIndex)
Tells whether or not a master change is equal to a new change and performs some modifications on the provided new change in the specific case of KEY_VCARD_ORG on Android 1.X. |
private void |
checkExistingContact(long nativeId)
Check changes between an existing contact on both native and people database. |
private void |
complete(int result)
Sets the internal state to DONE with the provided result status. |
private ContactChange[] |
computeDelta(ContactChange[] masterChanges,
ContactChange[] newChanges)
Computes the difference between the provided arrays of ContactChange. |
private void |
forceNabDetailId(ContactChange[] contact)
Forces a native detail id to detail that do not have one by setting it to the native contact id. |
int |
getCount()
Gets the total number of ids to process. |
private void |
getIdsLists()
Gets the list of native and people contacts ids. |
int |
getPosition()
Gets the current position in the list of ids. |
int |
getResult()
Gets the import result. |
private void |
initAccounts(boolean firstTimeImport)
Sets the accounts used to import the native contacs. |
private boolean |
isContactChangeKeySupported(ContactChange change)
Determines whether or not a ContactChange key is supported on native side. |
boolean |
isDone()
Returns the import state. |
private void |
iterateThroughNativeIds()
Iterates through the list of native and People ids to detect changes. |
private void |
processDeleted()
Deletes the contacts that were added the deleted array. |
private void |
removeNativeIds(ContactChange[] contact)
Removes the native ids in case of a first time import on the Android 2.X platform. |
private void |
setDetailForDeleteOrUpdate(ContactChange[] contactChanges,
int index)
Sets a detail as to be deleted or updated. |
private void |
sortContactChanges(ContactChange[] changes)
Sorts the provided array of ContactChange by key and native id. |
boolean |
tick()
Tick method to call each time there is time for processing the native contacts import. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.lang.String GOOGLE_ACCOUNT_TYPE
public static final int RESULT_UNDEFINED
getResult()
,
Constant Field Valuespublic static final int RESULT_OK
getResult()
,
Constant Field Valuespublic static final int RESULT_ERROR
getResult()
,
Constant Field Valuesprivate static final int MAX_CONTACTS_OPERATION_COUNT
tick()
,
Constant Field Valuesprivate PeopleContactsApi mPeopleContactsApi
private NativeContactsApi mNativeContactsApi
private static final int STATE_GET_IDS_LISTS
private static final int STATE_ITERATE_THROUGH_IDS
private static final int STATE_PROCESS_DELETED
private static final int STATE_DONE
private int mState
private long[] mNativeContactsIds
private long[] mPeopleNativeContactsIds
private int mTotalIds
private int mProcessedIds
private int mCurrentNativeId
mNativeContactsIds
private int mCurrentPeopleId
mPeopleNativeContactsIds
private int mCurrentDeletedId
mDeletedIds
private DynamicArrayLong mDeletedIds
private int mResult
private NativeImporter.NCCComparator mNCCC
private NativeContactsApi.Account[] mAccounts
private boolean mIsFirstImportOn2X
Constructor Detail |
---|
public NativeImporter(PeopleContactsApi pca, NativeContactsApi nca, boolean firstTimeImport)
pca
- handler to the People contacts Apinca
- handler to the Native contacts ApifirstTimeImport
- true if we import from native for the first time, false if notMethod Detail |
---|
private void initAccounts(boolean firstTimeImport)
private void complete(int result)
result
- the result status to setpublic boolean tick()
public boolean isDone()
public int getResult()
RESULT_OK
,
RESULT_ERROR
,
RESULT_UNDEFINED
public int getPosition()
getCount()
public int getCount()
private void getIdsLists()
private void iterateThroughNativeIds()
private void processDeleted()
private void addNewContact(long nativeId)
private void checkExistingContact(long nativeId)
nativeId
- the native id of the contact to checkprivate void sortContactChanges(ContactChange[] changes)
changes
- the ContactChange array to sortprivate ContactChange[] computeDelta(ContactChange[] masterChanges, ContactChange[] newChanges)
masterChanges
- the master array of ContactChange (i.e. the original one)newChanges
- the new ContactChange array (i.e. contains the new version of a contact)
private void removeNativeIds(ContactChange[] contact)
contact
- the contact to clear from native idsprivate void forceNabDetailId(ContactChange[] contact)
contact
- the contact to fixprivate boolean areContactChangeValuesEqualsPlusFix(ContactChange[] masterChanges, int masterIndex, ContactChange[] newChanges, int newIndex)
masterChanges
- the array of master changesmasterIndex
- the index of the change within the array of master changesnewChanges
- the array of new changesnewIndex
- the index of the change within the array of new changes
private void setDetailForDeleteOrUpdate(ContactChange[] contactChanges, int index)
contactChanges
- the array of ContactChangeindex
- the index of the ContactChange to set in the array of ContactChangeprivate boolean isContactChangeKeySupported(ContactChange change)
change
- the ContactChange to check
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc