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;
}
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;
}
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;
}
Aggregations