use of com.battlelancer.seriesguide.util.TraktTask in project SeriesGuide by UweTrottmann.
the class TraktCommentsFragment method comment.
private void comment() {
// prevent empty comments
String comment = editTextShout.getText().toString();
if (TextUtils.isEmpty(comment)) {
return;
}
// disable the comment button
buttonShout.setEnabled(false);
Bundle args = getArguments();
boolean isSpoiler = checkBoxIsSpoiler.isChecked();
// as determined by "science", episode comments are most likely, so check for them first
// comment for an episode?
int episodeTvdbId = args.getInt(InitBundle.EPISODE_TVDB_ID);
if (episodeTvdbId != 0) {
AsyncTaskCompat.executeParallel(new TraktTask(getActivity()).commentEpisode(episodeTvdbId, comment, isSpoiler));
return;
}
// comment for a movie?
int movieTmdbId = args.getInt(InitBundle.MOVIE_TMDB_ID);
if (movieTmdbId != 0) {
AsyncTaskCompat.executeParallel(new TraktTask(getActivity()).commentMovie(movieTmdbId, comment, isSpoiler));
return;
}
// comment for a show?
int showTvdbId = args.getInt(InitBundle.SHOW_TVDB_ID);
if (showTvdbId != 0) {
AsyncTaskCompat.executeParallel(new TraktTask(getActivity()).commentShow(showTvdbId, comment, isSpoiler));
}
// if all ids were 0, do nothing
Timber.e("comment: did nothing, all possible ids were 0");
}
use of com.battlelancer.seriesguide.util.TraktTask in project SeriesGuide by UweTrottmann.
the class TraktCancelCheckinDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity().getApplicationContext();
final Bundle args = getArguments();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(context.getString(R.string.traktcheckin_inprogress, mWait < 0 ? context.getString(R.string.not_available) : DateUtils.formatElapsedTime(mWait)));
final SgApp app = SgApp.from(getActivity());
builder.setPositiveButton(R.string.traktcheckin_cancel, new OnClickListener() {
@Override
@SuppressLint("CommitTransaction")
public void onClick(DialogInterface dialog, int which) {
AsyncTask<String, Void, String> cancelCheckinTask = new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
// check for credentials
if (!TraktCredentials.get(context).hasCredentials()) {
return context.getString(R.string.trakt_error_credentials);
}
try {
retrofit2.Response<Void> response = traktCheckin.get().deleteActiveCheckin().execute();
if (response.isSuccessful()) {
return null;
} else {
if (SgTrakt.isUnauthorized(context, response)) {
return context.getString(R.string.trakt_error_credentials);
}
SgTrakt.trackFailedRequest(context, "delete check-in", response);
}
} catch (IOException e) {
SgTrakt.trackFailedRequest(context, "delete check-in", e);
}
return context.getString(R.string.api_error_generic, context.getString(R.string.trakt));
}
@Override
protected void onPostExecute(String message) {
if (message == null) {
// all good
Toast.makeText(context, R.string.checkin_canceled_success_trakt, Toast.LENGTH_SHORT).show();
// relaunch the trakt task which called us to
// try the check in again
AsyncTaskCompat.executeParallel(new TraktTask(app, args));
} else {
// well, something went wrong
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
}
};
AsyncTaskCompat.executeParallel(cancelCheckinTask);
}
});
builder.setNegativeButton(R.string.traktcheckin_wait, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// broadcast check-in success
EventBus.getDefault().post(new TraktTask.TraktActionCompleteEvent(TraktAction.valueOf(args.getString(InitBundle.TRAKTACTION)), true, null));
}
});
return builder.create();
}
Aggregations