コード例 #1
0
ファイル: Sendmessage.java プロジェクト: Gilleland/Slide
    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
ファイル: RedditBot.java プロジェクト: Ferocit/RedditRssBot
 private void postRssNews(List<RssNewsEntry> rssNews, NewsConfig newsConfig) {
   int counter = 0;
   for (RssNewsEntry entry : rssNews) {
     try {
       if (!hasEntryBeenPosted(entry, newsConfig)) {
         fluentReddit
             .subreddit(newsConfig.getSubreddit())
             .submit(new URL(entry.getLink()), entry.getTitle());
         log.info("Posted: " + entry.getTitle() + ".");
         counter++;
       }
     } catch (ApiException e) {
       log.fatal("ApiException");
       log.fatal(e.getMessage());
       return;
     } catch (MalformedURLException e) {
       log.fatal("MalformedURLException");
       log.fatal(e.getMessage());
     }
   }
   log.info("Done posting " + counter + " new links");
 }
コード例 #3
0
ファイル: Sendmessage.java プロジェクト: Gilleland/Slide
    @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;
    }