klint cleaning

This commit is contained in:
Valere 2019-11-15 11:40:05 +01:00 committed by Benoit Marty
parent 6bd7257cf2
commit 2a4cdec020
2 changed files with 8 additions and 7 deletions

View File

@ -70,7 +70,8 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use
private fun createTextContent(text: CharSequence, autoMarkdown: Boolean): TextContent { private fun createTextContent(text: CharSequence, autoMarkdown: Boolean): TextContent {
if (autoMarkdown) { if (autoMarkdown) {
val source = transformPills(text,"[%2\$s](https://matrix.to/#/%1\$s)") ?: text.toString() val source = transformPills(text, "[%2\$s](https://matrix.to/#/%1\$s)")
?: text.toString()
val document = parser.parse(source) val document = parser.parse(source)
val htmlText = renderer.render(document) val htmlText = renderer.render(document)
@ -78,9 +79,9 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use
return TextContent(source, htmlText) return TextContent(source, htmlText)
} }
} else { } else {
//Try to detect pills // Try to detect pills
transformPills(text, "<a href=\"https://matrix.to/#/%1\$s\">%2\$s</a>")?.let { transformPills(text, "<a href=\"https://matrix.to/#/%1\$s\">%2\$s</a>")?.let {
return TextContent(text.toString(),it) return TextContent(text.toString(), it)
} }
} }
@ -88,7 +89,7 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use
} }
private fun transformPills(text: CharSequence, private fun transformPills(text: CharSequence,
template : String) template: String)
: String? { : String? {
val bufSB = StringBuffer() val bufSB = StringBuffer()
var currIndex = 0 var currIndex = 0
@ -98,9 +99,9 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use
pills.forEachIndexed { _, urlSpan -> pills.forEachIndexed { _, urlSpan ->
val start = it.getSpanStart(urlSpan) val start = it.getSpanStart(urlSpan)
val end = it.getSpanEnd(urlSpan) val end = it.getSpanEnd(urlSpan)
//We want to replace with the pill with a html link // We want to replace with the pill with a html link
bufSB.append(text, currIndex, start) bufSB.append(text, currIndex, start)
bufSB.append(String.format(template,urlSpan.userId,urlSpan.displayName)) bufSB.append(String.format(template, urlSpan.userId, urlSpan.displayName))
currIndex = end currIndex = end
} }
bufSB.append(text, currIndex, text.length) bufSB.append(text, currIndex, text.length)

View File

@ -386,7 +386,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
val finalText = legacyRiotQuoteText(textMsg, action.text.toString()) val finalText = legacyRiotQuoteText(textMsg, action.text.toString())
//TODO check for pills? // TODO check for pills?
// TODO Refactor this, just temporary for quotes // TODO Refactor this, just temporary for quotes
val parser = Parser.builder().build() val parser = Parser.builder().build()