Hey. As the image loader chose Fresco. It is necessary to cache pictures to disk and, when I'm offline, get them from the cache. Tell me how to implement it.

Dock links do not send please. Doku read, did not understand. Therefore, I ask a question here. And do not offer other options such as Glide and Picasso

    2 answers 2

    In general, I found how it can be configured in Fresco

    val diskCacheConfig = DiskCacheConfig.newBuilder(this).setBaseDirectoryPath(this.cacheDir) .setBaseDirectoryName("image") .setMaxCacheSize((100 * ByteConstants.MB).toLong()) .setMaxCacheSizeOnLowDiskSpace((10 * ByteConstants.MB).toLong()) .setMaxCacheSizeOnVeryLowDiskSpace((5 * ByteConstants.MB).toLong()) .setVersion(1) .build() val imagePipelineConfig = ImagePipelineConfig.newBuilder(this) .setMainDiskCacheConfig(diskCacheConfig) .build() Fresco.initialize(this, imagePipelineConfig) 

    It is enough to register all this in Application and use for SimpleDraweeView

      You can use Picasso caching in it automatically.

      Caching article

      Round Transformation:

       /** * @author zTrap * @date 05.09.2016. */ public class CircleTransform implements Transformation { @Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; } @Override public String key() { return "circle"; } } 

      Using:

       Picasso.with(this).load(profile.photo) .placeholder(R.drawable.no_avatar) .transform(new CircleTransform()) .resize(200, 200) .centerCrop() .into(avatar); 
      • I didn’t just choose fresco. It can cache to disk and after a call from the application or after rebooting the device, all the pictures are not deleted - pavel163
      • And who told you that in Picasso it is not so? - zTrap
      • Then attach the link. And all the same, I just need fresco - pavel163
      • Thank. But I still need with Fresco. Can Picasso make round images automatically? - pavel163
      • @ pavel163 updated the answer - zTrap