Search in sources :

Example 1 with ImageSpanTarget

use of io.plaidapp.util.glide.ImageSpanTarget in project plaid by nickbutcher.

the class DesignerNewsStory method bindDescription.

private void bindDescription() {
    final TextView storyComment = (TextView) header.findViewById(R.id.story_comment);
    if (!TextUtils.isEmpty(story.comment)) {
        HtmlUtils.parseMarkdownAndSetText(storyComment, story.comment, markdown, new Bypass.LoadImageCallback() {

            @Override
            public void loadImage(String src, ImageLoadingSpan loadingSpan) {
                Glide.with(DesignerNewsStory.this).load(src).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).into(new ImageSpanTarget(storyComment, loadingSpan));
            }
        });
    } else {
        storyComment.setVisibility(View.GONE);
    }
    upvoteStory = (TextView) header.findViewById(R.id.story_vote_action);
    upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count, NumberFormat.getInstance().format(story.vote_count)));
    upvoteStory.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            upvoteStory();
        }
    });
    final TextView share = (TextView) header.findViewById(R.id.story_share_action);
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url).setType("text/plain").setSubject(story.title).getIntent());
        }
    });
    TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time);
    SpannableString poster = new SpannableString(story.user_display_name.toLowerCase());
    poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job.toLowerCase() : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase();
    storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo));
    ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar);
    if (!TextUtils.isEmpty(story.user_portrait_url)) {
        Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
    } else {
        avatar.setVisibility(View.GONE);
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) ImageSpanTarget(io.plaidapp.util.glide.ImageSpanTarget) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableString(android.text.SpannableString) Bypass(in.uncod.android.bypass.Bypass) ImageLoadingSpan(in.uncod.android.bypass.style.ImageLoadingSpan) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableString (android.text.SpannableString)1 TextAppearanceSpan (android.text.style.TextAppearanceSpan)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 Bypass (in.uncod.android.bypass.Bypass)1 ImageLoadingSpan (in.uncod.android.bypass.style.ImageLoadingSpan)1 AuthorTextView (io.plaidapp.ui.widget.AuthorTextView)1 PinnedOffsetView (io.plaidapp.ui.widget.PinnedOffsetView)1 ImageSpanTarget (io.plaidapp.util.glide.ImageSpanTarget)1