Search in sources :

Example 1 with GroupItem

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

the class GroupsTableTest method generateGroupItemList.

private static List<GroupItem> generateGroupItemList() {
    List<GroupItem> groupItemList = new ArrayList<GroupItem>();
    for (int i = 0; i < GROUPS.length; i++) {
        GroupItem groupItem = new GroupItem();
        groupItem.mColor = GROUPS[i][0];
        groupItem.mGroupType = Integer.valueOf(GROUPS[i][1]);
        groupItem.mId = Long.valueOf(GROUPS[i][2]);
        groupItem.mIsReadOnly = Boolean.valueOf(GROUPS[i][3]);
        groupItem.mIsSmartGroup = Boolean.valueOf(GROUPS[i][4]);
        groupItem.mIsSystemGroup = Boolean.valueOf(GROUPS[i][5]);
        groupItem.mRequiresLocalisation = Boolean.valueOf(GROUPS[i][6]);
        groupItem.mName = GROUPS[i][7];
        groupItem.mUserId = Long.valueOf(GROUPS[i][8]);
        groupItemList.add(groupItem);
    }
    return groupItemList;
}
Also used : ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 2 with GroupItem

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

the class GroupsEngine method processCommsResponse.

@Override
protected void processCommsResponse(DecodedResponse resp) {
    LogUtils.logD("DownloadGroups.processCommsResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.ITEM_LIST_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        final List<GroupItem> tempGroupList = new ArrayList<GroupItem>();
        for (int i = 0; i < resp.mDataTypes.size(); i++) {
            ItemList itemList = (ItemList) resp.mDataTypes.get(i);
            if (itemList.mType != ItemList.Type.group_privacy) {
                completeUiRequest(ServiceStatus.ERROR_UNEXPECTED_RESPONSE);
                return;
            }
            // TODO: why cloning the list?
            for (int j = 0; j < itemList.mItemList.size(); j++) {
                tempGroupList.add((GroupItem) itemList.mItemList.get(j));
            }
        }
        LogUtils.logI("DownloadGroups.processCommsResponse() - No of groups " + tempGroupList.size());
        if (mPageNo == 0) {
            // clear old groups if we request the first groups page
            mDb.deleteAllGroups();
        }
        status = GroupsTable.addGroupList(tempGroupList, mDb.getWritableDatabase());
        if (ServiceStatus.SUCCESS != status) {
            completeUiRequest(status);
            return;
        }
        mNoOfGroupsFetched += tempGroupList.size();
        if (tempGroupList.size() < MAX_DOWN_PAGE_SIZE) {
            completeUiRequest(ServiceStatus.SUCCESS);
            return;
        }
        mPageNo++;
        requestNextGroupsPage();
        return;
    }
    LogUtils.logE("DownloadGroups.processCommsResponse() - Error requesting Zyb groups, error = " + status);
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ItemList(com.vodafone360.people.datatypes.ItemList) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 3 with GroupItem

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

the class UploadServerContactsTest method reportBackAddGroupSuccess.

private void reportBackAddGroupSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportBackAddGroupSuccess");
    mProcessor.verifyGroupAddsState();
    final List<Long> contactIdList = new ArrayList<Long>();
    final List<GroupItem> groupList = new ArrayList<GroupItem>();
    mProcessor.testFetchAddGroupLists(contactIdList, groupList);
    assertEquals(1, groupList.size());
    Long activeGroupId = groupList.get(0).mId;
    assertTrue(activeGroupId != null);
    ItemList itemList = new ItemList(ItemList.Type.contact_group_relations);
    data.add(itemList);
    for (Long contactServerId : contactIdList) {
        Contact expectedContact = new Contact();
        ServiceStatus status = mDb.fetchContactByServerId(contactServerId, expectedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        boolean found = false;
        for (Long groupId : expectedContact.groupList) {
            if (groupId.equals(activeGroupId)) {
                found = true;
                break;
            }
        }
        assertTrue("Contact " + contactServerId + " has been added to group " + activeGroupId + " which is not in the database", found);
        mItemCount--;
    }
    Log.i(LOG_TAG, "Groups/contacts remaining = " + mItemCount);
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ItemList(com.vodafone360.people.datatypes.ItemList) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem) Contact(com.vodafone360.people.datatypes.Contact)

Example 4 with GroupItem

use of com.vodafone360.people.datatypes.GroupItem 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 5 with GroupItem

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

the class UploadServerContacts method sendNextAddGroupRelationsPage.

/**
     * Sends next add contact/group relation request to the server. Many
     * contacts can be added by a single request.
     */
private void sendNextAddGroupRelationsPage() {
    ContactChangeInfo info = null;
    mActiveGroupId = null;
    mContactIdList.clear();
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.ADD_GROUP_REL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts." + "sendNextAddGroupRelationsPage() Unable to fetch add " + "group relations from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (groupInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> deleteInfoList = new ArrayList<ContactChangeInfo>();
    for (int i = 0; i < groupInfoList.size(); i++) {
        info = groupInfoList.get(i);
        if (info.mServerContactId == null) {
            info.mServerContactId = mDb.fetchServerId(info.mLocalContactId);
        }
        if (info.mServerContactId != null && info.mGroupOrRelId != null) {
            if (mActiveGroupId == null) {
                mActiveGroupId = info.mGroupOrRelId;
            }
            if (info.mGroupOrRelId.equals(mActiveGroupId)) {
                mContactIdList.add(info.mServerContactId);
                mContactChangeInfoList.add(info);
            }
            continue;
        }
        LogUtils.logE("UploadServerContact.sendNextAddGroupRelationsPage() " + "Invalid add group change: SID = " + info.mServerContactId + ", gid=" + info.mGroupOrRelId);
        deleteInfoList.add(info);
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mActiveGroupId == null) {
        moveToNextState();
        return;
    }
    mGroupList.clear();
    GroupItem group = new GroupItem();
    group.mId = mActiveGroupId;
    mGroupList.add(group);
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mGroupList.size();
    setReqId(GroupPrivacy.addContactGroupRelations(getEngine(), mContactIdList, mGroupList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Aggregations

GroupItem (com.vodafone360.people.datatypes.GroupItem)9 ArrayList (java.util.ArrayList)6 ItemList (com.vodafone360.people.datatypes.ItemList)3 ServiceStatus (com.vodafone360.people.service.ServiceStatus)2 Hashtable (java.util.Hashtable)2 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)1 Contact (com.vodafone360.people.datatypes.Contact)1 QueueManager (com.vodafone360.people.service.io.QueueManager)1 Request (com.vodafone360.people.service.io.Request)1 Vector (java.util.Vector)1