Search in sources :

Example 1 with FontPreferences

use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.

the class BaseActivity method applyDarkColorTheme.

/**
 * Applies the activity's base color theme based on the theme of a specific subreddit. Should be
 * called before inflating any layouts.
 * <p/>
 * This will take the accent colors from the sub theme but return the AMOLED with contrast base
 * theme.
 *
 * @param subreddit The subreddit to base the theme on
 */
protected void applyDarkColorTheme(String subreddit) {
    getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
    getTheme().applyStyle(new ColorPreferences(this).getDarkThemeSubreddit(subreddit), true);
    getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ColorPreferences(me.ccrama.redditslide.ColorPreferences)

Example 2 with FontPreferences

use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.

the class BaseActivity method applyColorTheme.

/**
 * Applies the activity's base color theme based on the theme of a specific subreddit. Should be
 * called before inflating any layouts.
 *
 * @param subreddit The subreddit to base the theme on
 */
protected void applyColorTheme(String subreddit) {
    getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
    getTheme().applyStyle(new ColorPreferences(this).getThemeSubreddit(subreddit), true);
    getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ColorPreferences(me.ccrama.redditslide.ColorPreferences)

Example 3 with FontPreferences

use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.

the class InboxAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (!(viewHolder instanceof ContributionAdapter.EmptyViewHolder) && !(viewHolder instanceof SpacerViewHolder)) {
        final MessageViewHolder messageViewHolder = (MessageViewHolder) viewHolder;
        final Message comment = dataSet.posts.get(i);
        messageViewHolder.time.setText(TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext));
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String author = comment.getAuthor();
        String direction = "from ";
        if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
            author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
            direction = "to ";
        }
        if (comment.getDataNode().has("subreddit") && author == null || author.isEmpty()) {
            direction = "via /r/" + comment.getSubreddit();
        }
        titleString.append(direction);
        if (author != null) {
            titleString.append(author);
            titleString.append(" ");
            if (UserTags.isUserTagged(author)) {
                SpannableStringBuilder pinned = new SpannableStringBuilder(" " + UserTags.getUserTag(author) + " ");
                pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                titleString.append(pinned);
                titleString.append(" ");
            }
            if (UserSubscriptions.friends.contains(author)) {
                SpannableStringBuilder pinned = new SpannableStringBuilder(" " + mContext.getString(R.string.profile_friend) + " ");
                pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                titleString.append(pinned);
                titleString.append(" ");
            }
        }
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        if (comment.getDataNode().has("subreddit") && !comment.getDataNode().get("subreddit").isNull()) {
            titleString.append(spacer);
            String subname = comment.getDataNode().get("subreddit").asText();
            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);
        }
        messageViewHolder.user.setText(titleString);
        SpannableStringBuilder b = new SpannableStringBuilder();
        if (mContext instanceof Inbox && comment.getCreated().getTime() > ((Inbox) mContext).last && !comment.isRead()) {
            SpannableStringBuilder tagNew = new SpannableStringBuilder("\u00A0NEW\u00A0");
            tagNew.setSpan(new RoundedBackgroundSpan(Color.WHITE, mContext.getResources().getColor(R.color.md_green_400), true, mContext), 0, tagNew.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            b.append(tagNew);
            b.append(" ");
        }
        b.append(comment.getSubject());
        if (comment.getDataNode().has("link_title")) {
            SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
            link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            b.append(link);
        }
        messageViewHolder.title.setText(b);
        if (comment.isRead()) {
            messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
        } else {
            messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
        }
        messageViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                int[] attrs = new int[] { R.attr.tintColor };
                TypedArray ta = mContext.obtainStyledAttributes(attrs);
                final int color = ta.getColor(0, Color.WHITE);
                Drawable profile = mContext.getResources().getDrawable(R.drawable.profile);
                final Drawable reply = mContext.getResources().getDrawable(R.drawable.reply);
                Drawable unhide = mContext.getResources().getDrawable(R.drawable.ic_visibility);
                Drawable hide = mContext.getResources().getDrawable(R.drawable.hide);
                Drawable copy = mContext.getResources().getDrawable(R.drawable.ic_content_copy);
                Drawable reddit = mContext.getResources().getDrawable(R.drawable.commentchange);
                profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                reply.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                unhide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                ta.recycle();
                BottomSheet.Builder b = new BottomSheet.Builder((Activity) mContext).title(Html.fromHtml(comment.getSubject()));
                String author = comment.getAuthor();
                if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
                    author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
                }
                if (comment.getAuthor() != null) {
                    b.sheet(1, profile, "/u/" + author);
                }
                String read = mContext.getString(R.string.mail_mark_read);
                Drawable rDrawable = hide;
                if (comment.isRead()) {
                    read = mContext.getString(R.string.mail_mark_unread);
                    rDrawable = unhide;
                }
                b.sheet(2, rDrawable, read);
                b.sheet(3, reply, mContext.getString(R.string.btn_reply));
                b.sheet(25, copy, mContext.getString(R.string.misc_copy_text));
                if (comment.isComment()) {
                    b.sheet(30, reddit, mContext.getString(R.string.mail_view_full_thread));
                }
                final String finalAuthor = author;
                b.listener(new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch(which) {
                            case 1:
                                {
                                    Intent i = new Intent(mContext, Profile.class);
                                    i.putExtra(Profile.EXTRA_PROFILE, finalAuthor);
                                    mContext.startActivity(i);
                                }
                                break;
                            case 2:
                                {
                                    if (comment.isRead()) {
                                        comment.read = false;
                                        new AsyncSetRead(false).execute(comment);
                                        messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
                                    } else {
                                        comment.read = true;
                                        new AsyncSetRead(true).execute(comment);
                                        messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
                                    }
                                }
                                break;
                            case 3:
                                {
                                    doInboxReply(comment);
                                }
                                break;
                            case 25:
                                {
                                    ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                                    ClipData clip = ClipData.newPlainText("Message", comment.getBody());
                                    clipboard.setPrimaryClip(clip);
                                    Toast.makeText(mContext, mContext.getString(R.string.mail_message_copied), Toast.LENGTH_SHORT).show();
                                }
                                break;
                            case 30:
                                {
                                    String context = comment.getDataNode().get("context").asText();
                                    new OpenRedditLink(mContext, "https://reddit.com" + context.substring(0, context.lastIndexOf("/")));
                                }
                                break;
                        }
                    }
                }).show();
                return true;
            }
        });
        messageViewHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (comment.isRead()) {
                    if (comment instanceof PrivateMessage) {
                        DataShare.sharedMessage = (PrivateMessage) comment;
                        Intent i = new Intent(mContext, SendMessage.class);
                        i.putExtra(SendMessage.EXTRA_NAME, comment.getAuthor());
                        i.putExtra(SendMessage.EXTRA_REPLY, true);
                        mContext.startActivity(i);
                    } else {
                        new OpenRedditLink(mContext, comment.getDataNode().get("context").asText());
                    }
                } else {
                    comment.read = true;
                    new AsyncSetRead(true).execute(comment);
                    messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
                    {
                        SpannableStringBuilder b = new SpannableStringBuilder(comment.getSubject());
                        if (comment.getDataNode().has("link_title")) {
                            SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
                            link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            b.append(link);
                        }
                        messageViewHolder.title.setText(b);
                    }
                }
            }
        });
        // Set typeface for body
        int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (type >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, type);
        } else {
            typeface = Typeface.DEFAULT;
        }
        messageViewHolder.content.setTypeface(typeface);
        setViews(comment.getDataNode().get("body_html").asText(), "FORCE_LINK_CLICK", messageViewHolder);
    }
    if (viewHolder instanceof SpacerViewHolder) {
        viewHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(viewHolder.itemView.getWidth(), ((Activity) mContext).findViewById(R.id.header).getHeight()));
    }
}
Also used : SendMessage(me.ccrama.redditslide.Activities.SendMessage) PrivateMessage(net.dean.jraw.models.PrivateMessage) Message(net.dean.jraw.models.Message) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) TypedArray(android.content.res.TypedArray) PrivateMessage(net.dean.jraw.models.PrivateMessage) Inbox(me.ccrama.redditslide.Activities.Inbox) SendMessage(me.ccrama.redditslide.Activities.SendMessage) ClipboardManager(android.content.ClipboardManager) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Typeface(android.graphics.Typeface) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) RoundedBackgroundSpan(me.ccrama.redditslide.Views.RoundedBackgroundSpan) StyleSpan(android.text.style.StyleSpan) ClipData(android.content.ClipData) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 4 with FontPreferences

