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
ecee2a7f
Commit
ecee2a7f
authored
Feb 02, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some comments and a few refactoring
parent
bfc6656f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
MessageParser.kt
...src/main/java/chat/rocket/android/helper/MessageParser.kt
+13
-12
No files found.
app/src/main/java/chat/rocket/android/helper/MessageParser.kt
View file @
ecee2a7f
...
@@ -25,10 +25,20 @@ class MessageParser @Inject constructor(val context: Application, private val co
...
@@ -25,10 +25,20 @@ class MessageParser @Inject constructor(val context: Application, private val co
private
val
parser
=
Markwon
.
createParser
()
private
val
parser
=
Markwon
.
createParser
()
/**
* Render a markdown text message to Spannable.
*
* @param text The text message containing markdown syntax.
* @param quote An optional message to be quoted either by a quote or reply action.
* @param urls A list of urls to convert to markdown link syntax.
*
* @return A Spannable with the parsed markdown.
*/
fun
renderMarkdown
(
text
:
String
,
quote
:
MessageViewModel
?,
urls
:
List
<
Url
>):
CharSequence
{
fun
renderMarkdown
(
text
:
String
,
quote
:
MessageViewModel
?,
urls
:
List
<
Url
>):
CharSequence
{
val
builder
=
SpannableBuilder
()
val
builder
=
SpannableBuilder
()
var
content
:
String
=
text
var
content
:
String
=
text
// Replace all url links to markdown url syntax.
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})"
)
}
}
...
@@ -97,18 +107,9 @@ class MessageParser @Inject constructor(val context: Application, private val co
...
@@ -97,18 +107,9 @@ class MessageParser @Inject constructor(val context: Application, private val co
}
}
}
}
class
QuoteMarginSpan
:
LeadingMarginSpan
,
LineHeightSpan
{
class
QuoteMarginSpan
(
b
:
Drawable
,
pad
:
Int
)
:
LeadingMarginSpan
,
LineHeightSpan
{
private
var
mDrawable
:
Drawable
?
=
null
private
var
mDrawable
:
Drawable
?
=
b
private
var
mPad
:
Int
=
0
private
var
mPad
:
Int
=
pad
constructor
(
b
:
Drawable
)
{
mDrawable
=
b
}
constructor
(
b
:
Drawable
,
pad
:
Int
)
{
mDrawable
=
b
mPad
=
pad
}
override
fun
getLeadingMargin
(
first
:
Boolean
):
Int
{
override
fun
getLeadingMargin
(
first
:
Boolean
):
Int
{
return
mDrawable
!!
.
intrinsicWidth
+
mPad
return
mDrawable
!!
.
intrinsicWidth
+
mPad
...
...
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