mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-24 14:09:44 +01:00
modify DisplayUtils and MessageUtils
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
6dfd3b6956
commit
522d18e9d8
@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import android.text.TextPaint
|
||||
import android.text.TextUtils
|
||||
@ -224,6 +225,28 @@ object DisplayUtils {
|
||||
return chip
|
||||
}
|
||||
|
||||
fun replaceLabelWithPlaceholder(
|
||||
text: Spanned,
|
||||
labelToSearch: String,
|
||||
placeholder: String
|
||||
): Spannable {
|
||||
val spannableStringBuilder = SpannableStringBuilder(text)
|
||||
val stringText = text.toString()
|
||||
val m = Pattern.compile(
|
||||
Pattern.quote(labelToSearch),
|
||||
Pattern.CASE_INSENSITIVE or Pattern.LITERAL or Pattern.MULTILINE
|
||||
)
|
||||
.matcher(spannableStringBuilder)
|
||||
var lastStartIndex = 0
|
||||
while (m.find()) {
|
||||
val start = stringText.indexOf(m.group(), lastStartIndex)
|
||||
val end = start + m.group().length
|
||||
lastStartIndex = end
|
||||
spannableStringBuilder.replace(start, end, placeholder)
|
||||
}
|
||||
return spannableStringBuilder
|
||||
}
|
||||
|
||||
fun searchAndReplaceWithMentionSpan(
|
||||
key: String,
|
||||
context: Context,
|
||||
|
@ -118,6 +118,19 @@ class MessageUtils(val context: Context) {
|
||||
} else {
|
||||
individualHashMap["id"]
|
||||
}
|
||||
val label = individualHashMap["name"]!!
|
||||
val type = individualHashMap["type"]!!
|
||||
val labelToSearch = if (type == "circle") {
|
||||
"@team/$label"
|
||||
} else {
|
||||
"@$label"
|
||||
}
|
||||
|
||||
messageStringInternal = DisplayUtils.replaceLabelWithPlaceholder(
|
||||
messageStringInternal,
|
||||
labelToSearch,
|
||||
PLACEHOLDER
|
||||
)
|
||||
|
||||
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
|
||||
key!!,
|
||||
@ -169,5 +182,6 @@ class MessageUtils(val context: Context) {
|
||||
private const val TAG = "MessageUtils"
|
||||
const val MAX_REPLY_LENGTH = 250
|
||||
const val HTTPS_PROTOCOL = "https://"
|
||||
const val PLACEHOLDER = "[mention]"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user