Search in sources :

Example 1 with ProfileCommentViewHolder

use of me.ccrama.redditslide.Adapters.ProfileCommentViewHolder in project Slide by ccrama.

the class RedditItemView method doComment.

public void doComment(Comment comment, View content) {
    ProfileCommentViewHolder holder = new ProfileCommentViewHolder(content);
    String scoreText;
    if (comment.isScoreHidden()) {
        scoreText = "[" + getContext().getString(R.string.misc_score_hidden).toUpperCase() + "]";
    } else {
        scoreText = String.format(Locale.getDefault(), "%d", comment.getScore());
    }
    SpannableStringBuilder score = new SpannableStringBuilder(scoreText);
    if (score == null || score.toString().isEmpty()) {
        score = new SpannableStringBuilder("0");
    }
    if (!scoreText.contains("[")) {
        score.append(String.format(Locale.getDefault(), " %s", getContext().getResources().getQuantityString(R.plurals.points, comment.getScore())));
    }
    holder.score.setText(score);
    if (Authentication.isLoggedIn) {
        if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
            holder.score.setTextColor(getContext().getResources().getColor(R.color.md_orange_500));
        } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
            holder.score.setTextColor(getContext().getResources().getColor(R.color.md_blue_500));
        } else {
            holder.score.setTextColor(holder.time.getCurrentTextColor());
        }
    }
    String spacer = getContext().getString(R.string.submission_properties_seperator);
    SpannableStringBuilder titleString = new SpannableStringBuilder();
    String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), getContext());
    String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : // some users were crashing here
    timeAgo);
    time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), getContext()) + ")" : ""));
    titleString.append(time);
    titleString.append(spacer);
    if (comment.getSubredditName() != null) {
        String subname = comment.getSubredditName();
        SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
        if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
            subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        titleString.append(subreddit);
    }
    holder.time.setText(titleString);
    setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
    int type = new FontPreferences(getContext()).getFontTypeComment().getTypeface();
    Typeface typeface;
    if (type >= 0) {
        typeface = RobotoTypefaces.obtainTypeface(getContext(), type);
    } else {
        typeface = Typeface.DEFAULT;
    }
    holder.content.setTypeface(typeface);
    if (comment.getTimesGilded() > 0) {
        final String timesGilded = (comment.getTimesGilded() == 1) ? "" : "\u200Ax" + Integer.toString(comment.getTimesGilded());
        SpannableStringBuilder gilded = new SpannableStringBuilder("\u00A0★" + timesGilded + "\u00A0");
        TypedArray a = getContext().obtainStyledAttributes(new FontPreferences(getContext()).getPostFontStyle().getResId(), R.styleable.FontStyle);
        int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
        a.recycle();
        Bitmap image = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.gold);
        float aspectRatio = (float) (1.00 * image.getWidth() / image.getHeight());
        image = Bitmap.createScaledBitmap(image, (int) Math.ceil(fontsize * aspectRatio), (int) Math.ceil(fontsize), true);
        gilded.setSpan(new ImageSpan(getContext(), image, ImageSpan.ALIGN_BASELINE), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        gilded.setSpan(new RelativeSizeSpan(0.75f), 3, gilded.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.gild.setVisibility(View.VISIBLE);
        ((TextView) holder.gild).setText(gilded);
    } else if (holder.gild.getVisibility() == View.VISIBLE) {
        holder.gild.setVisibility(View.GONE);
    }
    if (comment.getSubmissionTitle() != null) {
        holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
    } else {
        holder.title.setText(Html.fromHtml(comment.getAuthor()));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Typeface(android.graphics.Typeface) ProfileCommentViewHolder(me.ccrama.redditslide.Adapters.ProfileCommentViewHolder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) Bitmap(android.graphics.Bitmap) StyleSpan(android.text.style.StyleSpan) TypedArray(android.content.res.TypedArray) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Aggregations

TypedArray (android.content.res.TypedArray)1 Bitmap (android.graphics.Bitmap)1 Typeface (android.graphics.Typeface)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 ImageSpan (android.text.style.ImageSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 StyleSpan (android.text.style.StyleSpan)1 TextView (android.widget.TextView)1 ProfileCommentViewHolder (me.ccrama.redditslide.Adapters.ProfileCommentViewHolder)1 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)1 FontPreferences (me.ccrama.redditslide.Visuals.FontPreferences)1