Sample, add coild inside RecyclerView sample
This commit is contained in:
parent
ac05b07123
commit
28c2a7047d
@ -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']
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
||||

|
||||
""".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()
|
||||
}
|
||||
}
|
10
app-sample/src/main/res/drawable/ic_image_gray_24dp.xml
Normal file
10
app-sample/src/main/res/drawable/ic_image_gray_24dp.xml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user