Search in sources :

Example 21 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class StateTable method fetchOption.

/**
 * Fetches an option from the settings table.
 *
 * @param option Specifies which option is required
 * @param readableDb Readable SQLite database for fetching the information
 * @return A PersistSettings object containing the option data if
 *         successful, null otherwise.
 */
public static PersistSettings fetchOption(final PersistSettings.Option option, final SQLiteDatabase readableDb) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        DatabaseHelper.trace(false, "StateTable.fetchOption() name[" + option.tableFieldName() + "] value[" + option.defaultValue() + "] type[" + option.getType() + "]");
    }
    Cursor c = null;
    try {
        c = readableDb.rawQuery("SELECT " + option.tableFieldName() + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
        if (!c.moveToFirst()) {
            LogUtils.logE("StateTable.fetchOption() Unable to find option " + "in the database, option[" + option + "]");
            return null;
        }
        final PersistSettings setting = new PersistSettings();
        Object data = null;
        if (!c.isNull(0)) {
            data = PersistSettings.fetchValueFromCursor(c, 0, c.getColumnName(0));
        }
        setting.putOptionData(option, data);
        LogUtils.logD("StateTable.fetchOption() Fetched option[" + option + "]");
        return setting;
    } catch (Exception e) {
        LogUtils.logE("StateTable.fetchOption() Exception - Unable to " + "fetch options from database", e);
        return null;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteException(android.database.sqlite.SQLiteException)

Example 22 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class DownloadServerContacts method updateProgressUi.

/**
 * Check the given contact to see if it has a valid name, and if so send it
 * to be shown in the contacts sync progress UI.
 *
 * @param contact Contact which has been downloaded.
 * @param incOfCurrentPage Number of contacts that have so far been
 *            downloaded for the current page.
 */
private void updateProgressUi(Contact contact, int incOfCurrentPage) {
    String name = "";
    if (contact != null) {
        ContactDetail contactDetail = contact.getContactDetail(ContactDetail.DetailKeys.VCARD_NAME);
        if (contactDetail != null) {
            VCardHelper.Name vCardHelperName = contactDetail.getName();
            if (vCardHelperName != null) {
                name = vCardHelperName.toString();
            }
        }
    }
    int totalNumberOfContacts = ((mTotalNoOfPages * 10) - 1) * MAX_DOWN_PAGE_SIZE / 10;
    if (mLastPageSize != -1) {
        totalNumberOfContacts = (mTotalNoOfPages - 1) * MAX_DOWN_PAGE_SIZE + mLastPageSize;
    }
    int progress = (incOfCurrentPage + (mNoOfPagesDone * MAX_DOWN_PAGE_SIZE)) * 100 / totalNumberOfContacts;
    setSyncStatus(new SyncStatus(progress, name, Task.DOWNLOAD_SERVER_CONTACTS, TaskStatus.RECEIVED_CONTACTS, incOfCurrentPage + mNoOfPagesDone * MAX_DOWN_PAGE_SIZE, totalNumberOfContacts));
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) VCardHelper(com.vodafone360.people.datatypes.VCardHelper)

Example 23 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method preprocessContactToAdd.

/**
 * "Pre-processing" of {@link ContactChange} list before it can be added to
 * NAB. This needs to be done because of issues on the 1.X NAB and our CAB
 * In 1.X NAB: Name and Note which are stored differently from other details
 * In our CAB: Organization and Title are separate details contrary to the
 * NAB
 *
 * @param ccList {@link ContactChange} list for the add operation
 */
private void preprocessContactToAdd(ContactChange[] ccList) {
    final int ccListSize = ccList.length;
    boolean nameFound = false, noteFound = false;
    mValues.clear();
    for (int i = 0; i < ccListSize; i++) {
        final ContactChange cc = ccList[i];
        if (cc != null) {
            if (!nameFound && cc.getKey() == ContactChange.KEY_VCARD_NAME) {
                final Name name = VCardHelper.getName(cc.getValue());
                mValues.put(People.NAME, name.toString());
                nameFound = true;
            }
            if (!noteFound && cc.getKey() == ContactChange.KEY_VCARD_NOTE) {
                mValues.put(People.NOTES, cc.getValue());
                noteFound = true;
            }
            if (mMarkedOrganizationIndex < 0 && cc.getKey() == ContactChange.KEY_VCARD_ORG) {
                mMarkedOrganizationIndex = i;
            }
            if (mMarkedTitleIndex < 0 && cc.getKey() == ContactChange.KEY_VCARD_TITLE) {
                mMarkedTitleIndex = i;
            }
        }
    }
}
Also used : Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 24 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method updateDetail.

/**
 * Updates a detail.
 *
 * @param cc {@link ContactChange} to read data from
 * @param nabContactId ID of the NAB Contact
 * @return true if the detail was updated, false if not
 */
private boolean updateDetail(ContactChange cc) {
    mValues.clear();
    Uri contentUri = null;
    long nabDetailId = cc.getNabDetailId();
    final long nabContactId = cc.getNabContactId();
    switch(cc.getKey()) {
        case ContactChange.KEY_VCARD_PHONE:
            putPhoneValues(cc, nabContactId);
            contentUri = Phones.CONTENT_URI;
            break;
        case ContactChange.KEY_VCARD_EMAIL:
            putContactMethodValues(cc, CONTACT_METHODS_KIND_EMAIL, nabContactId);
            contentUri = ContactMethods.CONTENT_URI;
            break;
        case ContactChange.KEY_VCARD_ADDRESS:
            putContactMethodValues(cc, CONTACT_METHODS_KIND_ADDRESS, nabContactId);
            contentUri = ContactMethods.CONTENT_URI;
            break;
        case ContactChange.KEY_VCARD_NAME:
            final Name name = VCardHelper.getName(cc.getValue());
            mValues.put(People.NAME, name.toString());
            contentUri = People.CONTENT_URI;
            nabDetailId = nabContactId;
            break;
        case ContactChange.KEY_VCARD_NOTE:
            mValues.put(People.NOTES, cc.getValue());
            contentUri = People.CONTENT_URI;
            nabDetailId = nabContactId;
            break;
    }
    if (contentUri != null) {
        Uri uri = ContentUris.withAppendedId(contentUri, nabDetailId);
        return mCr.update(uri, mValues, null, null) > 0;
    }
    return false;
}
Also used : Uri(android.net.Uri) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 25 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method getContact.

/**
 * @see NativeContactsApi#getContact(long)
 */
@Override
public ContactChange[] getContact(long nabContactId) {
    final List<ContactChange> ccList = new ArrayList<ContactChange>();
    final Cursor cursor = mCr.query(ContentUris.withAppendedId(People.CONTENT_URI, nabContactId), PEOPLE_PROJECTION, null, null, null);
    try {
        if (cursor.moveToNext()) {
            final String displayName = CursorUtils.getString(cursor, People.NAME);
            if (!TextUtils.isEmpty(displayName)) {
                // TODO: Remove if really not necessary
                // final Name name = parseRawName(displayName);
                final Name name = new Name();
                name.firstname = displayName;
                final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NAME, VCardHelper.makeName(name), ContactChange.FLAG_NONE);
                cc.setNabContactId(nabContactId);
                ccList.add(cc);
            }
            // Note
            final String note = CursorUtils.getString(cursor, People.NOTES);
            if (!TextUtils.isEmpty(note)) {
                final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NOTE, note, ContactChange.FLAG_NONE);
                cc.setNabContactId(nabContactId);
                ccList.add(cc);
            }
            // Remaining contact details
            readContactPhoneNumbers(ccList, nabContactId);
            readContactMethods(ccList, nabContactId);
            readContactOrganizations(ccList, nabContactId);
        }
    } finally {
        CursorUtils.closeCursor(cursor);
    }
    return ccList.toArray(new ContactChange[ccList.size()]);
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Aggregations

ContactDetail (com.vodafone360.people.datatypes.ContactDetail)23 ServiceStatus (com.vodafone360.people.service.ServiceStatus)20 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Cursor (android.database.Cursor)12 Contact (com.vodafone360.people.datatypes.Contact)12 ArrayList (java.util.ArrayList)11 Name (com.vodafone360.people.datatypes.VCardHelper.Name)9 ContentValues (android.content.ContentValues)7 Uri (android.net.Uri)7 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)7 SQLException (android.database.SQLException)6 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)6 QueueManager (com.vodafone360.people.service.io.QueueManager)6 Request (com.vodafone360.people.service.io.Request)6 TimelineSummaryItem (com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)5 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)5 Hashtable (java.util.Hashtable)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Suppress (android.test.suitebuilder.annotation.Suppress)4 Date (java.util.Date)4