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