Search in sources :

Example 76 with ServiceStatus

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

the class ChatDbUtils method fillInContactDetails.

/**
 * Remove hard code
 *
 * @param msg
 * @param item
 * @param databaseHelper
 * @param incoming
 */
private static void fillInContactDetails(ChatMessage msg, TimelineSummaryItem item, DatabaseHelper databaseHelper, TimelineSummaryItem.Type incoming) {
    item.mTimestamp = System.currentTimeMillis();
    // here we set the time stamp back into the chat message
    // in order to be able to remove it from the chat history by time stamp in case its delivery fails
    msg.setTimeStamp(item.mTimestamp);
    item.mType = ActivityItem.Type.MESSAGE_IM_CONVERSATION;
    item.mDescription = msg.getBody();
    item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
    // we store sender's localContactId for incoming msgs and recipient's
    // localContactId for outgoing msgs
    item.mLocalContactId = msg.getLocalContactId();
    if (item.mLocalContactId != null && item.mLocalContactId != -1) {
        ContactDetail cd = ContactDetailsTable.fetchDetail(item.mLocalContactId, DetailKeys.VCARD_NAME, databaseHelper.getReadableDatabase());
        if (cd == null || cd.getName() == null) {
            // if we don't get any details, we have to check the summary
            // table because gtalk contacts
            // without name will be otherwise show as unknown
            ContactSummary contactSummary = new ContactSummary();
            ServiceStatus error = ContactSummaryTable.fetchSummaryItem(item.mLocalContactId, contactSummary, databaseHelper.getReadableDatabase());
            if (error == ServiceStatus.SUCCESS) {
                item.mContactName = (contactSummary.formattedName != null) ? contactSummary.formattedName : ContactDetail.UNKNOWN_NAME;
            } else {
                item.mContactName = ContactDetail.UNKNOWN_NAME;
            }
        } else {
            /**
             * Get name from contact details. *
             */
            VCardHelper.Name name = cd.getName();
            item.mContactName = (name != null) ? name.toString() : ContactDetail.UNKNOWN_NAME;
        }
    }
    item.mIncoming = incoming;
    item.mContactNetwork = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString();
    item.mNativeItemType = TimelineNativeTypes.ChatLog.ordinal();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Date(java.util.Date)

Example 77 with ServiceStatus

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

the class ResponseQueue method addToResponseQueue.

/**
 * Adds a response item to the queue.
 *
 * @param reqId The request ID to add the response for.
 * @param data The response data to add to the queue.
 * @param source The corresponding engine that fired off the request for the
 *            response.
 */
public void addToResponseQueue(final DecodedResponse response) {
    synchronized (QueueManager.getInstance().lock) {
        ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.UNKNOWN_DATA_TYPE, response.mDataTypes);
        if (status == ServiceStatus.ERROR_INVALID_SESSION) {
            EngineManager em = EngineManager.getInstance();
            if (em != null) {
                LogUtils.logE("Logging out the current user because of invalide session");
                em.getLoginEngine().logoutAndRemoveUser();
                return;
            }
        }
        synchronized (mResponses) {
            mResponses.add(response);
        }
        Request request = RequestQueue.getInstance().removeRequest(response.mReqId);
        if (request != null) {
            // we suppose the response being handled by the same engine
            // that issued the request with the given id
            response.mSource = request.mEngineId;
        }
        mEngMgr = EngineManager.getInstance();
        if (mEngMgr != null) {
            mEngMgr.onCommsInMessage(response.mSource);
        }
    }
}
Also used : EngineManager(com.vodafone360.people.engine.EngineManager) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 78 with ServiceStatus

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

the class DatabaseHelper method syncDeleteContactList.

/**
 * Function used by the contact sync engine to delete a list of contacts
 * from the database.
 *
 * @param contactIdList The list of contact IDs received from the server (at
 *            least localId should be set)
 * @param syncToServer true if the contacts need to be deleted from the
 *            server
 * @param syncToNative true if the contacts need to be deleted from the
 *            native phonebook
 * @return SUCCESS or a suitable error code
 * @see #deleteContact(long)
 */
