use of com.uwetrottmann.trakt5.entities.MovieCheckin in project SeriesGuide by UweTrottmann.
the class TraktTask method doCheckInAction.
private TraktResponse doCheckInAction() {
try {
retrofit2.Response response;
String message = mArgs.getString(InitBundle.MESSAGE);
switch(mAction) {
case CHECKIN_EPISODE:
{
int episodeTvdbId = mArgs.getInt(InitBundle.EPISODE_TVDBID);
EpisodeCheckin checkin = new EpisodeCheckin.Builder(new SyncEpisode().id(EpisodeIds.tvdb(episodeTvdbId)), APP_VERSION, null).message(message).build();
response = traktCheckin.get().checkin(checkin).execute();
break;
}
case CHECKIN_MOVIE:
{
int movieTmdbId = mArgs.getInt(InitBundle.MOVIE_TMDB_ID);
MovieCheckin checkin = new MovieCheckin.Builder(new SyncMovie().id(MovieIds.tmdb(movieTmdbId)), APP_VERSION, null).message(message).build();
response = traktCheckin.get().checkin(checkin).execute();
break;
}
default:
throw new IllegalArgumentException("check-in action unknown.");
}
if (response.isSuccessful()) {
return new TraktResponse(true, mContext.getString(R.string.checkin_success_trakt, mArgs.getString(InitBundle.TITLE)));
} else {
// check if the user wants to check-in, but there is already a check-in in progress
CheckinError checkinError = trakt.get().checkForCheckinError(response);
if (checkinError != null) {
DateTime expiresAt = checkinError.expires_at;
int waitTimeMin = expiresAt == null ? -1 : (int) ((expiresAt.getMillis() - System.currentTimeMillis()) / 1000);
return new CheckinBlockedResponse(waitTimeMin);
} else // check if item does not exist on trakt (yet)
if (response.code() == 404) {
return new TraktResponse(false, mContext.getString(R.string.trakt_error_not_exists));
} else if (SgTrakt.isUnauthorized(mContext, response)) {
return new TraktResponse(false, mContext.getString(R.string.trakt_error_credentials));
} else {
SgTrakt.trackFailedRequest(mContext, "check-in", response);
}
}
} catch (IOException e) {
SgTrakt.trackFailedRequest(mContext, "check-in", e);
}
// return generic failure message
return buildErrorResponse();
}
Aggregations