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
59961967
Commit
59961967
authored
Jul 02, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Group emojis by its tone
parent
35ed646c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
6 deletions
+51
-6
Emoji.kt
emoji/src/main/java/chat/rocket/android/emoji/Emoji.kt
+3
-1
EmojiRepository.kt
...rc/main/java/chat/rocket/android/emoji/EmojiRepository.kt
+37
-5
Fitzpatrick.kt
emoji/src/main/java/chat/rocket/android/emoji/Fitzpatrick.kt
+11
-0
No files found.
emoji/src/main/java/chat/rocket/android/emoji/Emoji.kt
View file @
59961967
...
@@ -6,5 +6,7 @@ data class Emoji(
...
@@ -6,5 +6,7 @@ data class Emoji(
val
unicode
:
String
,
val
unicode
:
String
,
val
keywords
:
List
<
String
>,
val
keywords
:
List
<
String
>,
val
category
:
String
,
val
category
:
String
,
val
count
:
Int
=
0
val
count
:
Int
=
0
,
val
siblings
:
MutableCollection
<
Emoji
>
=
mutableListOf
(),
val
fitzpatrick
:
Fitzpatrick
=
Fitzpatrick
.
Default
)
)
\ No newline at end of file
emoji/src/main/java/chat/rocket/android/emoji/EmojiRepository.kt
View file @
59961967
...
@@ -12,6 +12,7 @@ import java.util.*
...
@@ -12,6 +12,7 @@ import java.util.*
import
java.util.regex.Pattern
import
java.util.regex.Pattern
object
EmojiRepository
{
object
EmojiRepository
{
private
val
FITZPATRICK_REGEX
=
"(.*)_(tone[0-9]):"
.
toRegex
(
RegexOption
.
IGNORE_CASE
)
private
val
shortNameToUnicode
=
HashMap
<
String
,
String
>()
private
val
shortNameToUnicode
=
HashMap
<
String
,
String
>()
private
val
SHORTNAME_PATTERN
=
Pattern
.
compile
(
":([-+\\w]+):"
)
private
val
SHORTNAME_PATTERN
=
Pattern
.
compile
(
":([-+\\w]+):"
)
private
val
ALL_EMOJIS
=
mutableListOf
<
Emoji
>()
private
val
ALL_EMOJIS
=
mutableListOf
<
Emoji
>()
...
@@ -24,9 +25,9 @@ object EmojiRepository {
...
@@ -24,9 +25,9 @@ object EmojiRepository {
cachedTypeface
=
Typeface
.
createFromAsset
(
context
.
assets
,
"fonts/emojione-android.ttf"
)
cachedTypeface
=
Typeface
.
createFromAsset
(
context
.
assets
,
"fonts/emojione-android.ttf"
)
val
stream
=
context
.
assets
.
open
(
path
)
val
stream
=
context
.
assets
.
open
(
path
)
val
emojis
=
loadEmojis
(
stream
)
val
emojis
=
loadEmojis
(
stream
)
emojis
.
forEach
{
emojis
.
forEach
{
emoji
->
val
unicodeIntList
=
mutableListOf
<
Int
>()
val
unicodeIntList
=
mutableListOf
<
Int
>()
it
.
unicode
.
split
(
"-"
).
forEach
{
emoji
.
unicode
.
split
(
"-"
).
forEach
{
val
value
=
it
.
toInt
(
16
)
val
value
=
it
.
toInt
(
16
)
if
(
value
>=
0
x10000
)
{
if
(
value
>=
0
x10000
)
{
val
surrogatePair
=
calculateSurrogatePairs
(
value
)
val
surrogatePair
=
calculateSurrogatePairs
(
value
)
...
@@ -38,12 +39,43 @@ object EmojiRepository {
...
@@ -38,12 +39,43 @@ object EmojiRepository {
}
}
val
unicodeIntArray
=
unicodeIntList
.
toIntArray
()
val
unicodeIntArray
=
unicodeIntList
.
toIntArray
()
val
unicode
=
String
(
unicodeIntArray
,
0
,
unicodeIntArray
.
size
)
val
unicode
=
String
(
unicodeIntArray
,
0
,
unicodeIntArray
.
size
)
ALL_EMOJIS
.
add
(
it
.
copy
(
unicode
=
unicode
))
val
emojiWithUnicode
=
emoji
.
copy
(
unicode
=
unicode
)
if
(
hasFitzpatrick
(
emoji
.
shortname
))
{
val
matchResult
=
FITZPATRICK_REGEX
.
find
(
emoji
.
shortname
)
val
prefix
=
matchResult
!!
.
groupValues
[
1
]
+
":"
val
fitzpatrick
=
getFitzpatric
(
matchResult
.
groupValues
[
2
])
val
defaultEmoji
=
ALL_EMOJIS
.
firstOrNull
{
it
.
shortname
==
prefix
}
val
emojiWithFitzpatrick
=
emojiWithUnicode
.
copy
(
fitzpatrick
=
fitzpatrick
)
if
(
defaultEmoji
!=
null
)
{
defaultEmoji
.
siblings
.
add
(
emojiWithFitzpatrick
)
}
else
{
// This emoji doesn't have a default tone, ie. :man_in_business_suit_levitating_tone1:
// In this case, the default emoji becomes the first toned one.
ALL_EMOJIS
.
add
(
emojiWithFitzpatrick
)
}
}
else
{
ALL_EMOJIS
.
add
(
emojiWithUnicode
)
}
shortNameToUnicode
.
apply
{
shortNameToUnicode
.
apply
{
put
(
it
.
shortname
,
unicode
)
put
(
emoji
.
shortname
,
unicode
)
it
.
shortnameAlternates
.
forEach
{
alternate
->
put
(
alternate
,
unicode
)
}
emoji
.
shortnameAlternates
.
forEach
{
alternate
->
put
(
alternate
,
unicode
)
}
}
}
}
}
}
private
fun
hasFitzpatrick
(
shortname
:
String
):
Boolean
{
return
FITZPATRICK_REGEX
matches
shortname
}
private
fun
getFitzpatric
(
type
:
String
):
Fitzpatrick
{
return
when
(
type
)
{
Fitzpatrick
.
LightTone
.
type
->
Fitzpatrick
.
LightTone
Fitzpatrick
.
MediumTone
.
type
->
Fitzpatrick
.
MediumTone
Fitzpatrick
.
MediumLightTone
.
type
->
Fitzpatrick
.
MediumLightTone
Fitzpatrick
.
MediumDarkTone
.
type
->
Fitzpatrick
.
MediumDarkTone
Fitzpatrick
.
DarkTone
.
type
->
Fitzpatrick
.
DarkTone
else
->
Fitzpatrick
.
Default
}
}
}
/**
/**
...
...
emoji/src/main/java/chat/rocket/android/emoji/Fitzpatrick.kt
0 → 100644
View file @
59961967
package
chat.rocket.android.emoji
sealed
class
Fitzpatrick
(
val
type
:
String
)
{
object
Default
:
Fitzpatrick
(
""
)
object
LightTone
:
Fitzpatrick
(
"tone1"
)
object
MediumLightTone
:
Fitzpatrick
(
"tone2"
)
object
MediumTone
:
Fitzpatrick
(
"tone3"
)
object
MediumDarkTone
:
Fitzpatrick
(
"tone4"
)
object
DarkTone
:
Fitzpatrick
(
"tone5"
)
}
\ No newline at end of file
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