public ServiceStatus syncDeleteContactList(List<ContactsTable.ContactIdInfo> contactIdList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncDeleteContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase writableDb = getWritableDatabase();
    for (ContactsTable.ContactIdInfo contactIdInfo : contactIdList) {
        try {
            writableDb.beginTransaction();
            if (syncToNative && contactIdInfo.mergedLocalId == null) {
                if (!NativeChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.nativeId, writableDb)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (syncToServer) {
                if (!ContactChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.serverId, syncToServer, writableDb)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (!ContactGroupsTable.deleteContact(contactIdInfo.localId, writableDb)) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            if (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && SyncMeDbUtils.getMeProfileLocalContactId(this).longValue() == contactIdInfo.localId) {
                ServiceStatus status = StateTable.modifyMeProfileID(null, writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    return status;
                }
                SyncMeDbUtils.setMeProfileId(null);
                PresenceDbUtils.resetMeProfileIds();
            }
            ServiceStatus status = ContactSummaryTable.deleteContact(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            status = ContactDetailsTable.deleteDetailByContactId(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status && ServiceStatus.ERROR_NOT_FOUND != status) {
                return status;
            }
            status = ContactsTable.deleteContact(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            if (!deleteThumbnail(contactIdInfo.localId))
                LogUtils.logE("Not able to delete thumbnail for: " + contactIdInfo.localId);
            // timeline
            ActivitiesTable.removeTimelineContactData(contactIdInfo.localId, writableDb);
            writableDb.setTransactionSuccessful();
        } finally {
            writableDb.endTransaction();
        }
    }
    return ServiceStatus.SUCCESS;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 79 with ServiceStatus

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

the class DatabaseHelper method deleteTimelineActivity.

/**
 * Removes the selected timeline activity from the database.
 *
 * @param application The MainApplication
 * @param timelineItem TimelineSummaryItem to be deleted
 * @return SUCCESS or a suitable error code
 */
public ServiceStatus deleteTimelineActivity(MainApplication application, TimelineSummaryItem timelineItem, boolean isTimelineAll) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.deleteTimelineActivity()");
    ServiceStatus status = ServiceStatus.SUCCESS;
    if (isTimelineAll) {
        status = ActivitiesTable.deleteTimelineActivities(mContext, timelineItem, getWritableDatabase(), getReadableDatabase());
    } else {
        status = ActivitiesTable.deleteTimelineActivity(mContext, timelineItem, getWritableDatabase(), getReadableDatabase());
    }
    if (status == ServiceStatus.SUCCESS) {
        // Update Notifications in the Notification Bar
        IPeopleService peopleService = application.getServiceInterface();
        long localContactId = 0L;
        if (timelineItem.mLocalContactId != null) {
            localContactId = timelineItem.mLocalContactId;
        }
        peopleService.updateChatNotification(localContactId);
    }
    fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, true);
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) IPeopleService(com.vodafone360.people.service.interfaces.IPeopleService)

Example 80 with ServiceStatus

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

the class DatabaseHelper method addContact.

/**
 * Adds a contact to the database and fires an internal database change
 * event.
 *
 * @param contact A {@link Contact} object which contains the details to be
 *            added
 * @return SUCCESS or a suitable error code
 * @see #deleteContact(long)
 * @see #addContactDetail(ContactDetail)
 * @see #modifyContactDetail(ContactDetail)
 * @see #deleteContactDetail(long)
 * @see #addContactToGroup(long, long)
 * @see #deleteContactFromGroup(long, long)
 */
public ServiceStatus addContact(Contact contact) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.addContact() contactID[" + contact.contactID + "] nativeContactId[" + contact.nativeContactId + "]");
    }
    List<Contact> contactList = new ArrayList<Contact>();
    contactList.add(contact);
    ServiceStatus status = syncAddContactList(contactList, true, true);
    if (ServiceStatus.SUCCESS == status) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
    }
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

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