mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Use more precise viewholder type in PostGalleryTypeImageRecyclerViewAdapter (#1229)
This commit is contained in:
parent
44dcf64475
commit
b4c95fe4a5
@ -30,7 +30,7 @@ import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStra
|
|||||||
import ml.docilealligator.infinityforreddit.databinding.ItemGalleryImageInPostFeedBinding;
|
import ml.docilealligator.infinityforreddit.databinding.ItemGalleryImageInPostFeedBinding;
|
||||||
import ml.docilealligator.infinityforreddit.post.Post;
|
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 RequestManager glide;
|
||||||
private Typeface typeface;
|
private Typeface typeface;
|
||||||
private Markwon mPostDetailMarkwon;
|
private Markwon mPostDetailMarkwon;
|
||||||
@ -75,39 +75,37 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@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));
|
return new ImageViewHolder(ItemGalleryImageInPostFeedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
|
||||||
if (holder instanceof ImageViewHolder) {
|
|
||||||
if (ratio < 0) {
|
if (ratio < 0) {
|
||||||
int height = (int) (400 * mScale);
|
int height = (int) (400 * mScale);
|
||||||
((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
holder.binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||||
((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height;
|
holder.binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height;
|
||||||
} else {
|
} else {
|
||||||
((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
|
holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
|
||||||
}
|
}
|
||||||
((ImageViewHolder) holder).binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
|
holder.binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
|
||||||
((ImageViewHolder) holder).binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE);
|
holder.binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
|
holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
|
||||||
|
|
||||||
((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
holder.binding.imageViewItemGalleryImageInPostFeed.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
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);
|
holder.binding.imageViewItemGalleryImageInPostFeed.removeOnLayoutChangeListener(this);
|
||||||
loadImage(((ImageViewHolder) holder));
|
loadImage(holder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (showCaption) {
|
if (showCaption) {
|
||||||
loadCaptionPreview((ImageViewHolder) holder);
|
loadCaptionPreview(holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadImage((ImageViewHolder) holder);
|
loadImage(holder);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,13 +114,11 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull ImageViewHolder holder) {
|
||||||
super.onViewRecycled(holder);
|
super.onViewRecycled(holder);
|
||||||
if (holder instanceof ImageViewHolder) {
|
holder.binding.captionConstraintLayoutItemGalleryImageInPostFeed.setVisibility(View.GONE);
|
||||||
((ImageViewHolder) holder).binding.captionConstraintLayoutItemGalleryImageInPostFeed.setVisibility(View.GONE);
|
holder.binding.captionTextViewItemGalleryImageInPostFeed.setText("");
|
||||||
((ImageViewHolder) holder).binding.captionTextViewItemGalleryImageInPostFeed.setText("");
|
holder.binding.captionUrlTextViewItemGalleryImageInPostFeed.setText("");
|
||||||
((ImageViewHolder) holder).binding.captionUrlTextViewItemGalleryImageInPostFeed.setText("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadImage(ImageViewHolder holder) {
|
private void loadImage(ImageViewHolder holder) {
|
||||||
|
Loading…
Reference in New Issue
Block a user