Skip to content

Commit

Permalink
Don't repeat inline tags in the trailing hashtag bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Tak committed Dec 15, 2024
1 parent 02da325 commit c21a9b8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,33 @@ fun setClickableText(
trailingHashtagView == null || tags.isNullOrEmpty() -> Pair(spannableContent.length, emptyList())
else -> getTrailingHashtags(spannableContent)
}
var inlineHashtagSpanCount = 0
val inlineHashtags = mutableListOf<CharSequence>()

view.text = spannableContent.apply {
styleQuoteSpans(view)
getSpans(0, endOfContent, URLSpan::class.java).forEach { span ->
if (get(getSpanStart(span)) == '#') {
inlineHashtagSpanCount += 1
val start = getSpanStart(span)
if (get(start) == '#') {
inlineHashtags.add(subSequence(start + 1, getSpanEnd(span)))
}
setClickableText(span, this, mentions, tags, listener)
}
}.subSequence(0, endOfContent).trimEnd()

view.movementMethod = NoTrailingSpaceLinkMovementMethod

val showHashtagBar = (trailingHashtags.isNotEmpty() || inlineHashtagSpanCount != tags?.size)
val showHashtagBar = (trailingHashtags.isNotEmpty() || inlineHashtags.size != tags?.size)
// I don't _love_ setting the visibility here, but the alternative is to duplicate the logic in other places
trailingHashtagView?.visible(showHashtagBar)

if (showHashtagBar) {
trailingHashtagView?.apply { text = buildTrailingHashtagText(tags, trailingHashtags, listener) }
trailingHashtagView?.apply {
text = buildTrailingHashtagText(
tags?.filterNot { tag -> inlineHashtags.any { it.contentEquals(tag.name, ignoreCase = true) } },
trailingHashtags,
listener,
)
}
}
}

Expand Down

0 comments on commit c21a9b8

Please sign in to comment.