Fixed #2670 : Timestamp click behaviour in the description.

This commit is contained in:
faisalcodes 2023-01-18 22:02:08 +05:30
parent 7006693485
commit c98217f963

View File

@ -14,7 +14,7 @@ class LinkHandler(private val clickCallback: ((String) -> Unit)?) {
opening: Boolean, opening: Boolean,
tag: String?, tag: String?,
output: Editable?, output: Editable?,
attributes: Attributes? attributes: Attributes?,
): Boolean { ): Boolean {
// if the tag is not an anchor link, ignore for the default handler // if the tag is not an anchor link, ignore for the default handler
if (output == null || "a" != tag) { if (output == null || "a" != tag) {
@ -27,19 +27,21 @@ class LinkHandler(private val clickCallback: ((String) -> Unit)?) {
link = attributes.getValue("href") link = attributes.getValue("href")
} }
} else { } else {
val refTagEndIndex = output.length if (linkTagStartIndex >= 0 && link != null) {
setLinkSpans(output, linkTagStartIndex, refTagEndIndex, link) setLinkSpans(output, linkTagStartIndex, output.length, link!!)
linkTagStartIndex = -1
link = null
}
} }
return true return true
} }
private fun setLinkSpans(output: Editable, start: Int, end: Int, link: String?) { private fun setLinkSpans(output: Editable, start: Int, end: Int, link: String) {
output.setSpan( output.setSpan(
object : ClickableSpan() { object : ClickableSpan() {
override fun onClick(widget: View) { override fun onClick(widget: View) {
if (clickCallback != null && link != null) { clickCallback?.invoke(link)
clickCallback.invoke(link)
}
} }
override fun updateDrawState(ds: TextPaint) { override fun updateDrawState(ds: TextPaint) {