コード例 #1
0
    protected void onPostExecute(CommentList comments) {
      mIsUpdatingComments = false;
      mUpdateCommentsTask = null;
      if (!hasActivity()) {
        return;
      }
      if (isLoadingMore) {
        hideLoadingProgress();
      }
      mPullToRefreshHelper.setRefreshing(false);

      if (isCancelled()) return;

      mCanLoadMoreComments = (comments != null && comments.size() > 0);

      // result will be null on error OR if no more comments exists
      if (comments == null) {
        if (isError && !getActivity().isFinishing()) {
          ToastUtils.showToast(getActivity(), getString(R.string.error_refresh_comments));
        }
        return;
      }

      if (comments.size() > 0) {
        getCommentAdapter().loadComments();
      }
    }
コード例 #2
0
  /*
   * follow editText entry as a url
   */
  private void addAsUrl(final String entry) {
    if (TextUtils.isEmpty(entry)) {
      return;
    }

    // normalize the url and prepend protocol if not supplied
    final String normUrl;
    if (!entry.contains("://")) {
      normUrl = UrlUtils.normalizeUrl("http://" + entry);
    } else {
      normUrl = UrlUtils.normalizeUrl(entry);
    }

    // if this isn't a valid URL, add original entry as a tag
    if (!URLUtil.isNetworkUrl(normUrl)) {
      addAsTag(entry);
      return;
    }

    // make sure it isn't already followed
    if (ReaderBlogTable.isFollowedBlogUrl(normUrl) || ReaderBlogTable.isFollowedFeedUrl(normUrl)) {
      ToastUtils.showToast(this, R.string.reader_toast_err_already_follow_blog);
      return;
    }

    // URL is valid, so follow it
    performAddUrl(normUrl);
  }
コード例 #3
0
  private void sharePage() {
    if (!isAdded() || !hasPost()) {
      return;
    }

    final String url = (mPost.hasShortUrl() ? mPost.getShortUrl() : mPost.getUrl());
    final String shareText;

    if (mPost.hasTitle()) {
      final String title;
      // we don't know where the user will choose to share, so enforce a max title length
      // in order to fit a tweet with some extra room for the URL and user edits
      if (mPost.getTitle().length() > MAX_SHARE_TITLE_LEN) {
        title = mPost.getTitle().substring(0, MAX_SHARE_TITLE_LEN).trim() + "…";
      } else {
        title = mPost.getTitle().trim();
      }
      shareText = title + " - " + url;
    } else {
      shareText = url;
    }

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, shareText);
    intent.putExtra(
        Intent.EXTRA_SUBJECT,
        getString(R.string.reader_share_subject, getString(R.string.app_name)));
    try {
      startActivity(Intent.createChooser(intent, getString(R.string.reader_share_link)));
    } catch (android.content.ActivityNotFoundException ex) {
      ToastUtils.showToast(getActivity(), R.string.reader_toast_err_share_intent);
    }
  }
コード例 #4
0
 /*
  * triggered when user chooses to reblog the post
  */
 private void doPostReblog(View btnReblog, ReaderPost post) {
   if (post.isRebloggedByCurrentUser) {
     ToastUtils.showToast(this, R.string.reader_toast_err_already_reblogged);
     return;
   }
   btnReblog.setSelected(true);
   ReaderAniUtils.zoomAction(btnReblog);
   ReaderActivityLauncher.showReaderReblogForResult(this, post);
 }
コード例 #5
0
  /*
   * follow editText entry as a tag
   */
  private void addAsTag(final String entry) {
    if (TextUtils.isEmpty(entry)) {
      return;
    }

    if (!ReaderTag.isValidTagName(entry)) {
      ToastUtils.showToast(this, R.string.reader_toast_err_tag_invalid);
      return;
    }

    if (ReaderTagTable.isFollowedTagName(entry)) {
      ToastUtils.showToast(this, R.string.reader_toast_err_tag_exists);
      return;
    }

    // tag is valid, follow it
    mEditAdd.setText(null);
    EditTextUtils.hideSoftInput(mEditAdd);
    performAddTag(entry);
  }
コード例 #6
0
  /**
   * Shows a toast message, unless there is an authentication issue which will show an alert dialog.
   */
  public static void showToastOrAuthAlert(
      Context context, VolleyError error, String friendlyMessage) {
    if (context == null) return;

    String message = null;
    boolean isInvalidTokenError = false;
    JSONObject errorObj = VolleyUtils.volleyErrorToJSON(error);
    if (errorObj != null) {
      try {
        if (errorObj.has("error_description")) { // OAuth token request error
          message = (String) errorObj.get("error_description");
          String error_code = (String) errorObj.get("error");
          if (error_code != null
              && error_code.equals("invalid_request")
              && message.toLowerCase().contains("incorrect username or password")) {
            isInvalidTokenError = true;
          }
        } else {
          message = (String) errorObj.get("message");
          String error_code = (String) errorObj.get("error");
          if (error_code != null && error_code.equals("invalid_token")) {
            isInvalidTokenError = true;
          }
        }
      } catch (JSONException e) {
        AppLog.e(T.API, e);
      }
    } else {
      message = error.getMessage();
    }

    if (isInvalidTokenError && (context instanceof Activity)) {
      showAuthErrorView((Activity) context);
    } else {
      String fallbackErrorMessage =
          TextUtils.isEmpty(friendlyMessage)
              ? context.getString(R.string.error_generic)
              : friendlyMessage;
      if (message != null && message.contains("Limit reached")) {
        message = context.getString(R.string.limit_reached);
      }
      String errorMessage = TextUtils.isEmpty(message) ? fallbackErrorMessage : message;
      showToast(context, errorMessage, Duration.LONG);
    }
  }
コード例 #7
0
  public static void openUrl(Context context, String url, OpenUrlType openUrlType) {
    if (TextUtils.isEmpty(url)) {
      return;
    }

    // TODO: NotificationsWebViewActivity will fail without a current blog
    if (openUrlType == OpenUrlType.INTERNAL && WordPress.getCurrentBlog() != null) {
      NotificationsWebViewActivity.openUrl(context, url);
    } else {
      try {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(intent);
      } catch (ActivityNotFoundException e) {
        ToastUtils.showToast(
            context,
            context.getString(R.string.reader_toast_err_url_intent, url),
            ToastUtils.Duration.LONG);
      }
    }
  }
コード例 #8
0
 /*
  * called when post couldn't be loaded and failed to be returned from server
  */
 private void postFailed() {
   if (isAdded()) {
     ToastUtils.showToast(
         getActivity(), R.string.reader_toast_err_get_post, ToastUtils.Duration.LONG);
   }
 }