Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
8ccb7bf0
Commit
8ccb7bf0
authored
Jul 14, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Noop ordered list
parent
c32b8dc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
49 deletions
+90
-49
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+1
-0
MessageParser.kt
...src/main/java/chat/rocket/android/helper/MessageParser.kt
+37
-1
item_message.xml
app/src/main/res/layout/item_message.xml
+51
-47
dependencies.gradle
dependencies.gradle
+1
-1
No files found.
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
8ccb7bf0
...
@@ -247,6 +247,7 @@ class AppModule {
...
@@ -247,6 +247,7 @@ class AppModule {
val
res
=
context
.
resources
val
res
=
context
.
resources
return
SpannableConfiguration
.
builder
(
context
)
return
SpannableConfiguration
.
builder
(
context
)
.
theme
(
SpannableTheme
.
builder
()
.
theme
(
SpannableTheme
.
builder
()
.
blockMargin
(
0
)
.
linkColor
(
res
.
getColor
(
R
.
color
.
colorAccent
))
.
linkColor
(
res
.
getColor
(
R
.
color
.
colorAccent
))
.
build
())
.
build
())
.
build
()
.
build
()
...
...
app/src/main/java/chat/rocket/android/helper/MessageParser.kt
View file @
8ccb7bf0
...
@@ -10,6 +10,7 @@ import androidx.core.content.res.ResourcesCompat
...
@@ -10,6 +10,7 @@ import androidx.core.content.res.ResourcesCompat
import
android.text.Spanned
import
android.text.Spanned
import
android.text.style.ClickableSpan
import
android.text.style.ClickableSpan
import
android.text.style.ReplacementSpan
import
android.text.style.ReplacementSpan
import
android.text.style.StyleSpan
import
android.util.Patterns
import
android.util.Patterns
import
android.view.View
import
android.view.View
import
chat.rocket.android.R
import
chat.rocket.android.R
...
@@ -23,6 +24,10 @@ import chat.rocket.common.model.SimpleUser
...
@@ -23,6 +24,10 @@ import chat.rocket.common.model.SimpleUser
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
org.commonmark.node.AbstractVisitor
import
org.commonmark.node.AbstractVisitor
import
org.commonmark.node.Document
import
org.commonmark.node.Document
import
org.commonmark.node.ListItem
import
org.commonmark.node.Node
import
org.commonmark.node.OrderedList
import
org.commonmark.node.Paragraph
import
org.commonmark.node.Text
import
org.commonmark.node.Text
import
ru.noties.markwon.Markwon
import
ru.noties.markwon.Markwon
import
ru.noties.markwon.SpannableBuilder
import
ru.noties.markwon.SpannableBuilder
...
@@ -59,7 +64,7 @@ class MessageParser @Inject constructor(
...
@@ -59,7 +64,7 @@ class MessageParser @Inject constructor(
val
builder
=
SpannableBuilder
()
val
builder
=
SpannableBuilder
()
val
content
=
EmojiRepository
.
shortnameToUnicode
(
text
,
true
)
val
content
=
EmojiRepository
.
shortnameToUnicode
(
text
,
true
)
val
parentNode
=
parser
.
parse
(
toLenientMarkdown
(
content
))
val
parentNode
=
parser
.
parse
(
toLenientMarkdown
(
content
))
parentNode
.
accept
(
Spannable
MarkdownVisitor
(
configuration
,
builder
))
parentNode
.
accept
(
MarkdownVisitor
(
configuration
,
builder
))
parentNode
.
accept
(
LinkVisitor
(
builder
))
parentNode
.
accept
(
LinkVisitor
(
builder
))
parentNode
.
accept
(
EmojiVisitor
(
configuration
,
builder
))
parentNode
.
accept
(
EmojiVisitor
(
configuration
,
builder
))
message
.
mentions
?.
let
{
message
.
mentions
?.
let
{
...
@@ -138,6 +143,37 @@ class MessageParser @Inject constructor(
...
@@ -138,6 +143,37 @@ class MessageParser @Inject constructor(
}
}
}
}
class
MarkdownVisitor
(
configuration
:
SpannableConfiguration
,
val
builder
:
SpannableBuilder
)
:
SpannableMarkdownVisitor
(
configuration
,
builder
)
{
/**
* NOOP
*/
override
fun
visit
(
orderedList
:
OrderedList
)
{
var
number
=
orderedList
.
startNumber
val
delimiter
=
orderedList
.
delimiter
var
node
:
Node
?
=
orderedList
.
firstChild
while
(
node
!=
null
)
{
if
(
node
is
ListItem
)
{
newLine
()
builder
.
append
(
"$number$delimiter "
)
super
.
visit
(
node
.
firstChild
as
Paragraph
)
newLine
()
}
number
++
node
=
node
.
next
}
}
private
fun
newLine
()
{
if
(
builder
.
length
()
>
0
&&
'\n'
!=
builder
.
lastChar
())
{
builder
.
append
(
'\n'
)
}
}
}
class
LinkVisitor
(
private
val
builder
:
SpannableBuilder
)
:
AbstractVisitor
()
{
class
LinkVisitor
(
private
val
builder
:
SpannableBuilder
)
:
AbstractVisitor
()
{
override
fun
visit
(
text
:
Text
)
{
override
fun
visit
(
text
:
Text
)
{
...
...
app/src/main/res/layout/item_message.xml
View file @
8ccb7bf0
...
@@ -8,10 +8,10 @@
...
@@ -8,10 +8,10 @@
android:background=
"?android:attr/selectableItemBackground"
android:background=
"?android:attr/selectableItemBackground"
android:clickable=
"true"
android:clickable=
"true"
android:focusable=
"true"
android:focusable=
"true"
android:paddingBottom=
"@dimen/message_item_top_and_bottom_padding"
android:paddingEnd=
"@dimen/screen_edge_left_and_right_padding"
android:paddingStart=
"@dimen/screen_edge_left_and_right_padding"
android:paddingStart=
"@dimen/screen_edge_left_and_right_padding"
android:paddingTop=
"@dimen/message_item_top_and_bottom_padding"
>
android:paddingTop=
"@dimen/message_item_top_and_bottom_padding"
android:paddingEnd=
"@dimen/screen_edge_left_and_right_padding"
android:paddingBottom=
"@dimen/message_item_top_and_bottom_padding"
>
<LinearLayout
<LinearLayout
android:id=
"@+id/new_messages_notif"
android:id=
"@+id/new_messages_notif"
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
android:visibility=
"gone"
android:visibility=
"gone"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
tools:visibility=
"visible"
>
tools:visibility=
"visible"
>
...
@@ -56,63 +56,67 @@
...
@@ -56,63 +56,67 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/new_messages_notif"
/>
app:layout_constraintTop_toBottomOf=
"@+id/new_messages_notif"
/>
<LinearLayout
<TextView
android:id=
"@+id/top_container"
android:id=
"@+id/text_sender"
android:layout_width=
"0dp"
style=
"@style/Sender.Name.TextView"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginStart=
"16dp"
a
ndroid:orientation=
"horizontal
"
a
pp:layout_constraintHorizontal_bias=
"0.5
"
app:layout_constraintStart_toEndOf=
"@+id/layout_avatar"
app:layout_constraintStart_toEndOf=
"@+id/layout_avatar"
app:layout_constraintTop_toBottomOf=
"@+id/new_messages_notif"
>
app:layout_constraintTop_toBottomOf=
"@+id/new_messages_notif"
tools:text=
"Ronald Perkins"
/>
<TextView
<TextView
android:id=
"@+id/text_sender"
android:id=
"@+id/text_message_time"
style=
"@style/Sender.Name.TextView"
style=
"@style/Timestamp.TextView"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
tools:text=
"Ronald Perkins"
/>
android:layout_marginStart=
"4dp"
app:layout_constraintBaseline_toBaselineOf=
"@+id/text_sender"
<TextView
app:layout_constraintHorizontal_bias=
"0.5"
android:id=
"@+id/text_message_time"
app:layout_constraintStart_toEndOf=
"@+id/text_sender"
style=
"@style/Timestamp.TextView"
tools:text=
"11:45 PM"
/>
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"10dp"
tools:text=
"11:45 PM"
/>
<TextView
<TextView
android:id=
"@+id/text_edit_indicator"
android:id=
"@+id/text_edit_indicator"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"8dp"
android:layout_marginStart=
"4dp"
android:text=
"@string/msg_edited"
android:text=
"@string/msg_edited"
android:textStyle=
"italic"
android:textStyle=
"italic"
android:visibility=
"gone"
android:visibility=
"gone"
tools:visibility=
"visible"
/>
app:layout_constraintBaseline_toBaselineOf=
"@+id/text_sender"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/text_message_time"
tools:visibility=
"visible"
/>
<ImageView
<ImageView
android:id=
"@+id/image_star_indicator"
android:id=
"@+id/image_star_indicator"
android:layout_width=
"14dp"
android:layout_width=
"14dp"
android:layout_height=
"14dp"
android:layout_height=
"14dp"
android:layout_gravity=
"center_vertical"
android:layout_gravity=
"center_vertical"
android:layout_marginStart=
"8dp"
android:layout_marginStart=
"4dp"
android:layout_marginTop=
"2dp"
android:layout_marginTop=
"2dp"
android:src=
"@drawable/ic_action_message_star_24dp"
android:src=
"@drawable/ic_action_message_star_24dp"
android:visibility=
"gone"
android:visibility=
"gone"
tools:visibility=
"visible"
/>
app:layout_constraintBottom_toBottomOf=
"@+id/text_sender"
</LinearLayout>
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/text_edit_indicator"
app:layout_constraintTop_toTopOf=
"@+id/text_sender"
tools:visibility=
"visible"
/>
<TextView
<TextView
android:id=
"@+id/text_content"
android:id=
"@+id/text_content"
style=
"@style/Message.TextView"
style=
"@style/Message.TextView"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"2dp"
android:layout_marginTop=
"5dp"
android:layout_marginTop=
"5dp"
a
pp:layout_constraintStart_toStartOf=
"@+id/top_container
"
a
ndroid:layout_marginBottom=
"2dp
"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/top_container"
android:layout_marginEnd=
"4dp"
android:textDirection=
"locale"
app:layout_constraintStart_toStartOf=
"@+id/text_sender"
app:layout_constraintTop_toBottomOf=
"@+id/text_sender"
tools:text=
"This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!"
/>
tools:text=
"This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!"
/>
<include
<include
...
...
dependencies.gradle
View file @
8ccb7bf0
...
@@ -33,7 +33,7 @@ ext {
...
@@ -33,7 +33,7 @@ ext {
fresco
:
'1.9.0'
,
fresco
:
'1.9.0'
,
kotshi
:
'1.0.2'
,
kotshi
:
'1.0.2'
,
frescoImageViewer
:
'0.5.1'
,
frescoImageViewer
:
'0.5.1'
,
markwon
:
'1.0.
3
'
,
markwon
:
'1.0.
6
'
,
aVLoadingIndicatorView:
'2.1.3'
,
aVLoadingIndicatorView:
'2.1.3'
,
flexbox
:
'0.3.2'
,
flexbox
:
'0.3.2'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment