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
dd938089
Unverified
Commit
dd938089
authored
May 15, 2019
by
Filipe Brito
Committed by
GitHub
May 15, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2017 from dev-ritik/issue_2009
[BUG] Fixes custom emoji alias rendering issue
parents
e7fa51c0
1b91db74
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
24 deletions
+45
-24
build.gradle
emoji/build.gradle
+4
-1
EmojiParser.kt
emoji/src/main/java/chat/rocket/android/emoji/EmojiParser.kt
+41
-23
No files found.
emoji/build.gradle
View file @
dd938089
...
...
@@ -11,7 +11,7 @@ android {
minSdkVersion
versions
.
minSdk
targetSdkVersion
versions
.
targetSdk
versionCode
1
versionName
"
0.1
"
versionName
"
1.0.0
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions
{
...
...
@@ -40,6 +40,9 @@ dependencies {
implementation
libraries
.
androidKtx
implementation
libraries
.
material
implementation
libraries
.
glide
implementation
libraries
.
timber
implementation
libraries
.
room
kapt
libraries
.
roomProcessor
...
...
emoji/src/main/java/chat/rocket/android/emoji/EmojiParser.kt
View file @
dd938089
...
...
@@ -7,15 +7,11 @@ import android.text.Spannable
import
android.text.SpannableString
import
android.text.Spanned
import
android.text.style.ImageSpan
import
android.util.Log
import
com.bumptech.glide.Glide
import
com.bumptech.glide.load.engine.DiskCacheStrategy
import
com.bumptech.glide.load.resource.gif.GifDrawable
import
com.bumptech.glide.request.RequestOptions
import
kotlinx.coroutines.Deferred
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.async
import
timber.log.Timber
class
EmojiParser
{
...
...
@@ -31,7 +27,11 @@ class EmojiParser {
* @param factory Optional. A [Spannable.Factory] instance to reuse when creating [Spannable].
* @return A rendered Spannable containing any supported emoji.
*/
fun
parse
(
context
:
Context
,
text
:
CharSequence
,
factory
:
Spannable
.
Factory
?
=
null
):
CharSequence
{
fun
parse
(
context
:
Context
,
text
:
CharSequence
,
factory
:
Spannable
.
Factory
?
=
null
):
CharSequence
{
val
unicodedText
=
EmojiRepository
.
shortnameToUnicode
(
text
)
val
spannable
=
factory
?.
newSpannable
(
unicodedText
)
?:
SpannableString
.
valueOf
(
unicodedText
)
...
...
@@ -64,16 +64,20 @@ class EmojiParser {
inEmoji
=
true
}
else
{
if
(
inEmoji
)
{
spannable
.
setSpan
(
EmojiTypefaceSpan
(
"sans-serif"
,
typeface
),
emojiStart
,
offset
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
spannable
.
setSpan
(
EmojiTypefaceSpan
(
"sans-serif"
,
typeface
),
emojiStart
,
offset
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
inEmoji
=
false
}
offset
+=
count
if
(
offset
>=
length
&&
inEmoji
)
{
spannable
.
setSpan
(
EmojiTypefaceSpan
(
"sans-serif"
,
typeface
),
emojiStart
,
offset
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
spannable
.
setSpan
(
EmojiTypefaceSpan
(
"sans-serif"
,
typeface
),
emojiStart
,
offset
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
...
...
@@ -83,7 +87,7 @@ class EmojiParser {
return
spannable
.
also
{
sp
->
regex
.
findAll
(
spannable
).
iterator
().
forEach
{
match
->
customEmojis
.
find
{
it
.
shortname
.
toLowerCase
()
==
match
.
value
.
toLowerCase
(
)
}
?.
let
{
emoji
->
customEmojis
.
find
{
matchEmoji
(
it
,
match
.
value
)
}
?.
let
{
emoji
->
emoji
.
url
?.
let
{
url
->
try
{
val
glideRequest
=
if
(
url
.
endsWith
(
"gif"
,
true
))
{
...
...
@@ -100,16 +104,25 @@ class EmojiParser {
val
range
=
match
.
range
futureTarget
.
get
()
?.
let
{
image
->
if
(
image
is
Bitmap
)
{
spannable
.
setSpan
(
ImageSpan
(
context
,
image
),
range
.
start
,
range
.
endInclusive
+
1
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
spannable
.
setSpan
(
ImageSpan
(
context
,
image
),
range
.
start
,
range
.
endInclusive
+
1
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
else
if
(
image
is
GifDrawable
)
{
image
.
setBounds
(
0
,
0
,
image
.
intrinsicWidth
,
image
.
intrinsicHeight
)
spannable
.
setSpan
(
ImageSpan
(
image
),
range
.
start
,
range
.
endInclusive
+
1
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
image
.
setBounds
(
0
,
0
,
image
.
intrinsicWidth
,
image
.
intrinsicHeight
)
spannable
.
setSpan
(
ImageSpan
(
image
),
range
.
start
,
range
.
endInclusive
+
1
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
}
catch
(
ex
:
Throwable
)
{
Log
.
e
(
"EmojiParser"
,
""
,
ex
)
Timber
.
e
(
ex
)
}
}
}
...
...
@@ -117,12 +130,17 @@ class EmojiParser {
}
}
fun
parseAsync
(
context
:
Context
,
text
:
CharSequence
,
factory
:
Spannable
.
Factory
?
=
null
):
Deferred
<
CharSequence
>
{
return
GlobalScope
.
async
(
Dispatchers
.
IO
)
{
parse
(
context
,
text
,
factory
)
}
private
fun
matchEmoji
(
it
:
Emoji
,
text
:
String
):
Boolean
{
if
(
it
.
shortname
==
text
)
{
return
true
}
else
{
it
.
shortnameAlternates
.
forEach
{
if
(
":$it:"
==
text
)
{
return
true
}
}
return
false
}
}
}
}
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