Search in sources :

Example 1 with Name

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

the class DatabaseHelper method addContactDetail.

/***
     * Adds a contact detail to the database and fires an internal database
     * change event.
     * 
     * @param detail A {@link ContactDetail} object which contains the detail to
     *            add
     * @return SUCCESS or a suitable error code
     * @see #modifyContactDetail(ContactDetail)
     * @see #deleteContactDetail(long)
     * @see #addContact(Contact)
     * @see #deleteContact(long)
     * @see #addContactToGroup(long, long)
     * @see #deleteContactFromGroup(long, long)
     * @throws NullPointerException When detail is NULL
     */
public ServiceStatus addContactDetail(ContactDetail detail) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.addContactDetail() name[" + detail.getName() + "]");
    }
    if (detail == null) {
        throw new NullPointerException("DatabaseHelper.addContactDetail() detail should not be NULL");
    }
    boolean isMeProfile = (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && detail.localContactID != null && detail.localContactID.equals(SyncMeDbUtils.getMeProfileLocalContactId(this)));
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    detailList.add(detail);
    ServiceStatus status = syncAddContactDetailList(detailList, !isMeProfile, !isMeProfile);
    if (status == ServiceStatus.SUCCESS) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
        if (isMeProfile) {
            WidgetUtils.kickWidgetUpdateNow(mContext);
        }
    }
    return status;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList)

Example 2 with Name

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

the class DatabaseHelper method modifyContactDetail.

/***
     * Modifies an existing contact detail in the database. Also fires an
     * internal database change event.
     * 
     * @param detail A {@link ContactDetail} object which contains the detail to add    
     *         
     * @return SUCCESS or a suitable error code
     * @see #addContactDetail(ContactDetail)
     * @see #deleteContactDetail(long)
     * @see #addContact(Contact)
     * @see #deleteContact(long)
     * @see #addContactToGroup(long, long)
     * @see #deleteContactFromGroup(long, long)
     */
public ServiceStatus modifyContactDetail(ContactDetail detail) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.modifyContactDetail() name[" + detail.getName() + "]");
    }
    boolean isMeProfile = SyncMeDbUtils.isMeProfile(this, detail.localContactID);
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    detailList.add(detail);
    ServiceStatus status = syncModifyContactDetailList(detailList, !isMeProfile, !isMeProfile);
    if (ServiceStatus.SUCCESS == status) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
        if (isMeProfile) {
            WidgetUtils.kickWidgetUpdateNow(mContext);
        }
    }
    return status;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList)

Example 3 with Name

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

the class DatabaseHelper method syncAddContactList.

/***
     * Function used by the contact sync engine to add a list of contacts to the
     * database.
     * 
     * @param contactList The list of contacts received from the server
     * @param syncToServer true if the contacts need to be sent to the server
     * @param syncToNative true if the contacts need to be added to the native
     *            phonebook
     * @return SUCCESS or a suitable error code
     * @see #addContact(Contact)
     */
