use of com.uwetrottmann.seriesguide.backend.lists.model.SgList in project SeriesGuide by UweTrottmann.
the class ReorderListsTask 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;
}
// send lists with updated order to hexagon
SgListList wrapper = new SgListList();
List<SgList> lists = buildListsList(listIdsInOrder);
wrapper.setLists(lists);
try {
listsService.save(wrapper).execute();
} catch (IOException e) {
HexagonTools.trackFailedRequest(getContext(), "reorder lists", e);
return ERROR_HEXAGON_API;
}
}
// update local state
if (!doDatabaseUpdate()) {
return ERROR_DATABASE;
}
return SUCCESS;
}
use of com.uwetrottmann.seriesguide.backend.lists.model.SgList in project SeriesGuide by UweTrottmann.
the class ListsTools method downloadFromHexagon.
@SuppressLint("ApplySharedPref")
public static boolean downloadFromHexagon(SgApp app, boolean hasMergedLists) {
long currentTime = System.currentTimeMillis();
DateTime lastSyncTime = new DateTime(HexagonSettings.getLastListsSyncTime(app));
if (hasMergedLists) {
Timber.d("downloadFromHexagon: downloading lists changed since %s.", lastSyncTime);
} else {
Timber.d("downloadFromHexagon: downloading all lists.");
}
HashSet<String> localListIds = getListIds(app);
List<SgList> lists;
String cursor = null;
do {
try {
Lists listsService = app.getHexagonTools().getListsService();
if (listsService == null) {
// no longer signed in
return false;
}
// use default server limit
Lists.Get request = listsService.get();
if (hasMergedLists) {
request.setUpdatedSince(lastSyncTime);
}
if (!TextUtils.isEmpty(cursor)) {
request.setCursor(cursor);
}
SgListList response = request.execute();
if (response == null) {
Timber.d("downloadFromHexagon: failed, response is null.");
break;
}
cursor = response.getCursor();
lists = response.getLists();
} catch (IOException e) {
HexagonTools.trackFailedRequest(app, "get lists", e);
return false;
}
if (lists == null || lists.size() == 0) {
// empty response, assume we are done
break;
}
if (!doListsDatabaseUpdate(app, lists, localListIds, hasMergedLists)) {
// database update failed, abort
return false;
}
} while (// fetch next batch
!TextUtils.isEmpty(cursor));
// set new last sync time
if (hasMergedLists) {
PreferenceManager.getDefaultSharedPreferences(app).edit().putLong(HexagonSettings.KEY_LAST_SYNC_LISTS, currentTime).commit();
}
return true;
}
use of com.uwetrottmann.seriesguide.backend.lists.model.SgList 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;
}
use of com.uwetrottmann.seriesguide.backend.lists.model.SgList in project SeriesGuide by UweTrottmann.
the class AddListTask method buildList.
@NonNull
private static List<SgList> buildList(@NonNull String listId, @NonNull String listName) {
List<SgList> lists = new ArrayList<>(1);
SgList list = new SgList();
list.setListId(listId);
list.setName(listName);
lists.add(list);
return lists;
}
use of com.uwetrottmann.seriesguide.backend.lists.model.SgList in project SeriesGuide by UweTrottmann.
the class ChangeListItemListsTask method buildListItemLists.
@NonNull
private List<SgList> buildListItemLists(List<String> listsToChange) {
List<SgList> lists = new ArrayList<>(listsToChange.size());
for (String listId : listsToChange) {
SgList list = new SgList();
list.setListId(listId);
lists.add(list);
List<SgListItem> items = new ArrayList<>(1);
list.setListItems(items);
String listItemId = SeriesGuideContract.ListItems.generateListItemId(itemTvdbId, itemType, listId);
SgListItem item = new SgListItem();
items.add(item);
item.setListItemId(listItemId);
}
return lists;
}
Aggregations