sample, add regular coil sample
This commit is contained in:
parent
8cea2e0202
commit
2356dd4618
10
CHANGELOG.md
10
CHANGELOG.md
@ -3,8 +3,14 @@
|
|||||||
# SNAPSHOT
|
# SNAPSHOT
|
||||||
|
|
||||||
#### Changed
|
#### Changed
|
||||||
* `image-glide`: update to `4.11.0` version
|
* `image-glide` - update to `4.11.0` version
|
||||||
* `inline-parser`: revert parsing index when `InlineProcessor` returns `null` as result
|
* `inline-parser` - revert parsing index when `InlineProcessor` returns `null` as result
|
||||||
|
* `image-coil` - update `Coil` to `0.12.0` ([Coil changelog](https://coil-kt.github.io/coil/changelog/)) ([#284])<br>Thanks [@magnusvs]
|
||||||
|
|
||||||
|
[#284]: https://github.com/noties/Markwon/pull/284
|
||||||
|
|
||||||
|
[@magnusvs]: https://github.com/magnusvs
|
||||||
|
|
||||||
|
|
||||||
# 4.5.1
|
# 4.5.1
|
||||||
|
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"javaClassName": "io.noties.markwon.app.samples.image.CoilImageSample",
|
||||||
|
"id": "20200826101209",
|
||||||
|
"title": "Coil image",
|
||||||
|
"description": "",
|
||||||
|
"artifacts": [
|
||||||
|
"IMAGE_COIL"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"image"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"javaClassName": "io.noties.markwon.app.samples.JustifyModeSample",
|
"javaClassName": "io.noties.markwon.app.samples.JustifyModeSample",
|
||||||
"id": "20200826084338",
|
"id": "20200826084338",
|
||||||
|
@ -0,0 +1,93 @@
|
|||||||
|
package io.noties.markwon.app.samples.image
|
||||||
|
|
||||||
|
import coil.ImageLoader
|
||||||
|
import coil.request.Disposable
|
||||||
|
import coil.request.ImageRequest
|
||||||
|
import coil.transform.CircleCropTransformation
|
||||||
|
import io.noties.markwon.Markwon
|
||||||
|
import io.noties.markwon.app.sample.Tags
|
||||||
|
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample
|
||||||
|
import io.noties.markwon.image.AsyncDrawable
|
||||||
|
import io.noties.markwon.image.coil.CoilImagesPlugin
|
||||||
|
import io.noties.markwon.sample.annotations.MarkwonArtifact
|
||||||
|
import io.noties.markwon.sample.annotations.MarkwonSampleInfo
|
||||||
|
|
||||||
|
@MarkwonSampleInfo(
|
||||||
|
id = "20200826101209",
|
||||||
|
title = "Coil image",
|
||||||
|
artifacts = [MarkwonArtifact.IMAGE_COIL],
|
||||||
|
tags = [Tags.image]
|
||||||
|
)
|
||||||
|
class CoilImageSample : MarkwonTextViewSample() {
|
||||||
|
override fun render() {
|
||||||
|
val md = """
|
||||||
|
# H1
|
||||||
|
## H2
|
||||||
|
### H3
|
||||||
|
#### H4
|
||||||
|
##### H5
|
||||||
|
|
||||||
|
> a quote
|
||||||
|
|
||||||
|
+ one
|
||||||
|
- two
|
||||||
|
* three
|
||||||
|
|
||||||
|
1. one
|
||||||
|
1. two
|
||||||
|
1. three
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Images
|
||||||
|
|
||||||
|

|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
// pick one
|
||||||
|
val markwon = Markwon.builder(context)
|
||||||
|
// .usePlugin(coilPlugin1)
|
||||||
|
// .usePlugin(coilPlugin2)
|
||||||
|
.usePlugin(coilPlugin3)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
markwon.setMarkdown(textView, md)
|
||||||
|
}
|
||||||
|
|
||||||
|
val coilPlugin1: CoilImagesPlugin
|
||||||
|
get() = CoilImagesPlugin.create(context)
|
||||||
|
|
||||||
|
val coilPlugin2: CoilImagesPlugin
|
||||||
|
get() = CoilImagesPlugin.create(context, imageLoader)
|
||||||
|
|
||||||
|
val coilPlugin3: 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()
|
||||||
|
}
|
@ -2,39 +2,73 @@
|
|||||||
|
|
||||||
<MavenBadge4 :artifact="'image-coil'" />
|
<MavenBadge4 :artifact="'image-coil'" />
|
||||||
|
|
||||||
Image loading based on `Coil` library.
|
Image loading based on [Coil](https://github.com/coil-kt/coil/) library.
|
||||||
|
|
||||||
|
There are 3 factory methods to obtain `CoilImagesPlugin`:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val markwon = Markwon.builder(context)
|
val coilPlugin: CoilImagesPlugin
|
||||||
// automatically create Coil instance
|
get() = CoilImagesPlugin.create(context)
|
||||||
.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 {
|
|
||||||
return LoadRequest(context, customImageLoader.defaults) {
|
|
||||||
data(drawable.destination)
|
|
||||||
crossfade(true)
|
|
||||||
transformations(CircleCropTransformation())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override cancel(disposable: RequestDisposable) {
|
|
||||||
disposable.dispose()
|
|
||||||
}
|
|
||||||
}, customImageLoader))
|
|
||||||
.build()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
:::warning
|
:::warning
|
||||||
In order to use the `CoilImagesPlugin.create(Context)` factory method your
|
In order to use the `CoilImagesPlugin.create(Context)` factory method your
|
||||||
app must have **explicit** dependency on `coil` library
|
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](https://coil-kt.github.io/coil/getting_started/#artifacts)
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
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()
|
||||||
|
```
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
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:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val markwon = Markwon.builder(context)
|
||||||
|
.usePlugin(coilPlugin)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user