mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 22:29:09 +00:00
Merge pull request #4703 from nextcloud/fix_placeholder_support
display label in the placeholder
This commit is contained in:
commit
b3186bac76
@ -29,17 +29,21 @@ class ChatUtils {
|
|||||||
|
|
||||||
if (individualHashMap != null) {
|
if (individualHashMap != null) {
|
||||||
val type = individualHashMap["type"]
|
val type = individualHashMap["type"]
|
||||||
resultMessage = if (type == "user" || type == "guest" || type == "call" || type == "email" ||
|
resultMessage = if (type == "user" || type == "guest" || type == "call" || type == "email"
|
||||||
type == "circle"
|
|
||||||
) {
|
) {
|
||||||
resultMessage?.replace("{$key}", "@" + individualHashMap["name"])
|
resultMessage?.replace("{$key}", "@" + individualHashMap["name"])
|
||||||
} else if (type == "geo-location") {
|
} else if (type == "geo-location") {
|
||||||
individualHashMap["name"]
|
individualHashMap["name"]
|
||||||
} else if (individualHashMap.containsKey("link") == true) {
|
} else if (individualHashMap.containsKey("link")) {
|
||||||
if (type == "file") {
|
if (type == "file") {
|
||||||
resultMessage?.replace("{$key}", individualHashMap["name"].toString())
|
resultMessage?.replace("{$key}", individualHashMap["name"].toString())
|
||||||
} else {
|
} else {
|
||||||
individualHashMap["link"].toString()
|
individualHashMap["name"]?.let {
|
||||||
|
resultMessage?.replace(
|
||||||
|
"{$key}",
|
||||||
|
individualHashMap["name"]!!
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
individualHashMap["name"]?.let { resultMessage?.replace("{$key}", it) }
|
individualHashMap["name"]?.let { resultMessage?.replace("{$key}", it) }
|
||||||
|
@ -8,9 +8,12 @@ package com.nextcloud.talk.utils.message
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.graphics.Typeface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
|
import android.text.style.StyleSpan
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
@ -140,13 +143,38 @@ class MessageUtils(val context: Context) {
|
|||||||
context.startActivity(browserIntent)
|
context.startActivity(browserIntent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else -> {
|
||||||
|
messageStringInternal = defaultMessageParameters(messageStringInternal, individualHashMap, key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageStringInternal
|
return messageStringInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun defaultMessageParameters(
|
||||||
|
messageString: Spanned,
|
||||||
|
individualHashMap: HashMap<String?, String?>,
|
||||||
|
key: String?
|
||||||
|
): Spanned {
|
||||||
|
val spannable = SpannableStringBuilder(messageString)
|
||||||
|
val placeholder = "{$key}"
|
||||||
|
val replacementText = individualHashMap["name"]
|
||||||
|
var start = spannable.indexOf(placeholder)
|
||||||
|
while (start != -1) {
|
||||||
|
val end = start + placeholder.length
|
||||||
|
spannable.replace(start, end, replacementText)
|
||||||
|
spannable.setSpan(
|
||||||
|
StyleSpan(Typeface.BOLD),
|
||||||
|
start,
|
||||||
|
start + replacementText!!.length,
|
||||||
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||||
|
)
|
||||||
|
start = spannable.indexOf(placeholder, start + replacementText.length)
|
||||||
|
}
|
||||||
|
return spannable
|
||||||
|
}
|
||||||
|
|
||||||
fun getRenderedMarkdownText(context: Context, markdown: String, textColor: Int): Spanned {
|
fun getRenderedMarkdownText(context: Context, markdown: String, textColor: Int): Spanned {
|
||||||
val drawable = TaskListDrawable(textColor, textColor, context.getColor(R.color.bg_default))
|
val drawable = TaskListDrawable(textColor, textColor, context.getColor(R.color.bg_default))
|
||||||
val markwon = Markwon.builder(context).usePlugin(object : AbstractMarkwonPlugin() {
|
val markwon = Markwon.builder(context).usePlugin(object : AbstractMarkwonPlugin() {
|
||||||
@ -168,6 +196,5 @@ class MessageUtils(val context: Context) {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "MessageUtils"
|
private const val TAG = "MessageUtils"
|
||||||
const val MAX_REPLY_LENGTH = 250
|
const val MAX_REPLY_LENGTH = 250
|
||||||
const val HTTPS_PROTOCOL = "https://"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user