Esempio n. 1
0
 private boolean isGrid() {
   return manager.getViewMode() == ThreadManager.ViewMode.GRID;
 }
Esempio n. 2
0
 private boolean isList() {
   return manager.getViewMode() == ThreadManager.ViewMode.LIST;
 }
Esempio n. 3
0
 @Override
 public void onClick(View v) {
   manager.onPostClicked(post);
 }
Esempio n. 4
0
 public void onLinkableClick(PostLinkable linkable) {
   manager.onPostLinkableClicked(linkable);
 }
Esempio n. 5
0
  private void buildView(final Context context, TypedArray ta) {
    int thumbnailBackground = ta.getColor(R.styleable.PostView_thumbnail_background, 0);
    int replyCountColor = ta.getColor(R.styleable.PostView_reply_count_color, 0);

    int iconPadding = ta.getDimensionPixelSize(R.styleable.PostView_icon_padding, 0);
    int iconWidth = ta.getDimensionPixelSize(R.styleable.PostView_icon_width, 0);
    int iconHeight = ta.getDimensionPixelSize(R.styleable.PostView_icon_height, 0);
    int gridHeight = ta.getDimensionPixelSize(R.styleable.PostView_grid_height, 0);
    int optionsSpacing = ta.getDimensionPixelSize(R.styleable.PostView_options_spacing, 0);
    int titleSize = ta.getDimensionPixelSize(R.styleable.PostView_title_size, 0);
    int optionsLeftPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_left_padding, 0);
    int optionsTopPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_top_padding, 0);
    int optionsRightPadding =
        ta.getDimensionPixelSize(R.styleable.PostView_options_right_padding, 0);
    int optionsBottomPadding =
        ta.getDimensionPixelSize(R.styleable.PostView_options_bottom_padding, 0);
    int lastSeenHeight = ta.getDimensionPixelSize(R.styleable.PostView_last_seen_height, 0);

    int postListMaxHeight =
        ta.getDimensionPixelSize(R.styleable.PostView_list_comment_max_height, 0);

    int postCommentSize = 0;
    int commentPadding = 0;
    int postPadding = 0;
    int imageSize = 0;
    int repliesCountSize = 0;
    if (isList()) {
      postCommentSize =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_SP,
                  ThemeHelper.getInstance().getFontSize(),
                  getResources().getDisplayMetrics());
      commentPadding = ta.getDimensionPixelSize(R.styleable.PostView_list_comment_padding, 0);
      postPadding = ta.getDimensionPixelSize(R.styleable.PostView_list_padding, 0);
      imageSize = ta.getDimensionPixelSize(R.styleable.PostView_list_image_size, 0);
      repliesCountSize = ta.getDimensionPixelSize(R.styleable.PostView_list_replies_count_size, 0);
    } else if (isGrid()) {
      postCommentSize =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_SP,
                  ThemeHelper.getInstance().getFontSize() - 1,
                  getResources().getDisplayMetrics());
      commentPadding = ta.getDimensionPixelSize(R.styleable.PostView_grid_comment_padding, 0);
      postPadding = ta.getDimensionPixelSize(R.styleable.PostView_grid_padding, 0);
      imageSize = ta.getDimensionPixelSize(R.styleable.PostView_grid_image_size, 0);
      repliesCountSize = ta.getDimensionPixelSize(R.styleable.PostView_grid_replies_count_size, 0);
    }

    RelativeLayout wrapper = new RelativeLayout(context);
    wrapper.setLayoutParams(matchParams);

    full = new LinearLayout(context);
    if (isList()) {
      full.setOrientation(HORIZONTAL);
      wrapper.addView(full, matchParams);
    } else if (isGrid()) {
      full.setOrientation(VERTICAL);
      wrapper.addView(full, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, gridHeight));
    }

    LinearLayout imageContainer = new LinearLayout(context);
    imageContainer.setOrientation(VERTICAL);
    imageContainer.setBackgroundColor(thumbnailBackground);

    // Create thumbnail
    imageView = new CustomNetworkImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setFadeIn(100);

    imageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            manager.onThumbnailClicked(post);
          }
        });

    if (isList()) {
      imageContainer.addView(imageView, new LinearLayout.LayoutParams(imageSize, imageSize));
      full.addView(imageContainer, wrapMatchParams);
      full.setMinimumHeight(imageSize);
    } else if (isGrid()) {
      imageContainer.addView(
          imageView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, imageSize));
      full.addView(imageContainer, matchWrapParams);
    }

    contentContainer = new LinearLayout(context);
    contentContainer.setOrientation(VERTICAL);

    LinearLayout titleContainer = new LinearLayout(context);
    titleContainer.setOrientation(HORIZONTAL);

    if (isList()) {
      // 25 padding to give optionsView some space
      titleContainer.setPadding(0, 0, optionsSpacing, 0);
    }

    titleView = new TextView(context);
    titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
    titleView.setPadding(postPadding, postPadding, postPadding, 0);

    titleContainer.addView(titleView, wrapParams);

    contentContainer.addView(titleContainer, matchWrapParams);

    iconsView = new LinearLayout(context);
    iconsView.setOrientation(HORIZONTAL);
    iconsView.setPadding(postPadding, iconPadding, postPadding, 0);

    stickyView = new ImageView(context);
    stickyView.setImageDrawable(IconCache.stickyIcon);
    iconsView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    closedView = new ImageView(context);
    closedView.setImageDrawable(IconCache.closedIcon);
    iconsView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    deletedView = new ImageView(context);
    deletedView.setImageDrawable(IconCache.trashIcon);
    iconsView.addView(deletedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    archivedView = new ImageView(context);
    archivedView.setImageDrawable(IconCache.archivedIcon);
    iconsView.addView(archivedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    countryView = new NetworkImageView(context);
    countryView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    iconsView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight));

    contentContainer.addView(iconsView, matchWrapParams);

    commentView = new TextView(context);
    commentView.setTextSize(TypedValue.COMPLEX_UNIT_PX, postCommentSize);

    if (isList()) {
      commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding);

      if (manager.getLoadable().isBoardMode() || manager.getLoadable().isCatalogMode()) {
        commentView.setMaxHeight(postListMaxHeight);
      }
    } else if (isGrid()) {
      commentView.setPadding(postPadding, commentPadding, postPadding, 0);
      // So that is fills up all the height using weight later on
      commentView.setMinHeight(10000);
    }

    if (isList()) {
      contentContainer.addView(commentView, matchWrapParams);
    } else if (isGrid()) {
      contentContainer.addView(
          commentView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f));
    }

    repliesCountView = new TextView(context);
    Utils.setPressedDrawable(repliesCountView);
    repliesCountView.setTextColor(replyCountColor);
    repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding);
    repliesCountView.setTextSize(TypedValue.COMPLEX_UNIT_PX, repliesCountSize);
    repliesCountView.setSingleLine();

    contentContainer.addView(repliesCountView, wrapParams);

    lastSeen = new View(context);
    lastSeen.setBackgroundColor(0xffff0000);
    contentContainer.addView(lastSeen, new LayoutParams(LayoutParams.MATCH_PARENT, lastSeenHeight));

    if (!manager.getLoadable().isThreadMode()) {
      Utils.setPressedDrawable(contentContainer);
    }

    full.addView(contentContainer, matchWrapParams);

    optionsView = new ImageView(context);
    optionsView.setImageResource(R.drawable.ic_overflow);
    Utils.setPressedDrawable(optionsView);
    optionsView.setPadding(
        optionsLeftPadding, optionsTopPadding, optionsRightPadding, optionsBottomPadding);
    optionsView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(final View v) {
            PopupMenu popupMenu = new PopupMenu(context, v);
            manager.showPostOptions(post, popupMenu);
            popupMenu.show();
            if (ThemeHelper.getInstance().getTheme().isLightTheme) {
              optionsView.setImageResource(R.drawable.ic_overflow_black);
              popupMenu.setOnDismissListener(
                  new PopupMenu.OnDismissListener() {
                    @Override
                    public void onDismiss(final PopupMenu menu) {
                      optionsView.setImageResource(R.drawable.ic_overflow);
                    }
                  });
            }
          }
        });
    wrapper.addView(optionsView, wrapParams);
    RelativeLayout.LayoutParams optionsParams =
        (RelativeLayout.LayoutParams) optionsView.getLayoutParams();
    optionsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    optionsParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    optionsView.setLayoutParams(optionsParams);

    addView(wrapper, matchParams);

    wrapper.setOnClickListener(this);
  }
