Search in sources :

Example 96 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class ContactSummaryTable method addContact.

/**
 * Adds contact summary information to the table for a new contact. If the
 * contact has no name or no status, an alternative detail will be used such
 * as telephone number or email address.
 *
 * @param contact The new contact
 * @param writableDb Writable SQLite database
 * @return SUCCESS or a suitable error code
 */
public static ServiceStatus addContact(Contact contact, SQLiteDatabase writableDb) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        DatabaseHelper.trace(true, "ContactSummeryTable.addContact() contactID[" + contact.contactID + "]");
    }
    if (contact.localContactID == null) {
        LogUtils.logE("ContactSummeryTable.addContact() Invalid parameters");
        return ServiceStatus.ERROR_NOT_FOUND;
    }
    try {
        final ContentValues values = new ContentValues();
        values.put(Field.LOCALCONTACTID.toString(), contact.localContactID);
        values.put(Field.NATIVEID.toString(), contact.nativeContactId);
        values.put(Field.FRIENDOFMINE.toString(), contact.friendOfMine);
        values.put(Field.SYNCTOPHONE.toString(), contact.synctophone);
        ContactDetail altDetail = findAlternativeNameContactDetail(values, contact.details);
        updateAltValues(values, altDetail);
        addToPresenceMap(contact.localContactID);
        if (writableDb.insertOrThrow(TABLE_NAME, null, values) < 0) {
            LogUtils.logE("ContactSummeryTable.addContact() " + "Unable to insert new contact summary");
            return ServiceStatus.ERROR_NOT_FOUND;
        }
        return ServiceStatus.SUCCESS;
    } catch (SQLException e) {
        LogUtils.logE("ContactSummeryTable.addContact() SQLException - " + "Unable to insert new contact summary", e);
        return ServiceStatus.ERROR_DATABASE_CORRUPT;
    }
}
Also used : ContentValues(android.content.ContentValues) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLException(android.database.SQLException)

Example 97 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class GroupsTable method populateSystemGroups.

/**
 * Populates the table if system groups that are specified in the resources.
 *
 * @param context The context for reading the app resources
 * @param writableDb Writable SQLite database for updating the table
 * @return SUCCESS or a suitable error code
 */
public static ServiceStatus populateSystemGroups(Context context, SQLiteDatabase writableDb) {
    final List<GroupItem> groupList = new ArrayList<GroupItem>();
    GroupItem all = new GroupItem();
    all.mName = context.getString(R.string.ContactListActivity_group_all);
    all.mIsReadOnly = true;
    all.mId = GROUP_ALL;
    groupList.add(all);
    GroupItem online = new GroupItem();
    online.mName = context.getString(R.string.ContactListActivity_group_online);
    online.mIsReadOnly = true;
    online.mId = GROUP_ONLINE;
    groupList.add(online);
    GroupItem phonebook = new GroupItem();
    phonebook.mName = context.getString(R.string.ContactListActivity_group_phonebook);
    phonebook.mIsReadOnly = true;
    phonebook.mId = GROUP_PHONEBOOK;
    groupList.add(phonebook);
    return addGroupList(groupList, writableDb);
}
Also used : ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 98 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method setFirstTimeSyncComplete.

/**
 * Helper function to update the database when the state of the
 * {@link #mFirstTimeSyncComplete} flag changes.
 *
 * @param value New value to the flag. True indicates that 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 setFirstTimeSyncComplete(boolean value) {
    if (mFirstTimeSyncComplete == value) {
        return ServiceStatus.SUCCESS;
    }
    PersistSettings setting = new PersistSettings();
    setting.putFirstTimeSyncComplete(value);
    ServiceStatus status = mDb.setOption(setting);
    if (ServiceStatus.SUCCESS == status) {
        synchronized (this) {
            mFirstTimeSyncComplete = value;
        }
    }
    return status;
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 99 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method setFirstTimeSyncStarted.

/**
 * Helper function to update the database when the state of the
 * {@link #mFirstTimeSyncStarted} flag changes.
 *
 * @param value New value to the flag. True indicates that first time sync
 *            has been started. 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 setFirstTimeSyncStarted(boolean value) {
    if (mFirstTimeSyncStarted == value) {
        return ServiceStatus.SUCCESS;
    }
    PersistSettings setting = new PersistSettings();
    setting.putFirstTimeSyncStarted(value);
    ServiceStatus status = mDb.setOption(setting);
    if (ServiceStatus.SUCCESS == status) {
        synchronized (this) {
            mFirstTimeSyncStarted = value;
        }
    }
    return status;
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 100 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DownloadServerContacts method deleteContactList.

/**
 * Deletes contacts from the local database based on changes received from
 * the server (listed in the {@link #mDeleteContactList} list).
 *
 * @return true if > 0 contacts were deleted, false otherwise.
 */
private boolean deleteContactList() {
    if (mDeleteContactList.size() == 0) {
        return false;
    }
    LogUtils.logI("DownloadServerContacts.deleteContactList " + mDeleteContactList.size() + " contacts...");
    long startTime = System.nanoTime();
    ServiceStatus status = mDb.syncDeleteContactList(mDeleteContactList, false, true);
    if (ServiceStatus.SUCCESS != status) {
        complete(status);
        return true;
    }
    markDbChanged();
    long timeDiff = System.nanoTime() - startTime;
    mDbSyncTime += timeDiff;
    LogUtils.logI("DownloadServerContacts.deleteContactList - time = " + (timeDiff / NANOSECONDS_IN_MS) + "ms, total = " + (mDbSyncTime / NANOSECONDS_IN_MS) + "ms");
    mDeleteContactList.clear();
    return true;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)190 Contact (com.vodafone360.people.datatypes.Contact)71 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)63 MediumTest (android.test.suitebuilder.annotation.MediumTest)62 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)43 ArrayList (java.util.ArrayList)43 Suppress (android.test.suitebuilder.annotation.Suppress)40 Cursor (android.database.Cursor)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)16 Bundle (android.os.Bundle)12 ContentValues (android.content.ContentValues)11 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)11 SQLException (android.database.SQLException)9 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)9 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)8 LoginDetails (com.vodafone360.people.datatypes.LoginDetails)8 PersistSettings (com.vodafone360.people.service.PersistSettings)8