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