Search in sources :

Example 1 with ModAction

use of net.dean.jraw.models.ModAction in project Slide by ccrama.

the class ModLogAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHold, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (firstHold instanceof ModLogViewHolder) {
        ModLogViewHolder holder = (ModLogViewHolder) firstHold;
        final ModAction a = dataSet.posts.get(i);
        SpannableStringBuilder b = new SpannableStringBuilder();
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        String timeAgo = TimeUtils.getTimeAgo(a.getCreated().getTime(), mContext);
        String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : // some users were crashing here
        timeAgo);
        titleString.append(time);
        titleString.append(spacer);
        if (a.getSubreddit() != null) {
            String subname = a.getSubreddit();
            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);
        }
        b.append(titleString);
        b.append(spacer);
        SpannableStringBuilder author = new SpannableStringBuilder(a.getModerator());
        final int authorcolor = Palette.getFontColorUser(a.getModerator());
        author.setSpan(new TypefaceSpan("sans-serif-condensed"), 0, author.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        author.setSpan(new StyleSpan(Typeface.BOLD), 0, author.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (Authentication.name != null && a.getModerator().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
            author.replace(0, author.length(), " " + a.getModerator() + " ");
            author.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (authorcolor != 0) {
            author.setSpan(new ForegroundColorSpan(authorcolor), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        author.setSpan(new RelativeSizeSpan(0.8f), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        b.append(author);
        b.append("\n\n");
        b.append(a.getAction() + " " + (!a.getDataNode().get("target_title").isNull() ? "\"" + a.getDataNode().get("target_title").asText() + "\"" : "") + (a.getTargetAuthor() != null ? " by /u/" + a.getTargetAuthor() : ""));
        if (a.getTargetPermalink() != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    OpenRedditLink.openUrl(mContext, a.getTargetPermalink(), true);
                }
            });
        }
        if (a.getDetails() != null) {
            SpannableStringBuilder description = new SpannableStringBuilder(" (" + a.getDetails() + ")");
            description.setSpan(new StyleSpan(Typeface.ITALIC), 0, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            description.setSpan(new RelativeSizeSpan(0.8f), 0, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            b.append(description);
        }
        holder.body.setText(b);
        String action = a.getAction();
        if (action.equals("removelink")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.close, null));
        } else if (action.equals("approvecomment")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.support, null));
        } else if (action.equals("removecomment")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.commentchange, null));
        } else if (action.equals("approvelink")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.support, null));
        } else if (action.equals("editflair")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.flair, null));
        } else if (action.equals("distinguish")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null));
        } else if (action.equals("sticky")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.lock, null));
        } else if (action.equals("unsticky")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.lock, null));
        } else if (action.equals("ignorereports")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ignore, null));
        } else if (action.equals("unignorereports")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.unignore, null));
        } else if (action.equals("marknsfw")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null));
        } else if (action.equals("unmarknsfw")) {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null));
        } else {
            holder.icon.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.mod, null));
        }
    }
    if (firstHold instanceof SpacerViewHolder) {
        firstHold.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(firstHold.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
    }
}
Also used : ModAction(net.dean.jraw.models.ModAction) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) RoundedBackgroundSpan(me.ccrama.redditslide.Views.RoundedBackgroundSpan) StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) TypefaceSpan(android.text.style.TypefaceSpan)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 StyleSpan (android.text.style.StyleSpan)1 TypefaceSpan (android.text.style.TypefaceSpan)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)1 RoundedBackgroundSpan (me.ccrama.redditslide.Views.RoundedBackgroundSpan)1 ModAction (net.dean.jraw.models.ModAction)1