Search in sources :

Example 1 with InvalidScopeException

use of net.dean.jraw.http.oauth.InvalidScopeException in project Slide by ccrama.

the class CommentAdapterHelper method showBan.

public static void showBan(final Context mContext, final View mToolbar, final Comment submission, String rs, String nt, String msg, String t) {
    LinearLayout l = new LinearLayout(mContext);
    l.setOrientation(LinearLayout.VERTICAL);
    int sixteen = Reddit.dpToPxVertical(16);
    l.setPadding(sixteen, 0, sixteen, 0);
    final EditText reason = new EditText(mContext);
    reason.setHint(R.string.mod_ban_reason);
    reason.setText(rs);
    reason.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(reason);
    final EditText note = new EditText(mContext);
    note.setHint(R.string.mod_ban_note_mod);
    note.setText(nt);
    note.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(note);
    final EditText message = new EditText(mContext);
    message.setHint(R.string.mod_ban_note_user);
    message.setText(msg);
    message.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(message);
    final EditText time = new EditText(mContext);
    time.setHint(R.string.mod_ban_time);
    time.setText(t);
    time.setInputType(InputType.TYPE_CLASS_NUMBER);
    l.addView(time);
    AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
    builder.setView(l).setTitle(mContext.getString(R.string.mod_ban_title, submission.getAuthor())).setCancelable(true).setPositiveButton(R.string.mod_btn_ban, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // to ban
            if (reason.getText().toString().isEmpty() || time.getText().toString().isEmpty()) {
                new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_ban_requirements).setMessage(R.string.misc_please_try_again).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
                    }
                }).setCancelable(false).show();
            } else {
                new AsyncTask<Void, Void, Boolean>() {

                    @Override
                    protected Boolean doInBackground(Void... params) {
                        try {
                            String n = note.getText().toString();
                            String m = message.getText().toString();
                            if (n.isEmpty()) {
                                n = null;
                            }
                            if (m.isEmpty()) {
                                m = null;
                            }
                            new ModerationManager(Authentication.reddit).banUser(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m, Integer.valueOf(time.getText().toString()));
                            return true;
                        } catch (Exception e) {
                            if (e instanceof InvalidScopeException) {
                                scope = true;
                            }
                            e.printStackTrace();
                            return false;
                        }
                    }

                    boolean scope;

                    @Override
                    protected void onPostExecute(Boolean done) {
                        Snackbar s;
                        if (done) {
                            s = Snackbar.make(mToolbar, R.string.mod_ban_success, Snackbar.LENGTH_SHORT);
                        } else {
                            if (scope) {
                                new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_ban_reauth).setMessage(R.string.mod_ban_reauth_question).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Intent i = new Intent(mContext, Reauthenticate.class);
                                        mContext.startActivity(i);
                                    }
                                }).setNegativeButton(R.string.misc_maybe_later, null).setCancelable(false).show();
                            }
                            s = Snackbar.make(mToolbar, R.string.mod_ban_fail, Snackbar.LENGTH_INDEFINITE).setAction(R.string.misc_try_again, new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
                                }
                            });
                        }
                        if (s != null) {
                            View view = s.getView();
                            TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                            tv.setTextColor(Color.WHITE);
                            s.show();
                        }
                    }
                }.execute();
            }
        }
    }).setNegativeButton(R.string.btn_cancel, null).show();
}
Also used : EditText(android.widget.EditText) ModerationManager(net.dean.jraw.managers.ModerationManager) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) ApiException(net.dean.jraw.ApiException) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Example 2 with InvalidScopeException

use of net.dean.jraw.http.oauth.InvalidScopeException in project Slide by ccrama.

the class PopulateSubmissionViewHolder method showBan.

