ImageView Update Using Glide

I have one ImageView and one image uploaded to it using Glide:

Glide.with(ImageView.getContext())
    .load(url)
    .dontAnimate()
    .placeholder(R.drawable.placeholder)
    .signature(stringSignature)
    .into(new GlideDrawableImageViewTarget(ImageView) {
        @Override
        public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
            super.onResourceReady(drawable, anim);
            progressBar.setVisibility(View.GONE);
        }
    });

and when I want to update the image, I run the same code again only with a new signature. It works fine, but when a new download starts, the visible image disappears immediately.

Question

Is it possible to save an image in ImageView and replace it after loading a new image?

+4
source share
2 answers

.
, .load(x), Glide .clear() .
, Glide , , Bitmap.
, , :

    public <T> void loadNextImage(@NonNull T model,
                                  @NonNull BitmapTransformation... transformations) {
        //noinspection MagicNumber
        int hash = model.hashCode() + 31 * Arrays.hashCode(transformations);
        if (mLastLoadHash == hash) return;
        Glide.with(mContext).load(model).asBitmap().transform(transformations).into(mCurrentTarget);
        mLastLoadHash = hash;
    }

Target mCurrentTarget;



private class DiaporamaViewTarget extends ViewTarget<ImageView, Bitmap> {

        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            mLoadedDrawable = new BitmapDrawable(mImageView.getResources(), resource);
           // display the loaded image 
            mCurrentTarget = mPreviousTarget;
+3

Drawable , :

    private Drawable placeholder = ContextCompat.getDrawable(ctx, R.drawable.placeholder);

    public void loadImage(String url, ImageView imageView) {
        Glide.with(imageView.getContext())
            .load(url)
            .placeholder(placeholder)
            .into(new GlideDrawableImageViewTarget(imageView) {
                @Override
                public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
                    super.onResourceReady(drawable, anim);
                    placeholder = drawable;
                }
            });
    }
+1

All Articles