Search in sources :

Example 6 with Lists

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

the class RemoveListItemTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    if (isSendingToHexagon()) {
        Lists listsService = getContext().getHexagonTools().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) {
            HexagonTools.trackFailedRequest(getContext(), "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) IOException(java.io.IOException)

Example 7 with Lists

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

the class ChangeListItemListsTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    if (isSendingToHexagon()) {
        Lists listsService = getContext().getHexagonTools().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) {
                HexagonTools.trackFailedRequest(getContext(), "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) {
                HexagonTools.trackFailedRequest(getContext(), "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) IOException(java.io.IOException)

Aggregations

Lists (com.uwetrottmann.seriesguide.backend.lists.Lists)7 IOException (java.io.IOException)6 SgList (com.uwetrottmann.seriesguide.backend.lists.model.SgList)5 SgListList (com.uwetrottmann.seriesguide.backend.lists.model.SgListList)5 SuppressLint (android.annotation.SuppressLint)1 ContentProviderOperation (android.content.ContentProviderOperation)1 OperationApplicationException (android.content.OperationApplicationException)1 Nullable (android.support.annotation.Nullable)1 GoogleAccountCredential (com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential)1 DateTime (com.google.api.client.util.DateTime)1 SgListIds (com.uwetrottmann.seriesguide.backend.lists.model.SgListIds)1 ArrayList (java.util.ArrayList)1