I am displaying some images in recyclerview using the picasso library from firebase storage, what I want to achieve is to save the image into app-specific internal storage as soon as the image is displayed in the imageview.
Then when I open the app next time I want to fetch the image from internal storage, if the image is not available there then fetch it from firebase urls. I'm able to show the images using Picasso library but then I'm stuck, I just begun android development and don't know how to proceed from here. Below is my code.
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private List<LoadImage> loadImages;
private Map<String, Bitmap> mBitmaps = new HashMap<>();
public ImageAdapter(List<LoadImage> loadImages) {
this.loadImages = loadImages;
}
@NonNull
@Override
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_view, parent, false);
return new ImageViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
LoadImage currentImage = loadImages.get(position);
Picasso.get()
.load(currentImage.getImageUrl())
.fit()
.into(holder.imageViewDownload);
}
@Override
public int getItemCount() {
return loadImages.size();
}
public class ImageViewHolder extends RecyclerView.ViewHolder {
ImageView imageViewDownload;
public ImageViewHolder(@NonNull View itemView) {
super(itemView);
imageViewDownload = itemView.findViewById(R.id.image_view_download);
}
}
}
question from:
https://stackoverflow.com/questions/65858093/display-image-in-imageview-and-save-it-to-internal-storage-on-android 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…