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