diff options
author | Sergei Kozelko <KozelkoS@yandex.ru> | 2022-11-27 12:25:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 12:25:20 +0000 |
commit | b4c95fe4a56e2ad8442382869cfb8db097ec4cb7 (patch) | |
tree | 4d65d37d81c87b2df4b2011a20b3249b89266fee /app/src/main | |
parent | 44dcf644751897673147cdd18a8beb3ce762de65 (diff) | |
download | infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.tar infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.tar.gz infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.tar.bz2 infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.tar.lz infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.tar.xz infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.tar.zst infinity-for-reddit-b4c95fe4a56e2ad8442382869cfb8db097ec4cb7.zip |
Use more precise viewholder type in PostGalleryTypeImageRecyclerViewAdapter (#1229)
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java index daabf9a1..97b2ad5f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java @@ -30,7 +30,7 @@ import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStra import ml.docilealligator.infinityforreddit.databinding.ItemGalleryImageInPostFeedBinding; import ml.docilealligator.infinityforreddit.post.Post; -public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { +public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapter<PostGalleryTypeImageRecyclerViewAdapter.ImageViewHolder> { private RequestManager glide; private Typeface typeface; private Markwon mPostDetailMarkwon; @@ -75,39 +75,37 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return new ImageViewHolder(ItemGalleryImageInPostFeedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ImageViewHolder) { - if (ratio < 0) { - int height = (int) (400 * mScale); - ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height; - } else { - ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); - } - ((ImageViewHolder) holder).binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); - ((ImageViewHolder) holder).binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); - - ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); + public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) { + if (ratio < 0) { + int height = (int) (400 * mScale); + holder.binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP); + holder.binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height; + } else { + holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); + } + holder.binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); + holder.binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); - ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.removeOnLayoutChangeListener(this); - loadImage(((ImageViewHolder) holder)); - } - }); + holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); - if (showCaption) { - loadCaptionPreview((ImageViewHolder) holder); + holder.binding.imageViewItemGalleryImageInPostFeed.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { + holder.binding.imageViewItemGalleryImageInPostFeed.removeOnLayoutChangeListener(this); + loadImage(holder); } + }); - loadImage((ImageViewHolder) holder); + if (showCaption) { + loadCaptionPreview(holder); } + + loadImage(holder); } @Override @@ -116,13 +114,11 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte } @Override - public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { + public void onViewRecycled(@NonNull ImageViewHolder holder) { super.onViewRecycled(holder); - if (holder instanceof ImageViewHolder) { - ((ImageViewHolder) holder).binding.captionConstraintLayoutItemGalleryImageInPostFeed.setVisibility(View.GONE); - ((ImageViewHolder) holder).binding.captionTextViewItemGalleryImageInPostFeed.setText(""); - ((ImageViewHolder) holder).binding.captionUrlTextViewItemGalleryImageInPostFeed.setText(""); - } + holder.binding.captionConstraintLayoutItemGalleryImageInPostFeed.setVisibility(View.GONE); + holder.binding.captionTextViewItemGalleryImageInPostFeed.setText(""); + holder.binding.captionUrlTextViewItemGalleryImageInPostFeed.setText(""); } private void loadImage(ImageViewHolder holder) { |