Search in sources :

Example 16 with Flag

use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method setFirstTimeNativeSyncComplete.

/**
     * Helper function to update the database when the state of the
     * {@link #mFirstTimeNativeSyncComplete} flag changes.
     * 
     * @param value New value to the flag. True indicates that the native fetch
     *            part of the first time sync has been completed. The flag is
     *            never set to false again by the engine, it will be only set to
     *            false when a remove user data is done (and the database is
     *            deleted).
     * @return SUCCESS or a suitable error code if the database could not be
     *         updated.
     */
private ServiceStatus setFirstTimeNativeSyncComplete(boolean value) {
    if (mFirstTimeSyncComplete == value) {
        return ServiceStatus.SUCCESS;
    }
    PersistSettings setting = new PersistSettings();
    setting.putFirstTimeNativeSyncComplete(value);
    ServiceStatus status = mDb.setOption(setting);
    if (ServiceStatus.SUCCESS == status) {
        mFirstTimeNativeSyncComplete = value;
    }
    return status;
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 17 with Flag

use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.

the class PeopleContactsApi method getContact.

/**
     * Gets a contact from its native id.
     * 
     * @param nativeId the native id of the contact
     * @return an array of ContactChange representing the contact, null if not found
     */
public ContactChange[] getContact(long nativeId) {
    try {
        final SQLiteDatabase readableDb = mDbh.getReadableDatabase();
        if (NativeChangeLogTable.isContactChangeInList(nativeId, ContactChangeType.DELETE_CONTACT, readableDb)) {
            // the contact exists as a deleted contact in the NativeChangeLogTable
            // return one ContactChange with the deleted contact flag
            ContactChange[] changes = new ContactChange[1];
            changes[0] = new ContactChange(ContactChange.TYPE_DELETE_CONTACT);
            return changes;
        } else {
            // get the corresponding local contact id
            final ContactIdInfo info = ContactsTable.fetchContactIdFromNative((int) nativeId, readableDb);
            if (info != null) {
                // we found the contact on CAB, let's get the details
                final ContactChange[] existingDetails = ContactDetailsTable.getContactChanges((long) info.localId, false, readableDb);
                // get also the deleted details if any
                final ContactChange[] deletedDetails = NativeChangeLogTable.getDeletedDetails((long) info.localId, readableDb);
                if (existingDetails != null && deletedDetails != null) {
                    // merge both arrays
                    ContactChange[] mergedDetails = new ContactChange[existingDetails.length + deletedDetails.length];
                    System.arraycopy(existingDetails, 0, mergedDetails, 0, existingDetails.length);
                    System.arraycopy(deletedDetails, 0, mergedDetails, existingDetails.length, deletedDetails.length);
                    return mergedDetails;
                } else if (existingDetails != null) {
                    return existingDetails;
                } else {
                    return deletedDetails;
                }
            }
        }
    } catch (Exception e) {
        LogUtils.logE("getContact(" + nativeId + "), error: " + e);
    }
    // no contact found
    return null;
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 18 with Flag

use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.

the class DatabaseHelper method convertContactChange.

/**
     * Converts a ContactChange object into an equivalent ContactDetail object.
     * 
     * @see ContactChange
     * @see ContactDetail
     * @param change the ContactChange to convert
     * @return the equivalent ContactDetail
     */
public ContactDetail convertContactChange(ContactChange change) {
    final ContactDetail detail = new ContactDetail();
    final int flag = change.getFlags();
    // conversion is not straightforward, needs a little tweak
    final int key = ContactDetailsTable.mapContactChangeKeyToInternalKey(change.getKey());
    detail.localContactID = change.getInternalContactId() != ContactChange.INVALID_ID ? change.getInternalContactId() : null;
    detail.localDetailID = change.getInternalDetailId() != ContactChange.INVALID_ID ? change.getInternalDetailId() : null;
    detail.nativeContactId = change.getNabContactId() != ContactChange.INVALID_ID ? new Integer((int) change.getNabContactId()) : null;
    detail.nativeDetailId = change.getNabDetailId() != ContactChange.INVALID_ID ? new Integer((int) change.getNabDetailId()) : null;
    detail.unique_id = change.getBackendDetailId() != ContactChange.INVALID_ID ? new Long(change.getBackendDetailId()) : null;
    detail.key = DetailKeys.values()[key];
    detail.keyType = DetailKeyTypes.values()[ContactDetailsTable.mapContactChangeFlagToInternalType(flag)];
    detail.value = change.getValue();
    detail.order = ContactDetailsTable.mapContactChangeFlagToInternalOrder(flag);
    return detail;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail)

Example 19 with Flag

use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.

the class DatabaseHelper method modifyPictureLoadedFlag.

/**
     * Sets the picture loaded flag and fires a databaseChanged event.
     * 
     * @param localContactId Local contact id of the contact where to set the
     *            flag
     * @param value Value of the flag
     * @return true in case everything went fine, false otherwise
     */
public final boolean modifyPictureLoadedFlag(final Long localContactId, final Boolean value) {
    ServiceStatus serviceStatus = ContactSummaryTable.modifyPictureLoadedFlag(localContactId, value, getWritableDatabase());
    if (ServiceStatus.SUCCESS != serviceStatus) {
        return false;
    }
    fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, true);
    return true;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 20 with Flag

use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.

the class ContactChangeHelper method randomContactUpdate.

public static ContactChange[] randomContactUpdate(ContactChange[] contact) {
    final int originalDetailsNum = contact.length;
    final long internalCntId = contact[0].getInternalContactId();
    final long backendCntId = contact[0].getBackendContactId();
    final long nabCntId = contact[0].getNabContactId();
    int numDeletedDetails = 0, curNumDeletedDetails = 0, numAddedDetails = 0, curNumAddedDetails = 0, numChangedDetails = 0, curNumChangedDetails = 0;
    // At best we can only delete all but one detail
    numDeletedDetails = randomPositiveInt(originalDetailsNum - 1);
    // At best we can only change all details minus the ones we will delete
    numChangedDetails = randomPositiveInt(originalDetailsNum - numDeletedDetails);
    // Reasonable maximum of details we can add
    numAddedDetails = randomPositiveInt(MAX_NUM_DETAILS_ADD);
    final int updateCcListSize = numAddedDetails + numChangedDetails + numDeletedDetails;
    ContactChange[] updateCcList = new ContactChange[updateCcListSize];
    for (int i = 0; i < updateCcListSize; i++) {
        if (curNumChangedDetails < numChangedDetails) {
            updateCcList[i] = generateUpdateDetailChange(contact[i]);
            curNumChangedDetails++;
            continue;
        }
        if (curNumDeletedDetails < numDeletedDetails) {
            updateCcList[i] = generateDeleteDetailChange(contact[i]);
            curNumDeletedDetails++;
            continue;
        }
        if (curNumAddedDetails < numAddedDetails) {
            int key;
            do {
                // get a random key and don't let it be a unique key to simplify things
                key = randomKey();
                if (isKeyPlatformSupported(key)) {
                    if (!isUniqueKeyForContact(key) || (isUniqueKeyForContact(key) && !isKeyPresent(key, updateCcList) && !isKeyPresent(key, contact))) {
                        break;
                    }
                }
            } while (true);
            // The new detail, preferred flag not allowed to simplify things a little
            final ContactChange addDetailCc = randomContactChange(key, internalCntId, backendCntId, nabCntId, false);
            //addDetailCc.setInternalDetailId(randomPositiveLong());
            addDetailCc.setType(ContactChange.TYPE_ADD_DETAIL);
            updateCcList[i] = addDetailCc;
            curNumAddedDetails++;
        }
    }
    return updateCcList;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)9 ArrayList (java.util.ArrayList)6 PersistSettings (com.vodafone360.people.service.PersistSettings)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)3 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)3 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)3 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 Flag (com.vodafone360.people.datatypes.ActivityItem.Flag)2 Visibility (com.vodafone360.people.datatypes.ActivityItem.Visibility)2 PeopleContactsApi (com.vodafone360.people.engine.contactsync.PeopleContactsApi)2 SQLException (android.database.SQLException)1 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)1 NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)1 DecoderThread (com.vodafone360.people.service.transport.DecoderThread)1 HttpConnectionThread (com.vodafone360.people.service.transport.http.HttpConnectionThread)1