public ServiceStatus syncAddContactList(List<Contact> contactList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncAddContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase writableDb = getWritableDatabase();
    boolean needFireDbUpdate = false;
    for (Contact contact : contactList) {
        contact.deleted = null;
        contact.localContactID = null;
        if (syncToNative) {
            contact.nativeContactId = null;
        }
        if (syncToServer) {
            contact.contactID = null;
            contact.updated = null;
            contact.synctophone = true;
        }
        try {
            writableDb.beginTransaction();
            ServiceStatus status = ContactsTable.addContact(contact, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                LogUtils.logE("DatabaseHelper.syncAddContactList() Unable to add contact to contacts table, due to a database error");
                return status;
            }
            List<ContactDetail.DetailKeys> orderList = new ArrayList<ContactDetail.DetailKeys>();
            for (int i = 0; i < contact.details.size(); i++) {
                final ContactDetail detail = contact.details.get(i);
                detail.localContactID = contact.localContactID;
                detail.localDetailID = null;
                if (syncToServer) {
                    detail.unique_id = null;
                }
                if (detail.order != null && (detail.order.equals(ContactDetail.ORDER_PREFERRED))) {
                    if (orderList.contains(detail.key)) {
                        detail.order = ContactDetail.ORDER_NORMAL;
                    } else {
                        orderList.add(detail.key);
                    }
                }
                status = ContactDetailsTable.addContactDetail(detail, syncToServer, (syncToNative && contact.synctophone), writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    LogUtils.logE("DatabaseHelper.syncAddContactList() Unable to add contact detail (for new contact), " + "due to a database error. Contact ID[" + contact.localContactID + "]");
                    return status;
                }
            }
            // details are not stored
            if (!contact.details.isEmpty()) {
                status = ContactSummaryTable.addContact(contact, writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    return status;
                }
            }
            if (contact.groupList != null) {
                for (Long groupId : contact.groupList) {
                    if (groupId != -1 && !ContactGroupsTable.addContactToGroup(contact.localContactID, groupId, writableDb)) {
                        return ServiceStatus.ERROR_DATABASE_CORRUPT;
                    }
                }
            }
            if (contact.sources != null) {
                for (String source : contact.sources) {
                    if (!ContactSourceTable.addContactSource(contact.localContactID, source, writableDb)) {
                        return ServiceStatus.ERROR_DATABASE_CORRUPT;
                    }
                }
            }
            if (syncToServer) {
                if (contact.groupList != null) {
                    for (Long groupId : contact.groupList) {
                        if (!ContactChangeLogTable.addGroupRel(contact.localContactID, contact.contactID, groupId, writableDb)) {
                            return ServiceStatus.ERROR_DATABASE_CORRUPT;
                        }
                    }
                }
            }
            /*
                 * FIXME: Hacking a check for me profile here using syncToNative and syncToServer
                 * The me contact does not use a static local contact id 
                 * which is ridiculous. Basically we have to check the syncToNative and syncToServer
                 * flags together with isMeProfile
                 * because luckily as of yet the they are only both false when its me profile 
                 * in case that's the contact being added.
                 */
            String displayName = updateContactNameInSummary(writableDb, contact.localContactID, (!syncToNative && !syncToServer) || SyncMeDbUtils.isMeProfile(this, contact.localContactID));
            if (null == displayName) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            // updating timeline
            for (ContactDetail detail : contact.details) {
                // we already have name, don't need to get it again
                if (detail.key != ContactDetail.DetailKeys.VCARD_NAME) {
                    detail.localContactID = contact.localContactID;
                    detail.nativeContactId = contact.nativeContactId;
                    if (updateTimelineNames(detail, displayName, contact.contactID, writableDb)) {
                        needFireDbUpdate = true;
                    }
                }
            }
            writableDb.setTransactionSuccessful();
        } finally {
            writableDb.endTransaction();
        }
    }
    if (needFireDbUpdate) {
        fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) DetailKeys(com.vodafone360.people.datatypes.ContactDetail.DetailKeys) Contact(com.vodafone360.people.datatypes.Contact)

Example 4 with Name

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

the class DatabaseHelper method updateTimelineNames.

/**
     * Updates the contents of the activities table when a contact detail
     * changes.
     * 
     * @param cd The new or modified contact detail
     * @param contactFriendlyName Name of contact (if known)
     * @param serverId if known
     * @param db Writable SQLite database for the update
     * @return true if the Activities table was updated, false otherwise
     */
private boolean updateTimelineNames(ContactDetail cd, String contactFriendlyName, Long serverId, SQLiteDatabase db) {
    if (cd.key == ContactDetail.DetailKeys.VCARD_NAME) {
        if (contactFriendlyName != null) {
            ActivitiesTable.updateTimelineContactNameAndId(contactFriendlyName, cd.localContactID, db);
            return true;
        }
    }
    if (cd.key == ContactDetail.DetailKeys.VCARD_PHONE) {
        if (contactFriendlyName == null) {
            ContactSummary cs = new ContactSummary();
            if (ContactSummaryTable.fetchSummaryItem(cd.localContactID, cs, db) == ServiceStatus.SUCCESS) {
                contactFriendlyName = cs.formattedName;
            }
        }
        if (contactFriendlyName != null) {
            Long cId = serverId;
            if (cId == null) {
                cId = ContactsTable.fetchServerId(cd.localContactID, db);
            }
            ActivitiesTable.updateTimelineContactNameAndId(cd.getTel(), contactFriendlyName, cd.localContactID, cId, db);
            return true;
        } else {
            LogUtils.logE("updateTimelineNames() failed to fetch summary Item");
        }
    }
    return false;
}
Also used : ContactSummary(com.vodafone360.people.datatypes.ContactSummary)

Example 5 with Name

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

the class DatabaseHelper method updateContactNameInSummary.

/**
     * Updates the ContactSummary table with the new/changed Contact.
     * @param writableDatabase - SQLiteDatabase writable database.
     * @param localContactId - long contact local id.
     * @param isMeProfile - boolean that indicates if the localContactId belongs to Me Profile.
	 * @return The updated name, may be null in failure situations
     */
public String updateContactNameInSummary(SQLiteDatabase writableDatabase, long localContactId, boolean isMeProfile) {
    Contact contact = new Contact();
    ServiceStatus status = fetchBaseContact(localContactId, contact, writableDatabase);
    if (ServiceStatus.SUCCESS != status) {
        return null;
    }
    status = ContactDetailsTable.fetchContactDetails(localContactId, contact.details, writableDatabase);
    if (ServiceStatus.SUCCESS != status) {
        return null;
    }
    return ContactSummaryTable.updateContactDisplayName(contact, writableDatabase, isMeProfile);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact)

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