Commit 541d705a authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix #57 multi-line comment

parent c671d9c7
......@@ -3,6 +3,7 @@ package chat.rocket.android.widget.message;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
......@@ -46,7 +47,29 @@ public class RocketChatMessageLayout extends LinearLayout {
public void setText(String messageBody) {
removeAllViews();
appendTextView(messageBody);
if (messageBody.contains("```")) {
boolean highlight = false;
for (final String chunk : TextUtils.split(messageBody.replace("\r\n", "\n"), "```")) {
final String trimmedChunk = chunk.replaceFirst("^\n", "").replaceFirst("\n$", "");
if (highlight) {
appendHighlightTextView(trimmedChunk);
} else if (trimmedChunk.length() > 0) {
appendTextView(trimmedChunk);
}
highlight = !highlight;
}
} else {
appendTextView(messageBody);
}
}
private void appendHighlightTextView(String text) {
TextView textView = (TextView) inflater.inflate(R.layout.message_body_highlight, this, false);
textView.setText(text);
Linkify.markup(textView);
addView(textView);
}
private void appendTextView(String text) {
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/highlight_text_background_color"/>
<stroke android:width="1dp" android:color="@color/highlight_text_border_color" />
<corners android:radius="4dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.RocketChat.MessageBody.Highlight"
android:background="@drawable/highlight_background_with_border"
android:padding="6dp"
android:layout_marginStart="0px"
android:layout_marginEnd="6dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
/>
\ No newline at end of file
......@@ -4,6 +4,11 @@
<style name="TextAppearance.RocketChat.MessageBody" parent="TextAppearance.AppCompat.Body1">
</style>
<style name="TextAppearance.RocketChat.MessageBody.Highlight">
<item name="android:textColor">@color/highlight_text_color</item>
<item name="android:typeface">monospace</item>
<item name="android:textStyle">bold</item>
</style>
<color name="highlight_text_color">#333</color>
<color name="highlight_text_background_color">#f8f8f8</color>
......
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