Ejemplo n.º 1
0
    @Override
    public View getView(View convertView, ViewGroup parent) {
      if (convertView == null) {
        convertView = inflater.inflate(R.layout.timeline_post_cell, null);
      }
      TextView bodyView = (TextView) convertView.findViewById(R.id.postContent);
      TextView userNameView = (TextView) convertView.findViewById(R.id.userName);
      TextView userPointView = (TextView) convertView.findViewById(R.id.userPoint);
      TextView postedTimeView = (TextView) convertView.findViewById(R.id.postedTime);
      ImageView imageView = (ImageView) convertView.findViewById(R.id.userIcon);
      ImageView postImageView = (ImageView) convertView.findViewById(R.id.postImage);

      if (post.getImageURL() != null) {
        postImageView.setTag(post.getImageURL());
        imageLoader.displayImage(postImageView, TimelineAdapter.this.activity);
        postImageView.setVisibility(View.VISIBLE);
      } else {
        postImageView.setImageDrawable(null);
        postImageView.setVisibility(View.INVISIBLE);
      }
      if (post.getBody() != null) {
        bodyView.setText(post.getBody());
        bodyView.setVisibility(View.VISIBLE);
      } else {
        bodyView.setText(null);
        bodyView.setVisibility(View.INVISIBLE);
      }
      userNameView.setText(post.getUser().getName());
      userPointView.setText(Integer.toString(post.getUser().getTotalPoint()) + "P");
      imageView.setTag(post.getUser().getIconURL());
      imageLoader.displayImage(imageView, TimelineAdapter.this.activity);
      final Date postedDate = post.getTime();
      final long diffMillis = new Date().getTime() - postedDate.getTime();
      if (diffMillis < ONE_HOUR_MILLIS) {
        postedTimeView.setText((diffMillis / 1000 / 60) + "分前");
      } else {
        postedTimeView.setText(dateFormat.format(postedDate));
      }

      if (diffMillis < FIVE_MINUTES_MILLIS) {
        convertView.setBackgroundResource(R.drawable.cell_highlight_background);
      } else {
        convertView.setBackgroundColor(Color.TRANSPARENT);
      }

      return convertView;
    }
Ejemplo n.º 2
0
  public String body(Post post) {
    if (!StringUtils.hasText(post.getBody())) {
      return null;
    }

    //		Blog blog = blogService.readBlogById(Blog.DEFAULT_ID);
    Document document = Jsoup.parse(post.getBody());
    Elements elements = document.select("img");
    for (Element element : elements) {
      String src = element.attr("src");
      if (src.startsWith(wallRideProperties.getMediaUrlPrefix())) {
        String style = element.attr("style");
        Pattern pattern = Pattern.compile("width: ([0-9]+)px;");
        Matcher matcher = pattern.matcher(element.attr("style"));
        if (matcher.find()) {
          String replaced = src + "?w=" + matcher.group(1);
          element.attr("src", replaced);
        }
      }
    }
    return document.body().html();
  }
Ejemplo n.º 3
0
 public String summary(Post post, int length) {
   Document document = Jsoup.parse(post.getBody());
   String summary = document.text();
   if (!StringUtils.hasText(summary)) {
     return summary;
   }
   summary = summary.replaceAll("<.+?>", "");
   if (!StringUtils.hasText(summary)) {
     return summary;
   }
   if (summary.length() <= length) {
     return summary;
   }
   return summary.substring(0, length) + "...";
 }