use of io.plaidapp.ui.recyclerview.InsetDividerDecoration in project plaid by nickbutcher.
the class DribbbleShot method bindShot.
void bindShot(final boolean postponeEnterTransition) {
final Resources res = getResources();
// load the main image
final int[] imageSize = shot.images.bestSize();
Glide.with(this).load(shot.images.best()).listener(shotLoadListener).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE).override(imageSize[0], imageSize[1]).into(imageView);
imageView.setOnClickListener(shotClick);
shotSpacer.setOnClickListener(shotClick);
if (postponeEnterTransition)
postponeEnterTransition();
imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
imageView.getViewTreeObserver().removeOnPreDrawListener(this);
calculateFabPosition();
if (postponeEnterTransition)
startPostponedEnterTransition();
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
((FabOverlapTextView) title).setText(shot.title);
} else {
((TextView) title).setText(shot.title);
}
if (!TextUtils.isEmpty(shot.description)) {
final Spanned descText = shot.getParsedDescription(ContextCompat.getColorStateList(this, R.color.dribbble_links), ContextCompat.getColor(this, R.color.dribbble_link_highlight));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
((FabOverlapTextView) description).setText(descText);
} else {
HtmlUtils.setTextWithNiceLinks((TextView) description, descText);
}
} else {
description.setVisibility(View.GONE);
}
NumberFormat nf = NumberFormat.getInstance();
likeCount.setText(res.getQuantityString(R.plurals.likes, (int) shot.likes_count, nf.format(shot.likes_count)));
likeCount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((AnimatedVectorDrawable) likeCount.getCompoundDrawables()[1]).start();
if (shot.likes_count > 0) {
PlayerSheet.start(DribbbleShot.this, shot);
}
}
});
if (shot.likes_count == 0) {
// clear touch ripple if doesn't do anything
likeCount.setBackground(null);
}
viewCount.setText(res.getQuantityString(R.plurals.views, (int) shot.views_count, nf.format(shot.views_count)));
viewCount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((AnimatedVectorDrawable) viewCount.getCompoundDrawables()[1]).start();
}
});
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
new ShareDribbbleImageTask(DribbbleShot.this, shot).execute();
}
});
if (shot.user != null) {
playerName.setText(shot.user.name.toLowerCase());
Glide.with(this).load(shot.user.getHighQualityAvatarUrl()).transform(circleTransform).placeholder(R.drawable.avatar_placeholder).override(largeAvatarSize, largeAvatarSize).into(playerAvatar);
View.OnClickListener playerClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent player = new Intent(DribbbleShot.this, PlayerActivity.class);
if (shot.user.shots_count > 0) {
// legit user object
player.putExtra(PlayerActivity.EXTRA_PLAYER, shot.user);
} else {
// search doesn't fully populate the user object,
// in this case send the ID not the full user
player.putExtra(PlayerActivity.EXTRA_PLAYER_NAME, shot.user.username);
player.putExtra(PlayerActivity.EXTRA_PLAYER_ID, shot.user.id);
}
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this, playerAvatar, getString(R.string.transition_player_avatar));
startActivity(player, options.toBundle());
}
};
playerAvatar.setOnClickListener(playerClick);
playerName.setOnClickListener(playerClick);
if (shot.created_at != null) {
shotTimeAgo.setText(DateUtils.getRelativeTimeSpanString(shot.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase());
}
} else {
playerName.setVisibility(View.GONE);
playerAvatar.setVisibility(View.GONE);
shotTimeAgo.setVisibility(View.GONE);
}
commentAnimator = new CommentAnimator();
commentsList.setItemAnimator(commentAnimator);
adapter = new CommentsAdapter(shotDescription, commentFooter, shot.comments_count, getResources().getInteger(R.integer.comment_expand_collapse_duration));
commentsList.setAdapter(adapter);
commentsList.addItemDecoration(new InsetDividerDecoration(CommentViewHolder.class, res.getDimensionPixelSize(R.dimen.divider_height), res.getDimensionPixelSize(R.dimen.keyline_1), ContextCompat.getColor(this, R.color.divider)));
if (shot.comments_count != 0) {
loadComments();
}
checkLiked();
}
Aggregations