Commit f25e08a5 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix some markdown issues

parent a0486d28
......@@ -14,26 +14,28 @@ import chat.rocket.android.R
import chat.rocket.android.helper.MessageParser
import chat.rocket.android.util.content
import ru.noties.markwon.Markwon
import javax.inject.Inject
class ActionSnackbar : BaseTransientBottomBar<ActionSnackbar> {
companion object {
fun make(parentViewGroup: ViewGroup, content: String): ActionSnackbar {
fun make(parentViewGroup: ViewGroup, content: String = "", parser: MessageParser): ActionSnackbar {
val context = parentViewGroup.context
val view = LayoutInflater.from(context).inflate(R.layout.message_action_bar, parentViewGroup, false)
val citationSnackbar = ActionSnackbar(parentViewGroup, view, CallbackImpl(view))
citationSnackbar.messageTextView = view.findViewById(R.id.text_view_action_text) as TextView
citationSnackbar.titleTextView = view.findViewById(R.id.text_view_action_title) as TextView
citationSnackbar.cancelView = view.findViewById(R.id.image_view_action_cancel_quote) as ImageView
citationSnackbar.duration = BaseTransientBottomBar.LENGTH_INDEFINITE
val spannable = SpannableString(content)
citationSnackbar.marginDrawable = context.getDrawable(R.drawable.quote)
spannable.setSpan(MessageParser.QuoteMarginSpan(citationSnackbar.marginDrawable, 10), 0, content.length, 0)
citationSnackbar.messageTextView.content = spannable
return citationSnackbar
val actionSnackbar = ActionSnackbar(parentViewGroup, view, CallbackImpl(view))
actionSnackbar.parser = parser
actionSnackbar.messageTextView = view.findViewById(R.id.text_view_action_text) as TextView
actionSnackbar.titleTextView = view.findViewById(R.id.text_view_action_title) as TextView
actionSnackbar.cancelView = view.findViewById(R.id.image_view_action_cancel_quote) as ImageView
actionSnackbar.duration = BaseTransientBottomBar.LENGTH_INDEFINITE
val spannable = Markwon.markdown(context, content).trim()
actionSnackbar.marginDrawable = context.getDrawable(R.drawable.quote)
actionSnackbar.messageTextView.content = spannable
return actionSnackbar
}
}
lateinit var parser: MessageParser
lateinit var cancelView: View
private lateinit var messageTextView: TextView
private lateinit var titleTextView: TextView
......@@ -41,7 +43,7 @@ class ActionSnackbar : BaseTransientBottomBar<ActionSnackbar> {
var text: String = ""
set(value) {
val spannable = Markwon.markdown(this.context, value) as Spannable
val spannable = parser.renderMarkdown(value) as Spannable
spannable.setSpan(MessageParser.QuoteMarginSpan(marginDrawable, 10), 0, spannable.length, 0)
messageTextView.content = spannable
}
......
......@@ -16,6 +16,7 @@ import chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import chat.rocket.android.chatroom.presentation.ChatRoomView
import chat.rocket.android.chatroom.viewmodel.MessageViewModel
import chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import chat.rocket.android.helper.MessageParser
import chat.rocket.android.util.inflate
import chat.rocket.android.util.setVisible
import chat.rocket.android.util.textContent
......@@ -43,6 +44,7 @@ private const val BUNDLE_IS_CHAT_ROOM_READ_ONLY = "is_chat_room_read_only"
class ChatRoomFragment : Fragment(), ChatRoomView {
@Inject lateinit var presenter: ChatRoomPresenter
@Inject lateinit var parser: MessageParser
private lateinit var chatRoomId: String
private lateinit var chatRoomName: String
private lateinit var chatRoomType: String
......@@ -205,7 +207,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
}
private fun setupActionSnackbar() {
actionSnackbar = ActionSnackbar.make(message_list_container, "")
actionSnackbar = ActionSnackbar.make(message_list_container, parser = parser)
actionSnackbar.cancelView.setOnClickListener({
clearActionMessage()
})
......
......@@ -45,14 +45,14 @@ class MessageParser @Inject constructor(val context: Application, private val co
var content: String = text
// Replace all url links to markdown url syntax.
urls?.let {
if (urls != null) {
for (url in urls) {
content = content.replace(url.url, "[${url.url}](${url.url})")
}
}
val parentNode = parser.parse(toLenientMarkdown(content))
parentNode.accept(SpannableMarkdownVisitor(configuration, builder))
parentNode.accept(QuoteMessageBodyVisitor(context, configuration, builder))
quote?.apply {
var quoteNode = parser.parse("> $sender $time")
parentNode.appendChild(quoteNode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment