Clean code

This commit is contained in:
ganfra 2020-07-24 11:30:27 +02:00
parent 794b89c041
commit 20c7d80bb1
2 changed files with 25 additions and 9 deletions

View File

@ -353,17 +353,23 @@ class MessageItemFactory @Inject constructor(
codeVisitor.visit(localFormattedBody)
when (codeVisitor.codeKind) {
CodeVisitor.Kind.BLOCK -> {
val codeFormattedBlock = htmlRenderer.get().render(localFormattedBody) ?: messageContent.formattedBody!!
buildCodeBlockItem(codeFormattedBlock, informationData, highlight, callback, attributes)
val codeFormattedBlock = htmlRenderer.get().render(localFormattedBody)
if (codeFormattedBlock == null) {
buildFormattedTextItem(messageContent, informationData, highlight, callback, attributes)
} else {
buildCodeBlockItem(codeFormattedBlock, informationData, highlight, callback, attributes)
}
}
CodeVisitor.Kind.INLINE -> {
val codeFormatted = htmlRenderer.get().render(localFormattedBody)?: messageContent.formattedBody!!
buildMessageTextItem(codeFormatted, false, informationData, highlight, callback, attributes)
val codeFormatted = htmlRenderer.get().render(localFormattedBody)
if (codeFormatted == null) {
buildFormattedTextItem(messageContent, informationData, highlight, callback, attributes)
} else {
buildMessageTextItem(codeFormatted, false, informationData, highlight, callback, attributes)
}
}
CodeVisitor.Kind.NONE -> {
val compressed = htmlCompressor.compress(messageContent.formattedBody!!)
val formattedBody = htmlRenderer.get().render(compressed)
buildMessageTextItem(formattedBody, true, informationData, highlight, callback, attributes)
buildFormattedTextItem(messageContent, informationData, highlight, callback, attributes)
}
}
} else {
@ -371,6 +377,16 @@ class MessageItemFactory @Inject constructor(
}
}
private fun buildFormattedTextItem(messageContent: MessageTextContent,
informationData: MessageInformationData,
highlight: Boolean,
callback: TimelineEventController.Callback?,
attributes: AbsMessageItem.Attributes): MessageTextItem? {
val compressed = htmlCompressor.compress(messageContent.formattedBody!!)
val formattedBody = htmlRenderer.get().render(compressed)
return buildMessageTextItem(formattedBody, true, informationData, highlight, callback, attributes)
}
private fun buildMessageTextItem(body: CharSequence,
isFormatted: Boolean,
informationData: MessageInformationData,

View File

@ -44,7 +44,7 @@ class EventHtmlRenderer @Inject constructor(context: Context,
fun render(text: String): CharSequence {
return try {
markwon.toMarkdown(text)
}catch (failure: Throwable){
} catch (failure: Throwable) {
Timber.v("Fail to render $text to html")
text
}
@ -53,7 +53,7 @@ class EventHtmlRenderer @Inject constructor(context: Context,
fun render(node: Node): CharSequence? {
return try {
markwon.render(node)
}catch (failure: Throwable){
} catch (failure: Throwable) {
Timber.v("Fail to render $node to html")
return null
}