Esempio n. 6
0
  public void setPost(final Post post, final ThreadManager manager) {
    this.post = post;
    this.manager = manager;

    highlightQuotesNo = -1;

    boolean boardCatalogMode =
        manager.getLoadable().isBoardMode() || manager.getLoadable().isCatalogMode();

    TypedArray ta =
        context.obtainStyledAttributes(null, R.styleable.PostView, R.attr.post_style, 0);

    if (!isBuild) {
      buildView(context, ta);
      isBuild = true;
    }

    int dateColor = ta.getColor(R.styleable.PostView_date_color, 0);
    int savedReplyColor = ta.getColor(R.styleable.PostView_saved_reply_color, 0);
    int highlightedColor = ta.getColor(R.styleable.PostView_highlighted_color, 0);
    int detailSize = ta.getDimensionPixelSize(R.styleable.PostView_detail_size, 0);

    ta.recycle();

    if (post.hasImage) {
      imageView.setVisibility(View.VISIBLE);
      imageView.setImageUrl(post.thumbnailUrl, ChanApplication.getVolleyImageLoader());
    } else {
      imageView.setVisibility(View.GONE);
      imageView.setImageUrl(null, null);
    }

    CharSequence total = new SpannableString("");

    if (post.subjectSpan != null) {
      total = TextUtils.concat(total, post.subjectSpan);
    }

    if (isList()) {
      CharSequence relativeTime =
          DateUtils.getRelativeTimeSpanString(
              post.time * 1000L, Time.get(), DateUtils.SECOND_IN_MILLIS, 0);
      SpannableString date = new SpannableString("No." + post.no + " " + relativeTime);
      date.setSpan(new ForegroundColorSpan(dateColor), 0, date.length(), 0);
      date.setSpan(new AbsoluteSizeSpan(detailSize), 0, date.length(), 0);

      total =
          TextUtils.concat(
              total,
              post.subjectSpan == null ? "" : "\n",
              post.nameTripcodeIdCapcodeSpan,
              date,
              " ");
    }

    if (!TextUtils.isEmpty(total)) {
      titleView.setText(total);
      titleView.setVisibility(View.VISIBLE);
    } else {
      titleView.setVisibility(View.GONE);
    }

    commentView.setText(post.comment);

    if (manager.getLoadable().isThreadMode()) {
      post.setLinkableListener(this);
      commentView.setMovementMethod(new PostViewMovementMethod());
      commentView.setOnClickListener(this);
    } else {
      post.setLinkableListener(null);
      commentView.setOnClickListener(null);
      commentView.setClickable(false);
      commentView.setMovementMethod(null);
    }

    if (isGrid()
        || ((post.isOP && boardCatalogMode && post.replies > 0) || (post.repliesFrom.size() > 0))) {
      repliesCountView.setVisibility(View.VISIBLE);

      String text = "";

      int count = boardCatalogMode ? post.replies : post.repliesFrom.size();

      if (count != 1) {
        text = count + " " + context.getString(R.string.multiple_replies);
      } else if (count == 1) {
        text = count + " " + context.getString(R.string.one_reply);
      }

      if (boardCatalogMode && post.images > 0) {
        if (post.images != 1) {
          text += ", " + post.images + " " + context.getString(R.string.multiple_images);
        } else {
          text += ", " + post.images + " " + context.getString(R.string.one_image);
        }
      }

      if (manager.getLoadable().isThreadMode()) {
        repliesCountView.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                manager.showPostReplies(post);
              }
            });
      }

      repliesCountView.setText(text);
    } else {
      repliesCountView.setVisibility(View.GONE);
      repliesCountView.setOnClickListener(null);
    }

    boolean showCountryFlag =
        isList() && !TextUtils.isEmpty(post.country) && !TextUtils.isEmpty(post.countryUrl);
    boolean showStickyIcon = isList() && post.sticky;
    boolean showDeletedIcon = isList() && post.deleted;
    boolean showArchivedIcon = isList() && post.archived;
    boolean showClosedIcon = isList() && post.closed && !showArchivedIcon;

    iconsView.setVisibility(
        (showCountryFlag || showStickyIcon || showClosedIcon || showDeletedIcon || showArchivedIcon)
            ? View.VISIBLE
            : View.GONE);

    stickyView.setVisibility(showStickyIcon ? View.VISIBLE : View.GONE);
    closedView.setVisibility(showClosedIcon ? View.VISIBLE : View.GONE);
    deletedView.setVisibility(showDeletedIcon ? View.VISIBLE : View.GONE);
    archivedView.setVisibility(showArchivedIcon ? View.VISIBLE : View.GONE);
    if (showCountryFlag) {
      countryView.setVisibility(View.VISIBLE);
      countryView.setImageUrl(post.countryUrl, ChanApplication.getVolleyImageLoader());
    } else {
      countryView.setVisibility(View.GONE);
      countryView.setImageUrl(null, null);
    }

    if (post.isSavedReply) {
      full.setBackgroundColor(savedReplyColor);
    } else if (manager.isPostHightlighted(post)) {
      full.setBackgroundColor(highlightedColor);
    } else {
      full.setBackgroundColor(0x00000000);
    }

    if (manager.isPostLastSeen(post)) {
      lastSeen.setVisibility(View.VISIBLE);
    } else {
      lastSeen.setVisibility(View.GONE);
    }
  }