Images randomly uploaded to a pager with Glide and SimpleTarget

I use Glideto upload images to ViewPagerusing PagerAdapter. When I upload images using the following method:

Glide.with(mContext).load(mImage).placeholder(R.drawable.placeholder).into(mImageView);

Everything works fine, but now I need to get the bitmap from slipping and save it on the map when it loads for future editing, so I switched this method to the following:

Glide.with(mContext).load(mImage).asBitmap().placeholder(R.drawable.placeholder).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onLoadStarted(Drawable placeholder) {
                    super.onLoadStarted(placeholder);
                    mImageView.setImageDrawable(placeholder);
                }

                @Override
                public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
                    if (bitmap != null) {
                        mImageView.setImageBitmap(bitmap);
                    }
                    mBitmapMap.put(position, bitmap);
                    mInterface.onImageLoaded(position, bitmap);
                }
            });

But the result is that the image is not always displayed. I think this is due to the fact that glide loads async images and at some point returns when the method is instatiateItemalready completed.

This seems to be a related issue . But the offers there did not help me. Has anyone encountered this problem and have a solution for this?

+4
1

, SimpleTarget, , , BitmapImageViewTarget, , , . , , :

Glide.with(BaseApplication.getInstance()).load(newContent).asBitmap().placeholder(R.drawable.ic_action_picture).into(new BitmapImageViewTarget(mIvContent) {
                    @Override
                    public void onLoadStarted(Drawable placeholder) {
                        super.onLoadStarted(placeholder);
                        mIvContent.setImageDrawable(placeholder);
                    }

                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        super.onResourceReady(resource, glideAnimation);
                        mBitmapMap.put(position, resource);
                        progressBar.setVisibility(View.INVISIBLE);
                        mIvContent.setImageBitmap(resource);
                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable);
                        progressBar.setVisibility(View.INVISIBLE);
                    }
                });
+4

Source: https://habr.com/ru/post/1620562/


All Articles