Image Coil

image-coil

Image loading based on Coil library.

There are 3 factory methods to obtain CoilImagesPlugin:

val coilPlugin: CoilImagesPlugin
  get() = CoilImagesPlugin.create(context)

WARNING

In order to use the CoilImagesPlugin.create(Context) factory method your app must have explicit dependency on coil (io.coil-kt:coil) library. This artifact relies on io.coil-kt:coil-base as per Coil documentation

val coilPlugin: CoilImagesPlugin
  get() = CoilImagesPlugin.create(context, imageLoader)

val imageLoader: ImageLoader
  get() = ImageLoader.Builder(context)
    .apply {
      availableMemoryPercentage(0.5)
      bitmapPoolPercentage(0.5)
      crossfade(true)
    }
    .build()
val coilPlugin: CoilImagesPlugin
  get() {
    val loader = imageLoader
    return CoilImagesPlugin.create(
      object : CoilImagesPlugin.CoilStore {
        override fun load(drawable: AsyncDrawable): ImageRequest {
          return ImageRequest.Builder(context)
            .defaults(loader.defaults)
            .data(drawable.destination)
            .crossfade(true)
            .transformations(CircleCropTransformation())
            .build()
        }

        override fun cancel(disposable: Disposable) {
          disposable.dispose()
        }
      },
      loader
    )
  }

val imageLoader: ImageLoader
  get() = ImageLoader.Builder(context)
    .apply {
      availableMemoryPercentage(0.5)
      bitmapPoolPercentage(0.5)
      crossfade(true)
    }
    .build()

Finally, use as a regular plugin:

val markwon = Markwon.builder(context)
  .usePlugin(coilPlugin)
  .build()

Last Updated: 8/26/2020, 1:21:48 PM