From 2bfb0a0bcf35c567a96b8e7757b5ca02da4799ba Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Fri, 27 Sep 2024 18:05:09 -0400 Subject: Continue optimizing class structures in PostRecyclerViewAdapter. --- .../adapters/PostRecyclerViewAdapter.java | 1575 ++++++-------------- .../infinityforreddit/fragments/PostFragment.java | 3 +- 2 files changed, 449 insertions(+), 1129 deletions(-) (limited to 'app/src') 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 3a41b87f..fadba1a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -602,6 +602,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter imageRequestBuilder = mGlide.load(url).listener(((PostMaterial3CardWithPreviewViewHolder) holder).glideRequestListener); - - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostCard3WithPreview); - } else { - imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostCard3WithPreview); - } - } } } @@ -1714,98 +1505,92 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter= 0) { Post post = getItem(position); - ((PostBaseViewHolder) holder).markPostRead(post, false); + ((PostViewHolder) holder).markPostRead(post, false); } } - if (((PostBaseViewHolder) holder).itemViewIsNotCardView) { - holder.itemView.setBackgroundColor(mCardViewBackgroundColor); - } else { - holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + + ((PostViewHolder) holder).setItemViewBackgroundColor(false); + + ((PostViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); + mGlide.clear(((PostViewHolder) holder).iconGifImageView); + + ((PostViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE); + + if (((PostViewHolder) holder).crosspostImageView != null) { + ((PostViewHolder) holder).crosspostImageView.setVisibility(View.GONE); } - mGlide.clear(((PostBaseViewHolder) holder).iconGifImageView); - ((PostBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); - if (holder instanceof PostBaseVideoAutoplayViewHolder) { - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.mediaUri = null; - if (((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall != null - && !((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall.isCanceled()) { - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall.cancel(); - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall = null; - } - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.errorLoadingRedgifsImageView.setVisibility(View.GONE); - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.muteButton.setVisibility(View.GONE); - if (!((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.isManuallyPaused) { - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.resetVolume(); - } - mGlide.clear(((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.previewImageView); - ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.previewImageView.setVisibility(View.GONE); - } else if (holder instanceof PostWithPreviewTypeViewHolder) { - mGlide.clear(((PostWithPreviewTypeViewHolder) holder).imageView); - ((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).loadImageErrorTextView.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).imageViewNoPreviewGallery.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicator.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).linkTextView.setVisibility(View.GONE); - } else if (holder instanceof PostBaseGalleryTypeViewHolder) { - ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); - ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); - ((PostBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(null); - } else if (holder instanceof PostTextTypeViewHolder) { - ((PostTextTypeViewHolder) holder).contentTextView.setText(""); - ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); - ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.GONE); + if (((PostViewHolder) holder).archivedImageView != null) { + ((PostViewHolder) holder).archivedImageView.setVisibility(View.GONE); + } + if (((PostViewHolder) holder).lockedImageView != null) { + ((PostViewHolder) holder).lockedImageView.setVisibility(View.GONE); + } + if (((PostViewHolder) holder).nsfwTextView != null) { + ((PostViewHolder) holder).nsfwTextView.setVisibility(View.GONE); + } + if (((PostViewHolder) holder).spoilerTextView != null) { + ((PostViewHolder) holder).spoilerTextView.setVisibility(View.GONE); + } + if (((PostViewHolder) holder).flairTextView != null) { + ((PostViewHolder) holder).flairTextView.setText(""); + ((PostViewHolder) holder).flairTextView.setVisibility(View.GONE); } - mGlide.clear(((PostBaseViewHolder) holder).iconGifImageView); - ((PostBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).crosspostImageView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).archivedImageView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).lockedImageView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).nsfwTextView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).spoilerTextView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).flairTextView.setText(""); - ((PostBaseViewHolder) holder).flairTextView.setVisibility(View.GONE); - ((PostBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp); - ((PostBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); - ((PostBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor); - ((PostBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp); - ((PostBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); - } else if (holder instanceof PostCompactBaseViewHolder) { - if (mMarkPostsAsReadOnScroll) { - int position = ((PostCompactBaseViewHolder) holder).currentPosition; - if (position < getItemCount() && position >= 0) { - Post post = getItem(position); - ((PostCompactBaseViewHolder) holder).markPostRead(post, false); + ((PostViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp); + ((PostViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor); + ((PostViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp); + ((PostViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); + + if (holder instanceof PostBaseViewHolder) { + if (holder instanceof PostBaseVideoAutoplayViewHolder) { + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.mediaUri = null; + if (((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall != null + && !((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall.isCanceled()) { + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall.cancel(); + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall = null; + } + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.errorLoadingRedgifsImageView.setVisibility(View.GONE); + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.muteButton.setVisibility(View.GONE); + if (!((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.isManuallyPaused) { + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.resetVolume(); + } + mGlide.clear(((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.previewImageView); + ((PostBaseVideoAutoplayViewHolder) holder).toroPlayer.previewImageView.setVisibility(View.GONE); + } else if (holder instanceof PostWithPreviewTypeViewHolder) { + mGlide.clear(((PostWithPreviewTypeViewHolder) holder).imageView); + if (((PostWithPreviewTypeViewHolder) holder).imageWrapperFrameLayout != null) { + ((PostWithPreviewTypeViewHolder) holder).imageWrapperFrameLayout.setVisibility(View.GONE); + } + ((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).loadImageErrorTextView.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).imageViewNoPreviewGallery.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicator.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).linkTextView.setVisibility(View.GONE); + } else if (holder instanceof PostBaseGalleryTypeViewHolder) { + ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); + ((PostBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(null); + } else if (holder instanceof PostTextTypeViewHolder) { + ((PostTextTypeViewHolder) holder).contentTextView.setText(""); + ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); + ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.GONE); } + } else if (holder instanceof PostCompactBaseViewHolder) { + mGlide.clear(((PostCompactBaseViewHolder) holder).imageView); + ((PostCompactBaseViewHolder) holder).relativeLayout.setVisibility(View.GONE); + ((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.GONE); + ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.GONE); + ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.GONE); + ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.GONE); } - holder.itemView.setBackgroundColor(mCardViewBackgroundColor); - ((PostCompactBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); - mGlide.clear(((PostCompactBaseViewHolder) holder).imageView); - mGlide.clear(((PostCompactBaseViewHolder) holder).iconGifImageView); - ((PostCompactBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).relativeLayout.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).crosspostImageView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).archivedImageView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).lockedImageView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).nsfwTextView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).spoilerTextView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).flairTextView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).flairTextView.setText(""); - ((PostCompactBaseViewHolder) holder).linkTextView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.GONE); - ((PostCompactBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp); - ((PostCompactBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); - ((PostCompactBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor); - ((PostCompactBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp); - ((PostCompactBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); } else if (holder instanceof PostGalleryViewHolder) { if (mMarkPostsAsReadOnScroll) { int position = ((PostGalleryViewHolder) holder).currentPosition; @@ -1835,56 +1620,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter= 0) { - Post post = getItem(position); - ((PostMaterial3CardBaseViewHolder) holder).markPostRead(post, false); - } - } - holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mFilledCardViewBackgroundColor)); - mGlide.clear(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - ((PostMaterial3CardBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); - if (holder instanceof PostMaterial3CardBaseVideoAutoplayViewHolder) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.mediaUri = null; - if (((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall != null && !((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall.isCanceled()) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall.cancel(); - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.fetchRedgifsOrStreamableVideoCall = null; - } - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.errorLoadingRedgifsImageView.setVisibility(View.GONE); - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.muteButton.setVisibility(View.GONE); - if (!((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.isManuallyPaused) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.resetVolume(); - } - mGlide.clear(((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.previewImageView); - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).toroPlayer.previewImageView.setVisibility(View.GONE); - } else if (holder instanceof PostMaterial3CardWithPreviewViewHolder) { - mGlide.clear(((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostCard3WithPreview); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostCard3WithPreview.setVisibility(View.GONE); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageWrapperRelativeLayoutItemPostCard3WithPreview.setVisibility(View.GONE); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.loadImageErrorTextViewItemPostCard3WithPreview.setVisibility(View.GONE); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostCard3WithPreview.setVisibility(View.GONE); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.progressBarItemPostCard3WithPreview.setVisibility(View.GONE); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostCard3WithPreview.setVisibility(View.GONE); - ((PostMaterial3CardWithPreviewViewHolder) holder).binding.linkTextViewItemPostCard3WithPreview.setVisibility(View.GONE); - } else if (holder instanceof PostMaterial3CardBaseGalleryTypeViewHolder) { - ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); - ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); - ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(null); - } else if (holder instanceof PostMaterial3CardTextTypeViewHolder) { - ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setText(""); - ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setTextColor(mPostContentColor); - ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setVisibility(View.GONE); - } - - mGlide.clear(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); - ((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE); - ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp); - ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); - ((PostMaterial3CardBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor); - ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp); - ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); } } @@ -2063,6 +1798,22 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - if (canStartActivity) { - canStartActivity = false; - Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, - post.getSubredditName()); - mActivity.startActivity(intent); - } - } - }); - - iconGifImageView.setOnClickListener(view -> subredditTextView.performClick()); - } else { - subredditTextView.setOnClickListener(view -> { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - if (canStartActivity) { - canStartActivity = false; - Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, - post.getSubredditName()); - mActivity.startActivity(intent); - } - } - }); - - iconGifImageView.setOnClickListener(view -> userTextView.performClick()); - } - - userTextView.setOnClickListener(view -> { - if (!canStartActivity) { - return; - } - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post == null || post.isAuthorDeleted()) { - return; - } - canStartActivity = false; - Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor()); - mActivity.startActivity(intent); - }); - - setOnClickListeners(typeTextView, - nsfwTextView, - flairTextView, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountButton, - saveButton, - shareButton); - } - - void setBaseView(AspectRatioGifImageView iconGifImageView, - TextView nameTextView, - ImageView stickiedPostImageView, - TextView postTimeTextView, - TextView titleTextView, - CustomTextView typeTextView, - CustomTextView nsfwTextView, - CustomTextView flairTextView, + @Nullable CustomTextView typeTextView, + @Nullable CustomTextView nsfwTextView, + @Nullable CustomTextView flairTextView, MaterialButton upvoteButton, TextView scoreTextView, MaterialButton downvoteButton, @@ -2655,9 +2330,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - mCallback.nsfwChipClicked(); - } - }); - typeTextView.setOnClickListener(view -> { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - mCallback.typeChipClicked(post.getPostType()); - } - }); + if (nsfwTextView != null) { + nsfwTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + mCallback.nsfwChipClicked(); + } + }); + } - flairTextView.setOnClickListener(view -> { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - mCallback.flairChipClicked(post.getFlair()); - } - }); + if (typeTextView != null) { + typeTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + mCallback.typeChipClicked(post.getPostType()); + } + }); + } + + if (flairTextView != null) { + flairTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + mCallback.flairChipClicked(post.getFlair()); + } + }); + } } } + abstract void setItemViewBackgroundColor(boolean isReadPost); abstract void markPostRead(Post post, boolean changePostItemColor); } @@ -3026,24 +2709,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter glideRequestListener; @@ -3479,6 +3148,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter glideRequestListener; + @Override + void setItemViewBackgroundColor(boolean isReadPost) { + itemView.setBackgroundTintList(ColorStateList.valueOf(isReadPost ? mReadPostFilledCardViewBackgroundColor : mFilledCardViewBackgroundColor)); + } + } + public class PostMaterial3CardWithPreviewViewHolder extends PostWithPreviewTypeViewHolder { PostMaterial3CardWithPreviewViewHolder(@NonNull ItemPostCard3WithPreviewBinding binding) { super(binding.getRoot()); - this.binding = binding; setBaseView(binding.iconGifImageViewItemPostCard3WithPreview, binding.subredditNameTextViewItemPostCard3WithPreview, binding.userTextViewItemPostCard3WithPreview, binding.stickiedPostImageViewItemPostCard3WithPreview, binding.postTimeTextViewItemPostCard3WithPreview, binding.titleTextViewItemPostCard3WithPreview, + null, + null, + null, + null, + null, + null, + null, binding.bottomConstraintLayoutItemPostCard3WithPreview, binding.upvoteButtonItemPostCard3WithPreview, binding.scoreTextViewItemPostCard3WithPreview, binding.downvoteButtonItemPostCard3WithPreview, binding.commentsCountButtonItemPostCard3WithPreview, binding.saveButtonItemPostCard3WithPreview, - binding.shareButtonItemPostCard3WithPreview); - - if (mActivity.typeface != null) { - binding.linkTextViewItemPostCard3WithPreview.setTypeface(mActivity.typeface); - binding.loadImageErrorTextViewItemPostCard3WithPreview.setTypeface(mActivity.typeface); - } - binding.linkTextViewItemPostCard3WithPreview.setTextColor(mSecondaryTextColor); - binding.imageViewNoPreviewGalleryItemPostCard3WithPreview.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); - binding.imageViewNoPreviewGalleryItemPostCard3WithPreview.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); - binding.progressBarItemPostCard3WithPreview.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); - binding.videoOrGifIndicatorImageViewItemPostCard3WithPreview.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); - binding.videoOrGifIndicatorImageViewItemPostCard3WithPreview.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); - binding.loadImageErrorTextViewItemPostCard3WithPreview.setTextColor(mPrimaryTextColor); - - binding.imageViewItemPostCard3WithPreview.setOnClickListener(view -> { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - markPostRead(post, true); - openMedia(post); - } - }); - - binding.loadImageErrorTextViewItemPostCard3WithPreview.setOnClickListener(view -> { - binding.progressBarItemPostCard3WithPreview.setVisibility(View.VISIBLE); - binding.loadImageErrorTextViewItemPostCard3WithPreview.setVisibility(View.GONE); - loadImage(this); - }); - - binding.imageViewNoPreviewGalleryItemPostCard3WithPreview.setOnClickListener(view -> { - binding.imageViewItemPostCard3WithPreview.performClick(); - }); - - glideRequestListener = new RequestListener<>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - binding.progressBarItemPostCard3WithPreview.setVisibility(View.GONE); - binding.loadImageErrorTextViewItemPostCard3WithPreview.setVisibility(View.VISIBLE); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - binding.loadImageErrorTextViewItemPostCard3WithPreview.setVisibility(View.GONE); - binding.progressBarItemPostCard3WithPreview.setVisibility(View.GONE); - return false; - } - }; - } - } - - public class PostMaterial3CardBaseGalleryTypeViewHolder extends PostMaterial3CardBaseViewHolder { - FrameLayout frameLayout; - RecyclerView galleryRecyclerView; - CustomTextView imageIndexTextView; - ImageView noPreviewImageView; - - PostGalleryTypeImageRecyclerViewAdapter adapter; - private boolean swipeLocked; - - PostMaterial3CardBaseGalleryTypeViewHolder(View rootView, - AspectRatioGifImageView iconGifImageView, - TextView subredditTextView, - TextView userTextView, - ImageView stickiedPostImageView, - TextView postTimeTextView, - TextView titleTextView, - FrameLayout frameLayout, - RecyclerView galleryRecyclerView, - CustomTextView imageIndexTextView, - ImageView noPreviewImageView, - ConstraintLayout bottomConstraintLayout, - MaterialButton upvoteButton, - TextView scoreTextView, - MaterialButton downvoteButton, - MaterialButton commentsCountButton, - MaterialButton saveButton, - MaterialButton shareButton) { - super(rootView); - setBaseView( - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountButton, - saveButton, - shareButton); - - this.frameLayout = frameLayout; - this.galleryRecyclerView = galleryRecyclerView; - this.imageIndexTextView = imageIndexTextView; - this.noPreviewImageView = noPreviewImageView; - - imageIndexTextView.setTextColor(mMediaIndicatorIconTint); - imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor); - imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor); - if (mActivity.typeface != null) { - imageIndexTextView.setTypeface(mActivity.typeface); - } - - noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); - noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); - - adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, - mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); - galleryRecyclerView.setAdapter(adapter); - galleryRecyclerView.setOnTouchListener((v, motionEvent) -> { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { - if (mActivity.mSliderPanel != null) { - mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); - } - - if (mActivity.mViewPager2 != null) { - mActivity.mViewPager2.setUserInputEnabled(true); - } - mActivity.unlockSwipeRightToGoBack(); - swipeLocked = false; - } else { - if (mActivity.mSliderPanel != null) { - mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); - } - if (mActivity.mViewPager2 != null) { - mActivity.mViewPager2.setUserInputEnabled(false); - } - mActivity.lockSwipeRightToGoBack(); - swipeLocked = true; - } - - return false; - }); - new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); - galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); - LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false); - galleryRecyclerView.setLayoutManager(layoutManager); - galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - } - - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); - } - }); - galleryRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { - private float downX; - private float downY; - private boolean dragged; - private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); - - @Override - public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { - int action = e.getAction(); - switch (action) { - case MotionEvent.ACTION_DOWN: - downX = e.getRawX(); - downY = e.getRawY(); - break; - case MotionEvent.ACTION_MOVE: - if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { - dragged = true; - } - break; - case MotionEvent.ACTION_UP: - if (!dragged) { - int position = getBindingAdapterPosition(); - if (position >= 0) { - if (post != null) { - markPostRead(post, true); - openMedia(post, layoutManager.findFirstVisibleItemPosition()); - } - } - } - - downX = 0; - downY = 0; - dragged = false; - } - return false; - } - - @Override - public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { - - } - - @Override - public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { - - } - }); - - noPreviewImageView.setOnClickListener(view -> { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - if (post != null) { - markPostRead(post, true); - openMedia(post, 0); - } - }); + binding.shareButtonItemPostCard3WithPreview, + binding.linkTextViewItemPostCard3WithPreview, + binding.imageViewNoPreviewGalleryItemPostCard3WithPreview, + binding.progressBarItemPostCard3WithPreview, + binding.videoOrGifIndicatorImageViewItemPostCard3WithPreview, + binding.loadImageErrorTextViewItemPostCard3WithPreview, + binding.imageWrapperRelativeLayoutItemPostCard3WithPreview, + binding.imageViewItemPostCard3WithPreview); } - public boolean isSwipeLocked() { - return swipeLocked; + @Override + void setItemViewBackgroundColor(boolean isReadPost) { + itemView.setBackgroundTintList(ColorStateList.valueOf(isReadPost ? mReadPostFilledCardViewBackgroundColor : mFilledCardViewBackgroundColor)); } } - public class PostMaterial3CardGalleryTypeViewHolder extends PostMaterial3CardBaseGalleryTypeViewHolder { - + public class PostMaterial3CardGalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { PostMaterial3CardGalleryTypeViewHolder(ItemPostCard3GalleryTypeBinding binding) { super(binding.getRoot(), binding.iconGifImageViewItemPostCard3GalleryType, @@ -5205,6 +4510,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter