| | |
| | | import com.bumptech.glide.load.resource.bitmap.CenterCrop; |
| | | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| | | import com.dayu.pipirrapp.R; |
| | | import com.dayu.pipirrapp.bean.ImageBean; |
| | | import com.dayu.pipirrapp.bean.net.ImageResult; |
| | | import com.dayu.pipirrapp.bean.net.UplodFileState; |
| | | import com.dayu.pipirrapp.tool.GlideEngine; |
| | | |
| | | import java.util.List; |
| | |
| | | * @since 2024-11-27 |
| | | */ |
| | | public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> { |
| | | private List<ImageResult> imageUrls; // 图片的 URL 或本地路径 |
| | | private List<ImageBean> imageUrls; // 图片的 URL 或本地路径 |
| | | private Context mContext; |
| | | private OnItemClickListener onItemClickListener; |
| | | |
| | | // 构造方法 |
| | | public ImageAdapter(Context context, List<ImageResult> imageUrls, OnItemClickListener onItemClickListener) { |
| | | public ImageAdapter(Context context, List<ImageBean> imageUrls, OnItemClickListener onItemClickListener) { |
| | | this.imageUrls = imageUrls; |
| | | this.mContext = context; |
| | | this.onItemClickListener = onItemClickListener; |
| | |
| | | @Override |
| | | public void onBindViewHolder(ImageViewHolder holder, int position) { |
| | | |
| | | ImageBean imageBean=imageUrls.get(position); |
| | | if (imageBean.getType()== UplodFileState.VIDEO_TYPE){ |
| | | holder.play.setVisibility(View.VISIBLE); |
| | | }else { |
| | | holder.play.setVisibility(View.GONE); |
| | | } |
| | | // 使用 Glide 加载图片到 ImageView 中 |
| | | Glide.with(holder.itemView.getContext()) |
| | | .load(imageUrls.get(position).getWebPath()) // 加载图片的 URL 或路径 |
| | | .load(imageBean.getWebPath()) // 加载图片的 URL 或路径 |
| | | .thumbnail(0.1f) // 设置缩略图比例' |
| | | .transform(new CenterCrop(), new RoundedCorners(8)) |
| | | .placeholder(R.drawable.ps_image_placeholder) |
| | |
| | | public static class ImageViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | ImageView imageView; |
| | | ImageView play; |
| | | |
| | | public ImageViewHolder(View itemView) { |
| | | super(itemView); |
| | | imageView = itemView.findViewById(R.id.thumbnailImageView); |
| | | play=itemView.findViewById(R.id.item_play); |
| | | } |
| | | } |
| | | |