Пример #1
0
    public void sendMessage(Captcha captcha, String captchaAttempt) {
      if (reply) {
        try {
          new net.dean.jraw.managers.AccountManager(Authentication.reddit)
              .reply(previousMessage, bodytext);
        } catch (ApiException e) {
          messageSent = false;
          e.printStackTrace();
        }
      } else {
        try {
          if (captcha != null)
            new InboxManager(Authentication.reddit)
                .compose(totext, subjecttext, bodytext, captcha, captchaAttempt);
          else new InboxManager(Authentication.reddit).compose(totext, subjecttext, bodytext);

        } catch (ApiException e) {
          messageSent = false;
          e.printStackTrace();

          // Display a Toast with an error if the user doesn't exist
          if (e.getReason().equals("USER_DOESNT_EXIST") || e.getReason().equals("NO_USER")) {
            messageSentStatus = getString(R.string.msg_send_user_dne);
          } else if (e.getReason().toLowerCase().contains("captcha")) {
            messageSentStatus = "Captcha incorrect, please try again.";
          }

          // todo show captcha
        }
      }
    }
Пример #2
0
    @Override
    protected Void doInBackground(Void... voids) {
      if (new CaptchaHelper(Authentication.reddit).isNecessary()) {
        // display capacha
        final Captcha c;
        try {
          c = new CaptchaHelper(Authentication.reddit).getNew();

          runOnUiThread(
              new Runnable() {
                @Override
                public void run() {
                  LayoutInflater inflater = getLayoutInflater();

                  final View dialoglayout = inflater.inflate(R.layout.capatcha, null);
                  final AlertDialogWrapper.Builder builder =
                      new AlertDialogWrapper.Builder(Sendmessage.this);

                  ((Reddit) getApplication())
                      .getImageLoader()
                      .displayImage(
                          c.getImageUrl().toString(),
                          (ImageView) dialoglayout.findViewById(R.id.cap));

                  final Dialog dialog = builder.setView(dialoglayout).create();
                  dialog.show();
                  dialog.setOnDismissListener(
                      new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                          ((FloatingActionButton) findViewById(R.id.send)).show();
                        }
                      });
                  dialoglayout
                      .findViewById(R.id.ok)
                      .setOnClickListener(
                          new View.OnClickListener() {
                            @Override
                            public void onClick(View d) {
                              trying =
                                  ((EditText) dialoglayout.findViewById(R.id.entry))
                                      .getText()
                                      .toString();
                              dialog.dismiss();
                              final String text =
                                  ((EditText) findViewById(R.id.bodytext)).getText().toString();
                              new AsyncTask<Void, Void, Boolean>() {
                                @Override
                                protected Boolean doInBackground(Void... params) {
                                  sendMessage(c, trying);
                                  return true;
                                }
                              }.execute();
                            }
                          });
                }
              });
        } catch (ApiException e) {
          e.printStackTrace();
          // todo fail
          sendMessage(null, null);
        }
      } else {
        sendMessage(null, null);
      }

      return null;
    }