use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.

the class SetupWidget method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    disableSwipeBackLayout();
    getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
    getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
    getTheme().applyStyle(new ColorPreferences(this).getFontStyle().getBaseId(), true);
    super.onCreate(savedInstanceState);
    assignAppWidgetId();
    doShortcut();
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ColorPreferences(me.ccrama.redditslide.ColorPreferences)

Example 5 with FontPreferences

use of me.ccrama.redditslide.Visuals.FontPreferences in project Slide by ccrama.

the class ContributionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (firstHolder instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) firstHolder;
        final Submission submission = (Submission) dataSet.posts.get(i);
        CreateCardView.resetColorCard(holder.itemView);
        if (submission.getSubredditName() != null)
            CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                LayoutInflater inflater = mContext.getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(Html.fromHtml(submission.getTitle()));
                ((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
                ((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
                dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSaved()) {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
                        } else {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                        }
                        new AsyncSave(firstHolder.itemView).execute(submission);
                    }
                });
                dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
                if (submission.isSaved()) {
                    ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                }
                dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String urlString = "https://reddit.com" + submission.getPermalink();
                        Intent i = new Intent(mContext, Website.class);
                        i.putExtra(Website.EXTRA_URL, urlString);
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSelfPost()) {
                            if (SettingValues.shareLongLink) {
                                Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
                            } else {
                                Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
                            }
                        } else {
                            new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch(which) {
                                        case R.id.reddit_url:
                                            if (SettingValues.shareLongLink) {
                                                Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
                                            } else {
                                                Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
                                            }
                                            break;
                                        case R.id.link_url:
                                            Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
                                            break;
                                    }
                                }
                            }).show();
                        }
                    }
                });
                if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                    dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                    dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
                }
                title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final int pos = dataSet.posts.indexOf(submission);
                        final Contribution old = dataSet.posts.get(pos);
                        dataSet.posts.remove(submission);
                        notifyItemRemoved(pos + 1);
                        d.dismiss();
                        Hidden.setHidden(old);
                        Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                dataSet.posts.add(pos, old);
                                notifyItemInserted(pos + 1);
                                Hidden.undoHidden(old);
                            }
                        });
                        View view = s.getView();
                        TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                });
                return true;
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
        final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
        if (hideButton != null && isHiddenPost) {
            hideButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final int pos = dataSet.posts.indexOf(submission);
                    final Contribution old = dataSet.posts.get(pos);
                    dataSet.posts.remove(submission);
                    notifyItemRemoved(pos + 1);
                    Hidden.undoHidden(old);
                }
            });
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String url = "www.reddit.com" + submission.getPermalink();
                url = url.replace("?ref=search_posts", "");
                new OpenRedditLink(mContext, url);
                if (SettingValues.storeHistory) {
                    if (SettingValues.storeNSFWHistory && submission.isNsfw() || !submission.isNsfw())
                        HasSeen.addSeen(submission.getFullName());
                }
                notifyItemChanged(pos);
            }
        });
    } else if (firstHolder instanceof ProfileCommentViewHolder) {
        // IS COMMENT
        ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHolder;
        final Comment comment = (Comment) dataSet.posts.get(i);
        String scoreText;
        if (comment.isScoreHidden()) {
            scoreText = "[" + mContext.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", mContext.getResources().getQuantityString(R.plurals.points, comment.getScore())));
        }
        holder.score.setText(score);
        if (Authentication.isLoggedIn) {
            if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
            } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
            } else {
                holder.score.setTextColor(holder.time.getCurrentTextColor());
            }
        }
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
        // some users were crashing here
        String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
        time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
        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(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (type >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, 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 = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
            int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
            a.recycle();
            Bitmap image = BitmapFactory.decodeResource(mContext.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(mContext, 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()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
        holder.content.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
    } else if (firstHolder instanceof SpacerViewHolder) {
        firstHolder.itemView.setLayoutParams(new LinearLayout.LayoutParams(firstHolder.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
        if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
            CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.findViewById(R.id.header).getHeight());
            layoutParams.setFullSpan(true);
            firstHolder.itemView.setLayoutParams(layoutParams);
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Bitmap(android.graphics.Bitmap) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) ImageView(android.widget.ImageView) Comment(net.dean.jraw.models.Comment) Submission(net.dean.jraw.models.Submission) ForegroundColorSpan(android.text.style.ForegroundColorSpan) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Typeface(android.graphics.Typeface) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Contribution(net.dean.jraw.models.Contribution) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) ImageSpan(android.text.style.ImageSpan)

Aggregations

FontPreferences (me.ccrama.redditslide.Visuals.FontPreferences)19 View (android.view.View)9 TypedArray (android.content.res.TypedArray)8 Typeface (android.graphics.Typeface)8 RecyclerView (android.support.v7.widget.RecyclerView)7 SpannableStringBuilder (android.text.SpannableStringBuilder)7 RelativeSizeSpan (android.text.style.RelativeSizeSpan)6 TextView (android.widget.TextView)6 ColorPreferences (me.ccrama.redditslide.ColorPreferences)6 Intent (android.content.Intent)5 Bitmap (android.graphics.Bitmap)5 ForegroundColorSpan (android.text.style.ForegroundColorSpan)5 ImageSpan (android.text.style.ImageSpan)5 StyleSpan (android.text.style.StyleSpan)5 ImageView (android.widget.ImageView)5 LinearLayout (android.widget.LinearLayout)5 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)5 Resources (android.content.res.Resources)4 TypedValue (android.util.TypedValue)4 DialogInterface (android.content.DialogInterface)3