Sample, add coild inside RecyclerView sample

This commit is contained in:
Dimitry Ivanov 2020-08-03 16:27:19 +03:00
parent ac05b07123
commit 28c2a7047d
4 changed files with 118 additions and 5 deletions

View File

@ -48,6 +48,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
} }
kotlinOptions {
jvmTarget = "1.8"
}
sourceSets { sourceSets {
main { main {
java.srcDirs += '../sample-utils/annotations' java.srcDirs += '../sample-utils/annotations'
@ -141,6 +145,7 @@ dependencies {
implementation project(':markwon-image-picasso') implementation project(':markwon-image-picasso')
implementation project(':markwon-image-glide') implementation project(':markwon-image-glide')
implementation project(':markwon-image-coil')
deps.with { deps.with {
// implementation it['x-appcompat'] // implementation it['x-appcompat']

View File

@ -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", "javaClassName": "io.noties.markwon.app.samples.image.NativeAndHtmlImageSample",
"id": "20200803115847", "id": "20200803115847",
@ -795,13 +810,12 @@
] ]
}, },
{ {
"javaClassName": "io.noties.markwon.app.samples.GithubUserIssueInlineParsingSample", "javaClassName": "io.noties.markwon.app.samples.GithubUserIssueOnTextAddedSample",
"id": "20200629162024", "id": "20200629162024",
"title": "User mention and issue (via text)", "title": "User mention and issue (via text)",
"description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`", "description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`",
"artifacts": [ "artifacts": [
"CORE", "CORE"
"INLINE_PARSER"
], ],
"tags": [ "tags": [
"parsing", "parsing",
@ -810,12 +824,13 @@
] ]
}, },
{ {
"javaClassName": "io.noties.markwon.app.samples.GithubUserIssueOnTextAddedSample", "javaClassName": "io.noties.markwon.app.samples.GithubUserIssueInlineParsingSample",
"id": "20200629162024", "id": "20200629162024",
"title": "User mention and issue (via text)", "title": "User mention and issue (via text)",
"description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`", "description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`",
"artifacts": [ "artifacts": [
"CORE" "CORE",
"INLINE_PARSER"
], ],
"tags": [ "tags": [
"parsing", "parsing",

View File

@ -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()
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#333"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z" />
</vector>