Search in sources :

Example 1 with TraktTask

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");
}
Also used : Bundle(android.os.Bundle) TraktTask(com.battlelancer.seriesguide.util.TraktTask)

Example 2 with TraktTask

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();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) InitBundle(com.battlelancer.seriesguide.util.TraktTask.InitBundle) TraktTask(com.battlelancer.seriesguide.util.TraktTask) AsyncTask(android.os.AsyncTask) IOException(java.io.IOException) SgApp(com.battlelancer.seriesguide.SgApp) SuppressLint(android.annotation.SuppressLint) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint) NonNull(android.support.annotation.NonNull)

Aggregations

Bundle (android.os.Bundle)2 TraktTask (com.battlelancer.seriesguide.util.TraktTask)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 AsyncTask (android.os.AsyncTask)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 SgApp (com.battlelancer.seriesguide.SgApp)1 InitBundle (com.battlelancer.seriesguide.util.TraktTask.InitBundle)1 IOException (java.io.IOException)1