Fix relinkifying tags in posts from remote servers (#2359)

* Fix relinkifying tags in posts from remote servers

* Completely ignore urls, and (case-insensitively) match tag names instead
This commit is contained in:
Levi Bard 2022-02-28 16:54:25 +01:00 committed by GitHub
commit cdefcc441f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 43 deletions

View file

@ -98,15 +98,16 @@ fun setClickableText(
}
@VisibleForTesting
fun getTagName(text: CharSequence, tags: List<HashTag>?, span: URLSpan): String? {
fun getTagName(text: CharSequence, tags: List<HashTag>?): String? {
val scrapedName = text.subSequence(1, text.length).toString()
return when (tags) {
null -> text.subSequence(1, text.length).toString()
else -> tags.firstOrNull { it.url == span.url }?.name
null -> scrapedName
else -> tags.firstOrNull { it.name.equals(scrapedName, true) }?.name
}
}
private fun getCustomSpanForTag(text: CharSequence, tags: List<HashTag>?, span: URLSpan, listener: LinkListener): ClickableSpan? {
return getTagName(text, tags, span)?.let {
return getTagName(text, tags)?.let {
object : NoUnderlineURLSpan(span.url) {
override fun onClick(view: View) = listener.onViewTag(it)
}