fix link parsing

This commit is contained in:
Matthieu 2021-11-28 19:02:25 +01:00
parent 58b668e09a
commit af63fc8990
1 changed files with 31 additions and 28 deletions

View File

@ -60,7 +60,7 @@ fun parseHTMLText(
// Convert text to spannable
val content = fromHtml(text)
//Retrive all links that should be made clickable
// Retrieve all links that should be made clickable
val builder = SpannableStringBuilder(content)
val urlSpans = content.getSpans(0, content.length, URLSpan::class.java)
@ -78,12 +78,13 @@ fun parseHTMLText(
override fun onClick(widget: View) {
openTag(context, tag)
}
}
builder.removeSpan(span)
}
// Handle mentions
if(text[0] == '@' && !mentions.isNullOrEmpty()) {
else if(text[0] == '@') {
if (!mentions.isNullOrEmpty()){
val accountUsername = text.subSequence(1, text.length).toString()
var id: String? = null
@ -105,7 +106,7 @@ fun parseHTMLText(
val accountId: String = id
customSpan = object : ClickableSpanNoUnderline() {
override fun onClick(widget: View) {
Log.e("MENTION", "CLICKED")
// Retrieve the account for the given profile
lifecycleScope.launchWhenCreated {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
@ -115,8 +116,10 @@ fun parseHTMLText(
}
}
}
builder.removeSpan(span)
}
builder.setSpan(customSpan, start, end, flags)
// Add zero-width space after links in end of line to fix its too large hitbox.