Search in sources :

Example 96 with RequestOptions

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);
    }
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Photo(com.daotangbill.photopicker.entity.Photo) File(java.io.File) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RequestOptions (com.bumptech.glide.request.RequestOptions)96 ImageView (android.widget.ImageView)23 View (android.view.View)18 Drawable (android.graphics.drawable.Drawable)16 TextView (android.widget.TextView)13 Bitmap (android.graphics.Bitmap)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 File (java.io.File)8 Uri (android.net.Uri)7 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Context (android.content.Context)5 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 DataSource (com.bumptech.glide.load.DataSource)5 GlideException (com.bumptech.glide.load.engine.GlideException)5 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)5 Test (org.junit.Test)5 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3