use of com.battlelancer.seriesguide.backend.HexagonTools 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;
}
use of com.battlelancer.seriesguide.backend.HexagonTools 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;
}
Aggregations