use of com.bumptech.glide.request.RequestOptions in project MLib by DaoBillTang.
the class PhotoGridAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final PhotoViewHolder holder, int position) {
if (getItemViewType(position) == ITEM_TYPE_PHOTO) {
List<Photo> photos = getCurrentPhotos();
final Photo photo;
if (showCamera()) {
photo = photos.get(position - 1);
} else {
photo = photos.get(position);
}
boolean canLoadImage = AndroidLifecycleUtils.canLoadImage(holder.ivPhoto.getContext());
if (canLoadImage) {
final RequestOptions options = new RequestOptions();
options.centerCrop().dontAnimate().override(imageSize, imageSize).placeholder(R.drawable.__picker_ic_photo_black_48dp).error(R.drawable.__picker_ic_broken_image_black_48dp);
glide.setDefaultRequestOptions(options).load(new File(photo.getPath())).thumbnail(0.5f).into(holder.ivPhoto);
}
final boolean isChecked = isSelected(photo);
holder.vSelected.setSelected(isChecked);
holder.ivPhoto.setSelected(isChecked);
holder.ivPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (onPhotoClickListener != null) {
int pos = holder.getAdapterPosition();
if (previewEnable) {
onPhotoClickListener.onClick(view, pos, showCamera());
} else {
holder.vSelected.performClick();
}
}
}
});
holder.vSelected.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int pos = holder.getAdapterPosition();
boolean isEnable = true;
if (onItemCheckListener != null) {
isEnable = onItemCheckListener.onItemCheck(pos, photo, getSelectedPhotos().size() + (isSelected(photo) ? -1 : 1));
}
if (isEnable) {
toggleSelection(photo);
notifyItemChanged(pos);
}
}
});
} else {
holder.ivPhoto.setImageResource(R.drawable.__picker_camera);
}
}
Aggregations