public void showBan(final Context mContext, final View mToolbar, final Submission submission, String rs, String nt, String msg, String t) {
    LinearLayout l = new LinearLayout(mContext);
    l.setOrientation(LinearLayout.VERTICAL);
    int sixteen = Reddit.dpToPxVertical(16);
    l.setPadding(sixteen, 0, sixteen, 0);
    final EditText reason = new EditText(mContext);
    reason.setHint(R.string.mod_ban_reason);
    reason.setText(rs);
    reason.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(reason);
    final EditText note = new EditText(mContext);
    note.setHint(R.string.mod_ban_note_mod);
    note.setText(nt);
    note.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(note);
    final EditText message = new EditText(mContext);
    message.setHint(R.string.mod_ban_note_user);
    message.setText(msg);
    message.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    l.addView(message);
    final EditText time = new EditText(mContext);
    time.setHint(R.string.mod_ban_time);
    time.setText(t);
    time.setInputType(InputType.TYPE_CLASS_NUMBER);
    l.addView(time);
    AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
    builder.setView(l).setTitle(mContext.getString(R.string.mod_ban_title, submission.getAuthor())).setCancelable(true).setPositiveButton(R.string.mod_btn_ban, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // to ban
            if (reason.getText().toString().isEmpty()) {
                new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_ban_reason_required).setMessage(R.string.misc_please_try_again).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
                    }
                }).setCancelable(false).show();
            } else {
                new AsyncTask<Void, Void, Boolean>() {

                    @Override
                    protected Boolean doInBackground(Void... params) {
                        try {
                            String n = note.getText().toString();
                            String m = message.getText().toString();
                            if (n.isEmpty()) {
                                n = null;
                            }
                            if (m.isEmpty()) {
                                m = null;
                            }
                            if (time.getText().toString().isEmpty()) {
                                new ModerationManager(Authentication.reddit).banUserPermanently(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m);
                            } else {
                                new ModerationManager(Authentication.reddit).banUser(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m, Integer.valueOf(time.getText().toString()));
                            }
                            return true;
                        } catch (Exception e) {
                            if (e instanceof InvalidScopeException) {
                                scope = true;
                            }
                            e.printStackTrace();
                            return false;
                        }
                    }

                    boolean scope;

                    @Override
                    protected void onPostExecute(Boolean done) {
                        Snackbar s;
                        if (done) {
                            s = Snackbar.make(mToolbar, R.string.mod_ban_success, Snackbar.LENGTH_SHORT);
                        } else {
                            if (scope) {
                                new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_ban_reauth).setMessage(R.string.mod_ban_reauth_question).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Intent i = new Intent(mContext, Reauthenticate.class);
                                        mContext.startActivity(i);
                                    }
                                }).setNegativeButton(R.string.misc_maybe_later, null).setCancelable(false).show();
                            }
                            s = Snackbar.make(mToolbar, R.string.mod_ban_fail, Snackbar.LENGTH_INDEFINITE).setAction(R.string.misc_try_again, new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
                                }
                            });
                        }
                        if (s != null) {
                            View view = s.getView();
                            TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                            tv.setTextColor(Color.WHITE);
                            s.show();
                        }
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    }).setNegativeButton(R.string.btn_cancel, null).show();
}
Also used : EditText(android.widget.EditText) ModerationManager(net.dean.jraw.managers.ModerationManager) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) ApiException(net.dean.jraw.ApiException) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Aggregations

DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 AsyncTask (android.os.AsyncTask)2 Snackbar (android.support.design.widget.Snackbar)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 View (android.view.View)2 EditText (android.widget.EditText)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)2 ApiException (net.dean.jraw.ApiException)2 InvalidScopeException (net.dean.jraw.http.oauth.InvalidScopeException)2 ModerationManager (net.dean.jraw.managers.ModerationManager)2 RecyclerView (android.support.v7.widget.RecyclerView)1 ImageView (android.widget.ImageView)1 MediaView (me.ccrama.redditslide.Activities.MediaView)1 SubredditView (me.ccrama.redditslide.Activities.SubredditView)1 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)1 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)1 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)1