Search in sources :

Example 6 with HexagonTools

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;
}
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 7 with HexagonTools

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

HexagonTools (com.battlelancer.seriesguide.backend.HexagonTools)7 Lists (com.uwetrottmann.seriesguide.backend.lists.Lists)5 IOException (java.io.IOException)5 SgList (com.uwetrottmann.seriesguide.backend.lists.model.SgList)4 SgListList (com.uwetrottmann.seriesguide.backend.lists.model.SgListList)4 Account (android.accounts.Account)1 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1 SyncStatusObserver (android.content.SyncStatusObserver)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AnimationUtils (android.view.animation.AnimationUtils)1 TextView (android.widget.TextView)1 IdRes (androidx.annotation.IdRes)1 ActionBar (androidx.appcompat.app.ActionBar)1 AppCompatDelegate (androidx.appcompat.app.AppCompatDelegate)1 BuildConfig (com.battlelancer.seriesguide.BuildConfig)1 R (com.battlelancer.seriesguide.R)1 SgApp (com.battlelancer.seriesguide.SgApp)1