Search in sources :

Example 1 with DribbbleTarget

use of io.plaidapp.util.glide.DribbbleTarget in project plaid by nickbutcher.

the class FeedAdapter method bindDribbbleShotHolder.

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) {
    final int[] imageSize = shot.images.bestSize();
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        holder.image.setColorFilter(new ColorMatrixColorFilter(cm));
                    }
                });
                saturation.setDuration(2000L);
                saturation.setInterpolator(getFastOutSlowInInterpolator(host));
                saturation.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.image.clearColorFilter();
                        holder.image.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]).diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1]).into(new DribbbleTarget(holder.image, false));
    // need both placeholder & background to prevent seeing through shot as it fades in
    holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]);
    holder.image.showBadge(shot.animated);
    // need a unique transition name per shot, let's use it's url
    holder.image.setTransitionName(shot.html_url);
}
Also used : DribbbleTarget(io.plaidapp.util.glide.DribbbleTarget) RequestListener(com.bumptech.glide.request.RequestListener) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Target(com.bumptech.glide.request.target.Target) DribbbleTarget(io.plaidapp.util.glide.DribbbleTarget) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ObservableColorMatrix(io.plaidapp.util.ObservableColorMatrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Aggregations

Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)1 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)1 RequestListener (com.bumptech.glide.request.RequestListener)1 Target (com.bumptech.glide.request.target.Target)1 ObservableColorMatrix (io.plaidapp.util.ObservableColorMatrix)1 DribbbleTarget (io.plaidapp.util.glide.DribbbleTarget)1