diff --git a/app-sample/build.gradle b/app-sample/build.gradle index d6dec350..623c8bf2 100644 --- a/app-sample/build.gradle +++ b/app-sample/build.gradle @@ -48,6 +48,10 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = "1.8" + } + sourceSets { main { java.srcDirs += '../sample-utils/annotations' @@ -141,6 +145,7 @@ dependencies { implementation project(':markwon-image-picasso') implementation project(':markwon-image-glide') + implementation project(':markwon-image-coil') deps.with { // implementation it['x-appcompat'] diff --git a/app-sample/samples.json b/app-sample/samples.json index 8fa9e674..1e04d195 100644 --- a/app-sample/samples.json +++ b/app-sample/samples.json @@ -1,4 +1,19 @@ [ + { + "javaClassName": "io.noties.markwon.app.samples.image.CoilRecyclerViewSample", + "id": "20200803132053", + "title": "Coil inside RecyclerView", + "description": "Display images via Coil plugin in `RecyclerView`", + "artifacts": [ + "IMAGE_COIL", + "RECYCLER" + ], + "tags": [ + "image", + "recycler-view", + "rendering" + ] + }, { "javaClassName": "io.noties.markwon.app.samples.image.NativeAndHtmlImageSample", "id": "20200803115847", @@ -795,13 +810,12 @@ ] }, { - "javaClassName": "io.noties.markwon.app.samples.GithubUserIssueInlineParsingSample", + "javaClassName": "io.noties.markwon.app.samples.GithubUserIssueOnTextAddedSample", "id": "20200629162024", "title": "User mention and issue (via text)", "description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`", "artifacts": [ - "CORE", - "INLINE_PARSER" + "CORE" ], "tags": [ "parsing", @@ -810,12 +824,13 @@ ] }, { - "javaClassName": "io.noties.markwon.app.samples.GithubUserIssueOnTextAddedSample", + "javaClassName": "io.noties.markwon.app.samples.GithubUserIssueInlineParsingSample", "id": "20200629162024", "title": "User mention and issue (via text)", "description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`", "artifacts": [ - "CORE" + "CORE", + "INLINE_PARSER" ], "tags": [ "parsing", diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/image/CoilRecyclerViewSample.kt b/app-sample/src/main/java/io/noties/markwon/app/samples/image/CoilRecyclerViewSample.kt new file mode 100644 index 00000000..8592d3eb --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/image/CoilRecyclerViewSample.kt @@ -0,0 +1,83 @@ +package io.noties.markwon.app.samples.image + +import androidx.recyclerview.widget.LinearLayoutManager +import coil.ImageLoader +import coil.request.LoadRequest +import coil.request.RequestDisposable +import coil.transform.RoundedCornersTransformation +import io.noties.markwon.Markwon +import io.noties.markwon.app.R +import io.noties.markwon.app.sample.Tags +import io.noties.markwon.app.sample.ui.MarkwonRecyclerViewSample +import io.noties.markwon.image.AsyncDrawable +import io.noties.markwon.image.coil.CoilImagesPlugin +import io.noties.markwon.recycler.MarkwonAdapter +import io.noties.markwon.sample.annotations.MarkwonArtifact +import io.noties.markwon.sample.annotations.MarkwonSampleInfo +import okhttp3.OkHttpClient + +@MarkwonSampleInfo( + id = "20200803132053", + title = "Coil inside RecyclerView", + description = "Display images via Coil plugin in `RecyclerView`", + artifacts = [MarkwonArtifact.IMAGE_COIL, MarkwonArtifact.RECYCLER], + tags = [Tags.rendering, Tags.recyclerView, Tags.image] +) +class CoilRecyclerViewSample : MarkwonRecyclerViewSample() { + override fun render() { + val md = """ + # H1 + ## H2 + ### H3 + #### H4 + ##### H5 + + > a quote + + + one + - two + * three + + 1. one + 1. two + 1. three + + --- + + # Images + + ![img](https://picsum.photos/id/237/1024/800) + """.trimIndent() + + val markwon = Markwon.builder(context) + .usePlugin(CoilImagesPlugin.create( + object : CoilImagesPlugin.CoilStore { + override fun load(drawable: AsyncDrawable): LoadRequest { + return LoadRequest.Builder(context) + .transformations( + RoundedCornersTransformation(14F) + ) + .data(drawable.destination) + .placeholder(R.drawable.ic_image_gray_24dp) + .build() + } + + override fun cancel(disposable: RequestDisposable) { + disposable.dispose() + } + }, + ImageLoader.Builder(context) + .okHttpClient(OkHttpClient()) + .placeholder(R.drawable.ic_image_gray_24dp) + .build())) + .build() + + val adapter = MarkwonAdapter.createTextViewIsRoot(R.layout.adapter_node) + + recyclerView.layoutManager = LinearLayoutManager(context) + recyclerView.adapter = adapter + + adapter.setMarkdown(markwon, md) + adapter.notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app-sample/src/main/res/drawable/ic_image_gray_24dp.xml b/app-sample/src/main/res/drawable/ic_image_gray_24dp.xml new file mode 100644 index 00000000..e058e174 --- /dev/null +++ b/app-sample/src/main/res/drawable/ic_image_gray_24dp.xml @@ -0,0 +1,10 @@ + + +