Search in sources :

Example 1 with HexagonTools

use of com.battlelancer.seriesguide.backend.HexagonTools in project SeriesGuide by UweTrottmann.

the class AddListTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    String listId = getListId();
    if (isSendingToHexagon()) {
        HexagonTools hexagonTools = SgApp.getServicesComponent(getContext()).hexagonTools();
        Lists listsService = hexagonTools.getListsService();
        if (listsService == null) {
            // no longer signed in
            return ERROR_HEXAGON_API;
        }
        // send list to be added to hexagon
        SgListList wrapper = new SgListList();
        List<SgList> lists = buildList(listId, listName);
        wrapper.setLists(lists);
        try {
            listsService.save(wrapper).execute();
        } catch (IOException e) {
            Errors.logAndReportHexagon("add list", e);
            return ERROR_HEXAGON_API;
        }
    }
    // update local state
    if (!doDatabaseUpdate(getContext().getContentResolver(), listId)) {
        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 2 with HexagonTools

use of com.battlelancer.seriesguide.backend.HexagonTools in project SeriesGuide by UweTrottmann.

the class RemoveListTask 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;
        }
        // send list to be removed from hexagon
        try {
            listsService.remove(listId).execute();
        } catch (IOException e) {
            Errors.logAndReportHexagon("remove list", e);
            return ERROR_HEXAGON_API;
        }
    }
    // update local state
    if (!doDatabaseUpdate()) {
        return ERROR_DATABASE;
    }
    return SUCCESS;
}
Also used : Lists(com.uwetrottmann.seriesguide.backend.lists.Lists) HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) IOException(java.io.IOException)

Example 3 with HexagonTools

use of com.battlelancer.seriesguide.backend.HexagonTools in project SeriesGuide by UweTrottmann.

the class ReorderListsTask 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;
        }
        // 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) {
            Errors.logAndReportHexagon("reorder lists", 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 4 with HexagonTools

use of com.battlelancer.seriesguide.backend.HexagonTools in project SeriesGuide by UweTrottmann.

the class NetworkJobProcessor method doNetworkJob.

/**
 * @return true if the job can be removed, false if it should be retried later.
 */
private boolean doNetworkJob(long jobId, JobAction action, long createdAt, SgJobInfo jobInfo) {
    // upload to hexagon
    if (shouldSendToHexagon) {
        if (!AndroidUtils.isNetworkConnected(context)) {
            return false;
        }
        HexagonTools hexagonTools = SgApp.getServicesComponent(context).hexagonTools();
        NetworkJob hexagonJob = getHexagonJobForAction(hexagonTools, action, jobInfo);
        if (hexagonJob != null) {
            JobResult result = hexagonJob.execute(context);
            if (!result.successful) {
                showNotification(jobId, createdAt, result);
                return result.jobRemovable;
            }
        }
    }
    // upload to trakt
    if (shouldSendToTrakt) {
        if (!AndroidUtils.isNetworkConnected(context)) {
            return false;
        }
        NetworkJob traktJob = getTraktJobForAction(action, jobInfo, createdAt);
        if (traktJob != null) {
            JobResult result = traktJob.execute(context);
            // may need to show notification if successful (for not found error)
            showNotification(jobId, createdAt, result);
            if (!result.successful) {
                return result.jobRemovable;
            }
        }
    }
    return true;
}
Also used : HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) NetworkJob(com.battlelancer.seriesguide.jobs.NetworkJob)

Example 5 with HexagonTools

use of com.battlelancer.seriesguide.backend.HexagonTools in project SeriesGuide by UweTrottmann.

the class BaseTopActivity method onShowCloudAccountWarning.

protected void onShowCloudAccountWarning() {
    if (snackbar != null && snackbar.isShown()) {
        Timber.d("NOT showing Cloud account warning: existing snackbar.");
        return;
    }
    Snackbar newSnackbar = Snackbar.make(getSnackbarParentView(), R.string.hexagon_signed_out, Snackbar.LENGTH_INDEFINITE);
    newSnackbar.addCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            if (event == Snackbar.Callback.DISMISS_EVENT_SWIPE) {
                // user has dismissed warning, so disable Cloud
                HexagonTools hexagonTools = SgApp.getServicesComponent(BaseTopActivity.this).hexagonTools();
                hexagonTools.removeAccountAndSetDisabled();
            }
        }
    }).setAction(R.string.hexagon_signin, v -> {
        // forward to cloud setup which can help fix the account issue
        startActivity(new Intent(BaseTopActivity.this, CloudSetupActivity.class));
    }).show();
    snackbar = newSnackbar;
}
Also used : Utils(com.battlelancer.seriesguide.util.Utils) SgApp(com.battlelancer.seriesguide.SgApp) CloudSetupActivity(com.battlelancer.seriesguide.backend.CloudSetupActivity) Intent(android.content.Intent) StatsActivity(com.battlelancer.seriesguide.ui.stats.StatsActivity) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) ActionBar(androidx.appcompat.app.ActionBar) BuildConfig(com.battlelancer.seriesguide.BuildConfig) ContentResolver(android.content.ContentResolver) AccountUtils(com.battlelancer.seriesguide.sync.AccountUtils) SyncStatusObserver(android.content.SyncStatusObserver) Menu(android.view.Menu) BackupSettings(com.battlelancer.seriesguide.dataliberation.BackupSettings) View(android.view.View) HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) HexagonSettings(com.battlelancer.seriesguide.backend.settings.HexagonSettings) SupportTheDev(com.battlelancer.seriesguide.util.SupportTheDev) Account(android.accounts.Account) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) Timber(timber.log.Timber) IdRes(androidx.annotation.IdRes) TextView(android.widget.TextView) MoreOptionsActivity(com.battlelancer.seriesguide.ui.preferences.MoreOptionsActivity) R(com.battlelancer.seriesguide.R) Snackbar(com.google.android.material.snackbar.Snackbar) DataLiberationActivity(com.battlelancer.seriesguide.dataliberation.DataLiberationActivity) HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) Intent(android.content.Intent) Snackbar(com.google.android.material.snackbar.Snackbar)

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