Links
This commit is contained in:
parent
badad8f23a
commit
fc4071fa87
3 changed files with 25 additions and 10 deletions
|
@ -138,6 +138,7 @@ dependencies {
|
||||||
implementation 'io.noties.markwon:core:4.6.2'
|
implementation 'io.noties.markwon:core:4.6.2'
|
||||||
implementation 'io.noties.markwon:image-picasso:4.6.2'
|
implementation 'io.noties.markwon:image-picasso:4.6.2'
|
||||||
implementation 'io.noties.markwon:image:4.6.2'
|
implementation 'io.noties.markwon:image:4.6.2'
|
||||||
|
implementation 'io.noties.markwon:linkify:4.6.2'
|
||||||
implementation 'io.noties.markwon:ext-tables:4.6.2'
|
implementation 'io.noties.markwon:ext-tables:4.6.2'
|
||||||
implementation 'io.noties.markwon:ext-strikethrough:4.6.2'
|
implementation 'io.noties.markwon:ext-strikethrough:4.6.2'
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,10 +112,16 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
|
||||||
|
|
||||||
val context = itemView.context
|
val context = itemView.context
|
||||||
val unmatchedTags = unmatchedTags(splitTags(notification.tags))
|
val unmatchedTags = unmatchedTags(splitTags(notification.tags))
|
||||||
|
val message = maybeAppendActionErrors(formatMessage(notification), notification)
|
||||||
|
|
||||||
dateView.text = formatDateShort(notification.timestamp)
|
dateView.text = formatDateShort(notification.timestamp)
|
||||||
messageView.text = maybeAppendActionErrors(maybeMarkdown(formatMessage(notification), notification), notification)
|
if (notification.isMarkdown()) {
|
||||||
messageView.autoLinkMask = if (notification.isMarkdown()) 0 else Linkify.WEB_URLS
|
messageView.autoLinkMask = 0
|
||||||
|
markwon.setMarkdown(messageView, message.toString())
|
||||||
|
} else {
|
||||||
|
messageView.autoLinkMask = Linkify.WEB_URLS
|
||||||
|
messageView.text = message
|
||||||
|
}
|
||||||
messageView.movementMethod = BetterLinkMovementMethod.getInstance()
|
messageView.movementMethod = BetterLinkMovementMethod.getInstance()
|
||||||
messageView.setOnClickListener {
|
messageView.setOnClickListener {
|
||||||
// Click & Long-click listeners on the text as well, because "autoLink=web" makes them
|
// Click & Long-click listeners on the text as well, because "autoLink=web" makes them
|
||||||
|
|
|
@ -3,18 +3,18 @@ package io.heckel.ntfy.util
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.text.method.LinkMovementMethod
|
|
||||||
import android.text.style.*
|
import android.text.style.*
|
||||||
|
import android.text.util.Linkify
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import io.heckel.ntfy.R
|
import io.heckel.ntfy.R
|
||||||
import io.noties.markwon.*
|
import io.noties.markwon.*
|
||||||
import io.noties.markwon.core.CorePlugin
|
import io.noties.markwon.core.CorePlugin
|
||||||
import io.noties.markwon.core.CoreProps
|
import io.noties.markwon.core.CoreProps
|
||||||
import io.noties.markwon.core.MarkwonTheme
|
import io.noties.markwon.core.MarkwonTheme
|
||||||
|
import io.noties.markwon.core.spans.LinkSpan
|
||||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
|
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
|
||||||
import io.noties.markwon.ext.tables.TableAwareMovementMethod
|
import io.noties.markwon.image.ImagesPlugin
|
||||||
import io.noties.markwon.ext.tables.TablePlugin
|
import io.noties.markwon.linkify.LinkifyPlugin
|
||||||
import io.noties.markwon.ext.tables.TableTheme
|
|
||||||
import io.noties.markwon.movement.MovementMethodPlugin
|
import io.noties.markwon.movement.MovementMethodPlugin
|
||||||
import me.saket.bettermovementmethod.BetterLinkMovementMethod
|
import me.saket.bettermovementmethod.BetterLinkMovementMethod
|
||||||
import org.commonmark.ext.gfm.tables.TableCell
|
import org.commonmark.ext.gfm.tables.TableCell
|
||||||
|
@ -30,14 +30,22 @@ internal object MarkwonFactory {
|
||||||
return Markwon.builder(context)
|
return Markwon.builder(context)
|
||||||
.usePlugin(CorePlugin.create())
|
.usePlugin(CorePlugin.create())
|
||||||
.usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.getInstance()))
|
.usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.getInstance()))
|
||||||
// .usePlugin(PicassoImagesPlugin.create(picasso))
|
.usePlugin(ImagesPlugin.create())
|
||||||
|
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||||
.usePlugin(StrikethroughPlugin.create())
|
.usePlugin(StrikethroughPlugin.create())
|
||||||
//.usePlugin(TablePlugin.create(context))
|
|
||||||
.usePlugin(object : AbstractMarkwonPlugin() {
|
.usePlugin(object : AbstractMarkwonPlugin() {
|
||||||
override fun configureTheme(builder: MarkwonTheme.Builder) {
|
override fun configureTheme(builder: MarkwonTheme.Builder) {
|
||||||
builder.linkColor(ContextCompat.getColor(context, R.color.teal))
|
builder
|
||||||
|
.linkColor(ContextCompat.getColor(context, R.color.teal))
|
||||||
.isLinkUnderlined(true)
|
.isLinkUnderlined(true)
|
||||||
|
.blockMargin(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
||||||
|
builder
|
||||||
|
.linkResolver(LinkResolverDef())
|
||||||
|
}
|
||||||
|
|
||||||
override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
|
override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
|
||||||
builder
|
builder
|
||||||
.setFactory(Heading::class.java) { _, props: RenderProps? ->
|
.setFactory(Heading::class.java) { _, props: RenderProps? ->
|
||||||
|
@ -52,7 +60,7 @@ internal object MarkwonFactory {
|
||||||
.setFactory(Code::class.java) { _, _ ->
|
.setFactory(Code::class.java) { _, _ ->
|
||||||
arrayOf<Any>(
|
arrayOf<Any>(
|
||||||
BackgroundColorSpan(Color.LTGRAY),
|
BackgroundColorSpan(Color.LTGRAY),
|
||||||
TypefaceSpan("monospace")
|
//TypefaceSpan("monospace")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.setFactory(ListItem::class.java) { _, _ -> BulletSpan(bulletGapWidth) }
|
.setFactory(ListItem::class.java) { _, _ -> BulletSpan(bulletGapWidth) }
|
||||||
|
|
Loading…
Reference in a new issue