Add ImageLoader API

This commit is contained in:
Tyler Wong 2019-11-12 23:46:01 -08:00
parent bf61d8c627
commit 4fa1ac718f
2 changed files with 29 additions and 0 deletions

View File

@ -8,6 +8,15 @@ Image loading based on `Coil` library
val markwon = Markwon.builder(context)
// automatically create Coil instance
.usePlugin(CoilImagesPlugin.create(context))
// use supplied ImageLoader instance
.usePlugin(CoilImagesPlugin.create(
context,
ImageLoader(context) {
availableMemoryPercentage(0.5)
bitmapPoolPercentage(0.5)
crossfade(true)
}
))
// if you need more control
.usePlugin(CoilImagesPlugin.create(object : CoilImagesPlugin.CoilStore {
override fun load(drawable: AsyncDrawable): LoadRequest {

View File

@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.Map;
import coil.Coil;
import coil.ImageLoader;
import coil.api.ImageLoaders;
import coil.request.LoadRequest;
import coil.request.RequestDisposable;
@ -58,6 +59,25 @@ public class CoilImagesPlugin extends AbstractMarkwonPlugin {
});
}
@NonNull
public static CoilImagesPlugin create(@NonNull final Context context,
@NonNull final ImageLoader imageLoader) {
return create(new CoilStore() {
@NonNull
@Override
public LoadRequest load(@NonNull AsyncDrawable drawable) {
return ImageLoaders.newLoadBuilder(imageLoader, context)
.data(drawable.getDestination())
.build();
}
@Override
public void cancel(@NonNull RequestDisposable disposable) {
disposable.dispose();
}
});
}
@NonNull
public static CoilImagesPlugin create(@NonNull CoilStore coilStore) {
return new CoilImagesPlugin(coilStore);