Search in sources :

Example 1 with BitmapAndSizeDecoder

use of com.simplecity.amp_library.glide.utils.BitmapAndSizeDecoder in project Shuttle by timusus.

the class ArtworkView method bindView.

@Override
public void bindView(ViewHolder holder) {
    super.bindView(holder);
    long time = System.currentTimeMillis();
    holder.textContainer.setBackground(null);
    holder.progressBar.setVisibility(View.VISIBLE);
    holder.lineTwo.setText(null);
    Glide.with(holder.itemView.getContext()).using(new TypeLoader(type, file), InputStream.class).from(ArtworkProvider.class).as(BitmapAndSize.class).sourceEncoder(new StreamEncoder()).decoder(new BitmapAndSizeDecoder(holder.itemView.getContext())).diskCacheStrategy(DiskCacheStrategy.NONE).load(artworkProvider).listener(new RequestListener<ArtworkProvider, BitmapAndSize>() {

        @Override
        public boolean onException(Exception e, ArtworkProvider model, Target<BitmapAndSize> target, boolean isFirstResource) {
            if (glideListener != null) {
                if (holder.itemView.getHandler() != null) {
                    holder.itemView.getHandler().postDelayed(() -> glideListener.onArtworkLoadFailed(ArtworkView.this), System.currentTimeMillis() + 1000 - time);
                }
            }
            return false;
        }

        @Override
        public boolean onResourceReady(BitmapAndSize resource, ArtworkProvider model, Target<BitmapAndSize> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    }).into(new ImageViewTarget<BitmapAndSize>(((ViewHolder) holder).imageView) {

        @Override
        protected void setResource(BitmapAndSize resource) {
            holder.textContainer.setBackgroundResource(R.drawable.text_protection_scrim_reversed);
            holder.progressBar.setVisibility(View.GONE);
            holder.imageView.setImageBitmap(resource.bitmap);
            holder.lineTwo.setText(String.format("%sx%spx", resource.size.width, resource.size.height));
        }
    });
    holder.lineOne.setText(ArtworkModel.getTypeString(type));
    if (type == ArtworkProvider.Type.FOLDER && file != null) {
        holder.lineOne.setText(file.getName());
    }
    if (isCustom && file != null && file.getPath().contains("custom_artwork")) {
        holder.lineOne.setText(holder.itemView.getContext().getString(R.string.artwork_type_custom));
    }
    holder.checkView.setVisibility(isSelected() ? View.VISIBLE : View.GONE);
}
Also used : Target(com.bumptech.glide.request.target.Target) ImageViewTarget(com.bumptech.glide.request.target.ImageViewTarget) RequestListener(com.bumptech.glide.request.RequestListener) BitmapAndSizeDecoder(com.simplecity.amp_library.glide.utils.BitmapAndSizeDecoder) BaseViewHolder(com.simplecityapps.recycler_adapter.recyclerview.BaseViewHolder) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) BitmapAndSize(com.simplecity.amp_library.glide.utils.BitmapAndSize) TypeLoader(com.simplecity.amp_library.glide.loader.TypeLoader) StreamEncoder(com.bumptech.glide.load.model.StreamEncoder)

Aggregations

StreamEncoder (com.bumptech.glide.load.model.StreamEncoder)1 RequestListener (com.bumptech.glide.request.RequestListener)1 ImageViewTarget (com.bumptech.glide.request.target.ImageViewTarget)1 Target (com.bumptech.glide.request.target.Target)1 TypeLoader (com.simplecity.amp_library.glide.loader.TypeLoader)1 BitmapAndSize (com.simplecity.amp_library.glide.utils.BitmapAndSize)1 BitmapAndSizeDecoder (com.simplecity.amp_library.glide.utils.BitmapAndSizeDecoder)1 ArtworkProvider (com.simplecity.amp_library.model.ArtworkProvider)1 BaseViewHolder (com.simplecityapps.recycler_adapter.recyclerview.BaseViewHolder)1