From 0a9d567c089db99d837e627899b7732328d4ced3 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Thu, 26 Sep 2024 22:10:26 -0400 Subject: Continue optimizing class structures in PostRecyclerViewAdapter. PostCard2WithPreviewViewHolder now extends PostWithPreviewTypeViewHolder. --- .../adapters/PostRecyclerViewAdapter.java | 266 +++++++++++---------- 1 file changed, 145 insertions(+), 121 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 84faa827..14d0fb90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -879,81 +879,80 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener); if (blurImage) { imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostWithPreviewTypeViewHolder) holder).binding.imageViewItemPostWithPreview); + .into(((PostWithPreviewTypeViewHolder) holder).imageView); } else { - imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).binding.imageViewItemPostWithPreview); + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView); } } } else if (holder instanceof PostCompactBaseViewHolder) { @@ -2048,7 +2047,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter imageRequestBuilder = mGlide.load(url).listener(((PostCard2WithPreviewViewHolder) holder).requestListener); + RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostCard2WithPreviewViewHolder) holder).glideRequestListener); if (blurImage) { imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) @@ -2269,14 +2268,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter glideRequestListener; + PostWithPreviewTypeViewHolder(@NonNull View itemView) { + super(itemView); + } + PostWithPreviewTypeViewHolder(@NonNull ItemPostWithPreviewBinding binding) { super(binding.getRoot()); - this.binding = binding; setBaseView( binding.iconGifImageViewItemPostWithPreview, binding.subredditNameTextViewItemPostWithPreview, @@ -3915,21 +3921,83 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { + linkTextView.setTextColor(mSecondaryTextColor); + imageViewNoPreviewGallery.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + imageViewNoPreviewGallery.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + videoOrGifIndicator.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); + videoOrGifIndicator.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); + loadImageErrorTextView.setTextColor(mPrimaryTextColor); + + imageView.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position < 0) { return; @@ -3941,28 +4009,28 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - binding.progressBarItemPostWithPreview.setVisibility(View.VISIBLE); - binding.loadImageErrorTextViewItemPostWithPreview.setVisibility(View.GONE); + loadImageErrorTextView.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + loadImageErrorTextView.setVisibility(View.GONE); loadImage(this); }); - binding.imageViewNoPreviewGalleryItemPostWithPreview.setOnClickListener(view -> { - binding.imageViewItemPostWithPreview.performClick(); + imageViewNoPreviewGallery.setOnClickListener(view -> { + imageView.performClick(); }); glideRequestListener = new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - binding.progressBarItemPostWithPreview.setVisibility(View.GONE); - binding.loadImageErrorTextViewItemPostWithPreview.setVisibility(View.VISIBLE); + progressBar.setVisibility(View.GONE); + loadImageErrorTextView.setVisibility(View.VISIBLE); return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - binding.loadImageErrorTextViewItemPostWithPreview.setVisibility(View.GONE); - binding.progressBarItemPostWithPreview.setVisibility(View.GONE); + loadImageErrorTextView.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); return false; } }; @@ -4924,13 +4992,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter requestListener; PostCard2WithPreviewViewHolder(@NonNull ItemPostCard2WithPreviewBinding binding) { super(binding.getRoot()); this.binding = binding; + this.itemViewIsNotCardView = true; setBaseView( binding.iconGifImageViewItemPostCard2WithPreview, binding.subredditNameTextViewItemPostCard2WithPreview, @@ -4952,58 +5020,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - markPostRead(post, true); - openMedia(post); - } - }); - - binding.loadImageErrorTextViewItemPostCard2WithPreview.setOnClickListener(view -> { - binding.progressBarItemPostCard2WithPreview.setVisibility(View.VISIBLE); - binding.loadImageErrorTextViewItemPostCard2WithPreview.setVisibility(View.GONE); - loadImage(this); - }); - - binding.imageViewNoPreviewGalleryItemPostCard2WithPreview.setOnClickListener(view -> { - binding.imageViewItemPostCard2WithPreview.performClick(); - }); - - requestListener = new RequestListener<>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - binding.progressBarItemPostCard2WithPreview.setVisibility(View.GONE); - binding.loadImageErrorTextViewItemPostCard2WithPreview.setVisibility(View.VISIBLE); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - binding.loadImageErrorTextViewItemPostCard2WithPreview.setVisibility(View.GONE); - binding.progressBarItemPostCard2WithPreview.setVisibility(View.GONE); - return false; - } - }; } } -- cgit v1.2.3