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