From d34454ef7aeb2a74b7f7ebd2778295212fe76bb0 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:14:52 -0400 Subject: Continue optimizing class structures in PostRecyclerViewAdapter. --- .../adapters/PostRecyclerViewAdapter.java | 1063 ++++++++------------ 1 file changed, 398 insertions(+), 665 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index fc30b293..c13ea749 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -593,148 +593,186 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } + if (post == null) { + return; + } - if (holder.getBindingAdapterPosition() >= 0) { - post.setAuthorIconUrl(iconUrl); - } + if (mDisplaySubredditName) { + if (post.getAuthorNamePrefixed().equals(post.getSubredditNamePrefixed())) { + if (post.getAuthorIconUrl() == null) { + mFragment.loadIcon(post.getAuthor(), false, (subredditOrUserName, iconUrl) -> { + if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) { + if (iconUrl == null || iconUrl.equals("")) { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostViewHolder) holder).iconGifImageView); + } else { + mGlide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostViewHolder) holder).iconGifImageView); } - }); - } else if (!post.getAuthorIconUrl().equals("")) { - mGlide.load(post.getAuthorIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } - } else { - if (post.getSubredditIconUrl() == null) { - mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> { - if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } - if (holder.getBindingAdapterPosition() >= 0) { - post.setSubredditIconUrl(iconUrl); - } + if (holder.getBindingAdapterPosition() >= 0) { + post.setAuthorIconUrl(iconUrl); } - }); - } else if (!post.getSubredditIconUrl().equals("")) { - mGlide.load(post.getSubredditIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostBaseViewHolder) holder).iconGifImageView); - } + } + }); + } else if (!post.getAuthorIconUrl().equals("")) { + mGlide.load(post.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostViewHolder) holder).iconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostViewHolder) holder).iconGifImageView); } } else { - if (post.getAuthorIconUrl() == null) { - String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor(); - mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> { - if (mActivity != null && getItemCount() > 0) { - if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) { + if (post.getSubredditIconUrl() == null) { + mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> { + if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) { + if (iconUrl == null || iconUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostBaseViewHolder) holder).iconGifImageView); + .into(((PostViewHolder) holder).iconGifImageView); } else { mGlide.load(iconUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostBaseViewHolder) holder).iconGifImageView); + .into(((PostViewHolder) holder).iconGifImageView); } if (holder.getBindingAdapterPosition() >= 0) { - post.setAuthorIconUrl(iconUrl); + post.setSubredditIconUrl(iconUrl); } } }); - } else if (!post.getAuthorIconUrl().equals("")) { - mGlide.load(post.getAuthorIconUrl()) + } else if (!post.getSubredditIconUrl().equals("")) { + mGlide.load(post.getSubredditIconUrl()) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostBaseViewHolder) holder).iconGifImageView); + .into(((PostViewHolder) holder).iconGifImageView); } else { mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostBaseViewHolder) holder).iconGifImageView); + .into(((PostViewHolder) holder).iconGifImageView); } } + } else { + if (post.getAuthorIconUrl() == null) { + String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor(); + mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> { + if (mActivity != null && getItemCount() > 0) { + if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostViewHolder) holder).iconGifImageView); + } else { + mGlide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostViewHolder) holder).iconGifImageView); + } - if (mShowElapsedTime) { - ((PostBaseViewHolder) holder).postTimeTextView.setText( - Utils.getElapsedTime(mActivity, post.getPostTimeMillis())); + if (holder.getBindingAdapterPosition() >= 0) { + post.setAuthorIconUrl(iconUrl); + } + } + }); + } else if (!post.getAuthorIconUrl().equals("")) { + mGlide.load(post.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostViewHolder) holder).iconGifImageView); } else { - ((PostBaseViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern)); + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostViewHolder) holder).iconGifImageView); + } + } + + if (mShowElapsedTime) { + ((PostViewHolder) holder).postTimeTextView.setText( + Utils.getElapsedTime(mActivity, post.getPostTimeMillis())); + } else { + ((PostViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern)); + } + + ((PostViewHolder) holder).titleTextView.setText(post.getTitle()); + if (!mHideTheNumberOfVotes) { + ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + } else { + ((PostViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote)); + } + + switch (post.getVoteType()) { + case 1: + //Upvoted + ((PostViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp); + ((PostViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); + break; + case -1: + //Downvoted + ((PostViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp); + ((PostViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); + break; + } + + if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) { + ((PostViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE); + mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostViewHolder) holder).stickiedPostImageView); + } + + if (!mHideTheNumberOfComments) { + ((PostViewHolder) holder).commentsCountButton.setVisibility(View.VISIBLE); + ((PostViewHolder) holder).commentsCountButton.setText(Integer.toString(post.getNComments())); + } else { + ((PostViewHolder) holder).commentsCountButton.setVisibility(View.GONE); + } + + if (post.isSaved()) { + ((PostViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp); + } else { + ((PostViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp); + } + + + + if (holder instanceof PostBaseViewHolder) { + ((PostBaseViewHolder) holder).post = post; + ((PostBaseViewHolder) holder).currentPosition = position; + if (post.isRead()) { + if (((PostBaseViewHolder) holder).itemViewIsNotCardView) { + holder.itemView.setBackgroundColor(mReadPostCardViewBackgroundColor); + } else { + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + } + + ((PostBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor); } - ((PostBaseViewHolder) holder).titleTextView.setText(post.getTitle()); - if (!mHideTheNumberOfVotes) { - ((PostBaseViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + if (mHideSubredditAndUserPrefix) { + ((PostBaseViewHolder) holder).subredditTextView.setText(post.getSubredditName()); + ((PostBaseViewHolder) holder).userTextView.setText(post.getAuthor()); } else { - ((PostBaseViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote)); + ((PostBaseViewHolder) holder).subredditTextView.setText(post.getSubredditNamePrefixed()); + ((PostBaseViewHolder) holder).userTextView.setText(post.getAuthorNamePrefixed()); } + ((PostBaseViewHolder) holder).userTextView.setTextColor( + post.isModerator() ? mModeratorColor : mUsernameColor); + if (post.isLocked()) { ((PostBaseViewHolder) holder).lockedImageView.setVisibility(View.VISIBLE); } @@ -747,7 +785,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } - - if (holder.getBindingAdapterPosition() >= 0) { - post.setAuthorIconUrl(iconUrl); - } - } - }); - } else if (!post.getAuthorIconUrl().equals("")) { - mGlide.load(post.getAuthorIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } - } else { - if (post.getSubredditIconUrl() == null) { - mFragment.loadIcon(subredditName, true, (subredditOrUserName, iconUrl) -> { - if (mActivity != null && getItemCount() > 0 && subredditName.equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } - - if (holder.getBindingAdapterPosition() >= 0) { - post.setSubredditIconUrl(iconUrl); - } - } - }); - } else if (!post.getSubredditIconUrl().equals("")) { - mGlide.load(post.getSubredditIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } - } - ((PostCompactBaseViewHolder) holder).nameTextView.setTextColor(mSubredditColor); if (mHideSubredditAndUserPrefix) { ((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getSubredditName()); } else { - ((PostCompactBaseViewHolder) holder).nameTextView.setText("r/" + post.getSubredditName()); + ((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getSubredditNamePrefixed()); } } else { - if (post.getAuthorIconUrl() == null) { - String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor(); - mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> { - if (mActivity != null && getItemCount() > 0 && authorName.equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } - - if (holder.getBindingAdapterPosition() >= 0) { - post.setAuthorIconUrl(iconUrl); - } - } - }); - } else if (!post.getAuthorIconUrl().equals("")) { - mGlide.load(post.getAuthorIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostCompactBaseViewHolder) holder).iconGifImageView); - } - ((PostCompactBaseViewHolder) holder).nameTextView.setTextColor( post.isModerator() ? mModeratorColor : mUsernameColor); if (mHideSubredditAndUserPrefix) { ((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getAuthor()); } else { - ((PostCompactBaseViewHolder) holder).nameTextView.setText(authorPrefixed); + ((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getAuthorNamePrefixed()); } } - if (mShowElapsedTime) { - ((PostCompactBaseViewHolder) holder).postTimeTextView.setText( - Utils.getElapsedTime(mActivity, post.getPostTimeMillis())); - } else { - ((PostCompactBaseViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern)); - } - if (mCompactLayoutToolbarHiddenByDefault) { ViewGroup.LayoutParams params = ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams(); params.height = 0; @@ -1149,13 +1042,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } - - if (holder.getBindingAdapterPosition() >= 0) { - post.setAuthorIconUrl(iconUrl); - } - } - }); - } else if (!post.getAuthorIconUrl().equals("")) { - mGlide.load(post.getAuthorIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } - } else { - if (post.getSubredditIconUrl() == null) { - mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> { - if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) { - if (iconUrl == null || iconUrl.equals("")) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } - - if (holder.getBindingAdapterPosition() >= 0) { - post.setSubredditIconUrl(iconUrl); - } - } - }); - } else if (!post.getSubredditIconUrl().equals("")) { - mGlide.load(post.getSubredditIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } - } - } else { - if (post.getAuthorIconUrl() == null) { - String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor(); - mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> { - if (mActivity != null && getItemCount() > 0) { - if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(iconUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } - - if (holder.getBindingAdapterPosition() >= 0) { - post.setAuthorIconUrl(iconUrl); - } - } - }); - } else if (!post.getAuthorIconUrl().equals("")) { - mGlide.load(post.getAuthorIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - } + ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gallery); + if (mDataSavingMode && mDisableImagePreview) { + ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE); + ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_day_night_24dp); + } else { + ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE); + ((PostCompactBaseViewHolder) holder).playButtonImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_day_night_24dp)); + } + break; + case Post.TEXT_TYPE: + ((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.text); + break; } - if (mShowElapsedTime) { - ((PostMaterial3CardBaseViewHolder) holder).postTimeTextView.setText( - Utils.getElapsedTime(mActivity, post.getPostTimeMillis())); - } else { - ((PostMaterial3CardBaseViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern)); + mCallback.currentlyBindItem(holder.getBindingAdapterPosition()); + } else if (holder instanceof PostMaterial3CardBaseViewHolder) { + ((PostMaterial3CardBaseViewHolder) holder).post = post; + ((PostMaterial3CardBaseViewHolder) holder).currentPosition = position; + if (post.isRead()) { + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostFilledCardViewBackgroundColor)); + ((PostMaterial3CardBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor); } - ((PostMaterial3CardBaseViewHolder) holder).titleTextView.setText(post.getTitle()); - if (!mHideTheNumberOfVotes) { - ((PostMaterial3CardBaseViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + if (mHideSubredditAndUserPrefix) { + ((PostMaterial3CardBaseViewHolder) holder).subredditTextView.setText(post.getSubredditName()); + ((PostMaterial3CardBaseViewHolder) holder).userTextView.setText(post.getAuthor()); } else { - ((PostMaterial3CardBaseViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote)); - } - - switch (post.getVoteType()) { - case 1: - //Upvoted - ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp); - ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor)); - ((PostMaterial3CardBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); - break; - case -1: - //Downvoted - ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp); - ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor)); - ((PostMaterial3CardBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); - break; + ((PostMaterial3CardBaseViewHolder) holder).subredditTextView.setText(post.getSubredditNamePrefixed()); + ((PostMaterial3CardBaseViewHolder) holder).userTextView.setText(post.getAuthorNamePrefixed()); } - if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) { - ((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE); - mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView); - } + ((PostMaterial3CardBaseViewHolder) holder).userTextView.setTextColor( + post.isModerator() ? mModeratorColor : mUsernameColor); if (post.isArchived()) { ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor)); @@ -1660,19 +1184,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter