Skip to content

Commit

Permalink
fix: ShowMsgAt cannot display emos and links correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
klxiaoniu committed Jul 18, 2023
1 parent c291d06 commit e9477f7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/me/ketal/hook/ShowMsgAt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ object ShowMsgAt : CommonSwitchFunctionHook(), OnBubbleBuilder {
is TextView -> {
copeAtInfo(content, atList)
}

is ViewGroup -> {
content.forEach {
if (it is TextView)
copeAtInfo(it, atList)
}
}

else -> {
Log.d("暂不支持的控件类型--->$content")
return
Expand Down Expand Up @@ -134,7 +136,8 @@ object ShowMsgAt : CommonSwitchFunctionHook(), OnBubbleBuilder {
}
}

private fun createAtSpanBySearch(text: String, atElements: List<TextElement>): SpannableString {
private fun setAtSpanBySearch(textView: TextView, atElements: List<TextElement>) {
val text = textView.text
val ssb = SpannableString(text)
for (at in atElements) {
if (at.content.length >= 2) {
Expand All @@ -145,7 +148,7 @@ object ShowMsgAt : CommonSwitchFunctionHook(), OnBubbleBuilder {
ssb.setSpan(createClickSpanForUid(uid), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
return ssb
textView.text = ssb
}

override fun onGetViewNt(rootView: ViewGroup, chatMessage: MsgRecord, param: XC_MethodHook.MethodHookParam) {
Expand All @@ -167,8 +170,7 @@ object ShowMsgAt : CommonSwitchFunctionHook(), OnBubbleBuilder {
val tv = rootView.findHostView<TextView>("ex1")
// TODO 2023-07-16 有时候 ex1 会为空
tv?.let {
val spannable = createAtSpanBySearch(tv.text.toString(), atElements)
tv.text = spannable
setAtSpanBySearch(it, atElements)
}
}

Expand Down

0 comments on commit e9477f7

Please sign in to comment.