Search in sources :

Example 6 with SgListList

use of com.uwetrottmann.seriesguide.backend.lists.model.SgListList in project SeriesGuide by UweTrottmann.

the class HexagonListsSync method uploadAll.

public boolean uploadAll() {
    Timber.d("uploadAll");
    SgListList listsWrapper = new SgListList();
    List<SgList> lists = new ArrayList<>(LISTS_MAX_BATCH_SIZE);
    listsWrapper.setLists(lists);
    Cursor listsQuery = context.getContentResolver().query(SeriesGuideContract.Lists.CONTENT_URI, ListsTools.Query.PROJECTION_LIST, null, null, null);
    if (listsQuery == null) {
        // query failed
        return false;
    }
    while (listsQuery.moveToNext()) {
        SgList list = new SgList();
        // add list properties
        String listId = listsQuery.getString(ListsTools.Query.LIST_ID);
        String listName = listsQuery.getString(ListsTools.Query.NAME);
        if (TextUtils.isEmpty(listId)) {
            // skip, no list id
            continue;
        }
        list.setListId(listId);
        list.setName(listName);
        int order = listsQuery.getInt(ListsTools.Query.ORDER);
        if (order != 0) {
            list.setOrder(order);
        }
        // add list items
        List<SgListItem> listItems = ListsTools.getListItems(context, listId);
        if (listItems != null) {
            list.setListItems(listItems);
        } else {
            Timber.d("uploadAll: no items to upload for list %s.", listId);
        }
        lists.add(list);
        if (lists.size() == LISTS_MAX_BATCH_SIZE || listsQuery.isLast()) {
            if (doUploadSomeLists(listsWrapper)) {
                lists.clear();
            } else {
                // part upload failed, next sync will try again
                return false;
            }
        }
    }
    listsQuery.close();
    return true;
}
Also used : SgList(com.uwetrottmann.seriesguide.backend.lists.model.SgList) SgListList(com.uwetrottmann.seriesguide.backend.lists.model.SgListList) SgListItem(com.uwetrottmann.seriesguide.backend.lists.model.SgListItem) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 7 with SgListList

use of com.uwetrottmann.seriesguide.backend.lists.model.SgListList in project SeriesGuide by UweTrottmann.

the class ChangeListItemListsTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    if (isSendingToHexagon()) {
        HexagonTools hexagonTools = SgApp.getServicesComponent(getContext()).hexagonTools();
        Lists listsService = hexagonTools.getListsService();
        if (listsService == null) {
            return ERROR_HEXAGON_API;
        }
        SgListList wrapper = new SgListList();
        if (addToTheseLists.size() > 0) {
            List<SgList> lists = buildListItemLists(addToTheseLists);
            wrapper.setLists(lists);
            try {
                listsService.save(wrapper).execute();
            } catch (IOException e) {
                Errors.logAndReportHexagon("add list items", e);
                return ERROR_HEXAGON_API;
            }
        }
        if (removeFromTheseLists.size() > 0) {
            List<SgList> lists = buildListItemLists(removeFromTheseLists);
            wrapper.setLists(lists);
            try {
                listsService.removeItems(wrapper).execute();
            } catch (IOException e) {
                Errors.logAndReportHexagon("remove list items", e);
                return ERROR_HEXAGON_API;
            }
        }
    }
    // update local state
    if (!doDatabaseUpdate()) {
        return ERROR_DATABASE;
    }
    return SUCCESS;
}
Also used : SgList(com.uwetrottmann.seriesguide.backend.lists.model.SgList) SgListList(com.uwetrottmann.seriesguide.backend.lists.model.SgListList) Lists(com.uwetrottmann.seriesguide.backend.lists.Lists) HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) IOException(java.io.IOException)

Example 8 with SgListList

use of com.uwetrottmann.seriesguide.backend.lists.model.SgListList in project SeriesGuide by UweTrottmann.

the class RemoveListItemTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    if (isSendingToHexagon()) {
        HexagonTools hexagonTools = SgApp.getServicesComponent(getContext()).hexagonTools();
        Lists listsService = hexagonTools.getListsService();
        if (listsService == null) {
            // no longer signed in
            return ERROR_HEXAGON_API;
        }
        // extract the list id of this list item
        String[] splitListItemId = SeriesGuideContract.ListItems.splitListItemId(listItemId);
        if (splitListItemId == null) {
            return ERROR_DATABASE;
        }
        String removeFromListId = splitListItemId[2];
        // send the item to be removed from hexagon
        SgListList wrapper = new SgListList();
        List<SgList> lists = buildListItemLists(removeFromListId, listItemId);
        wrapper.setLists(lists);
        try {
            listsService.removeItems(wrapper).execute();
        } catch (IOException e) {
            Errors.logAndReportHexagon("remove list item", e);
            return ERROR_HEXAGON_API;
        }
    }
    // update local state
    if (!doDatabaseUpdate()) {
        return ERROR_DATABASE;
    }
    return SUCCESS;
}
Also used : SgList(com.uwetrottmann.seriesguide.backend.lists.model.SgList) SgListList(com.uwetrottmann.seriesguide.backend.lists.model.SgListList) Lists(com.uwetrottmann.seriesguide.backend.lists.Lists) HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) IOException(java.io.IOException)

Aggregations

SgList (com.uwetrottmann.seriesguide.backend.lists.model.SgList)8 SgListList (com.uwetrottmann.seriesguide.backend.lists.model.SgListList)8 Lists (com.uwetrottmann.seriesguide.backend.lists.Lists)6 IOException (java.io.IOException)6 HexagonTools (com.battlelancer.seriesguide.backend.HexagonTools)4 SuppressLint (android.annotation.SuppressLint)2 Cursor (android.database.Cursor)2 DateTime (com.google.api.client.util.DateTime)2 SgListItem (com.uwetrottmann.seriesguide.backend.lists.model.SgListItem)2 ArrayList (java.util.ArrayList)2