mukeshsoni
mukeshsoni

Reputation: 583

Save Glide image onClick in ViewPager

I'm showing images from the server with RecyclerView. When a user clicks in RecyclerView item it open with ViewPager and FullImage fragment. There is a button that user can save that image.

For now, when user click on a button, I get the image position and save it with another glide request like this -

GlideApp.with(container.getContext())
    .asBitmap()
    .load(image.getUrl())
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
               // I want here the trigger option. When user click btn
              // saveImage(resource, image.getTitle());
                        imageViewPreview.setImageBitmap(resource);
            }
});

It takes time and data cause it sending another req. I want that when a user clicks on a button, It should save from that original Glide resource. Now how can I trigger that option?

GlideApp.with(container.getContext())
    .asBitmap()
    .load(image.getUrl())
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
               // I want here the trigger option. When user click btn
              // saveImage(resource, image.getTitle());
                        imageViewPreview.setImageBitmap(resource);
            }
});

Upvotes: 0

Views: 589

Answers (1)

Ionut J. Bejan
Ionut J. Bejan

Reputation: 754

You can use a global Bitmap variable, and after first load (when user switch to the current picture) set that bitmap. So, onResourceReady you will do something like currentBitmap = resource.

Eventually, if you are on the ViewPager, you can get the image based on current position using getAdapterPosition(); (which I suppose you already do)

Upvotes: 1

Related Questions