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
37b86ee9
Commit
37b86ee9
authored
Jul 19, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Load custom emojis from host
parent
60570bc8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
17 deletions
+59
-17
RocketChatApplication.kt
...ain/java/chat/rocket/android/app/RocketChatApplication.kt
+2
-4
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+3
-1
MainPresenter.kt
...va/chat/rocket/android/main/presentation/MainPresenter.kt
+33
-0
MainActivity.kt
...src/main/java/chat/rocket/android/main/ui/MainActivity.kt
+1
-0
Emoji.kt
emoji/src/main/java/chat/rocket/android/emoji/Emoji.kt
+3
-2
EmojiRepository.kt
...rc/main/java/chat/rocket/android/emoji/EmojiRepository.kt
+16
-9
EmojiCategory.kt
.../java/chat/rocket/android/emoji/internal/EmojiCategory.kt
+1
-1
No files found.
app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt
View file @
37b86ee9
...
@@ -19,7 +19,6 @@ import chat.rocket.android.server.domain.GetCurrentServerInteractor
...
@@ -19,7 +19,6 @@ import chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.GetSettingsInteractor
import
chat.rocket.android.server.domain.GetSettingsInteractor
import
chat.rocket.android.server.domain.SITE_URL
import
chat.rocket.android.server.domain.SITE_URL
import
chat.rocket.android.server.domain.TokenRepository
import
chat.rocket.android.server.domain.TokenRepository
import
chat.rocket.android.emoji.EmojiRepository
import
com.crashlytics.android.Crashlytics
import
com.crashlytics.android.Crashlytics
import
com.crashlytics.android.core.CrashlyticsCore
import
com.crashlytics.android.core.CrashlyticsCore
import
com.facebook.drawee.backends.pipeline.DraweeConfig
import
com.facebook.drawee.backends.pipeline.DraweeConfig
...
@@ -87,7 +86,6 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -87,7 +86,6 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
context
=
WeakReference
(
applicationContext
)
context
=
WeakReference
(
applicationContext
)
AndroidThreeTen
.
init
(
this
)
AndroidThreeTen
.
init
(
this
)
EmojiRepository
.
load
(
this
)
setupCrashlytics
()
setupCrashlytics
()
setupFresco
()
setupFresco
()
...
...
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
37b86ee9
...
@@ -80,7 +80,9 @@ class ChatRoomsPresenter @Inject constructor(
...
@@ -80,7 +80,9 @@ class ChatRoomsPresenter @Inject constructor(
}
else
{
}
else
{
val
id
=
if
(
isDirectMessage
&&
!
open
)
{
val
id
=
if
(
isDirectMessage
&&
!
open
)
{
retryIO
(
"createDirectMessage($name)"
)
{
retryIO
(
"createDirectMessage($name)"
)
{
client
.
createDirectMessage
(
name
)
client
.
createDirectMessage
(
name
,
callback
=
{
b
,
s
->
})
}
}
val
fromTo
=
mutableListOf
(
myself
.
id
,
id
).
apply
{
val
fromTo
=
mutableListOf
(
myself
.
id
,
id
).
apply
{
sort
()
sort
()
...
...
app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt
View file @
37b86ee9
package
chat.rocket.android.main.presentation
package
chat.rocket.android.main.presentation
import
android.content.Context
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.db.DatabaseManagerFactory
import
chat.rocket.android.db.DatabaseManagerFactory
import
chat.rocket.android.emoji.Emoji
import
chat.rocket.android.emoji.EmojiRepository
import
chat.rocket.android.emoji.Fitzpatrick
import
chat.rocket.android.emoji.internal.EmojiCategory
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.main.uimodel.NavHeaderUiModel
import
chat.rocket.android.main.uimodel.NavHeaderUiModel
import
chat.rocket.android.main.uimodel.NavHeaderUiModelMapper
import
chat.rocket.android.main.uimodel.NavHeaderUiModelMapper
...
@@ -27,6 +32,7 @@ import chat.rocket.common.model.UserStatus
...
@@ -27,6 +32,7 @@ import chat.rocket.common.model.UserStatus
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.realtime.setDefaultStatus
import
chat.rocket.core.internal.realtime.setDefaultStatus
import
chat.rocket.core.internal.rest.getCustomEmojis
import
chat.rocket.core.internal.rest.logout
import
chat.rocket.core.internal.rest.logout
import
chat.rocket.core.internal.rest.me
import
chat.rocket.core.internal.rest.me
import
chat.rocket.core.internal.rest.unregisterPushToken
import
chat.rocket.core.internal.rest.unregisterPushToken
...
@@ -116,6 +122,33 @@ class MainPresenter @Inject constructor(
...
@@ -116,6 +122,33 @@ class MainPresenter @Inject constructor(
}
}
}
}
fun
loadEmojis
()
{
launchUI
(
strategy
)
{
val
customEmojiList
=
mutableListOf
<
Emoji
>()
try
{
for
(
customEmoji
in
client
.
getCustomEmojis
())
{
customEmojiList
.
add
(
Emoji
(
shortname
=
":${customEmoji.name}:"
,
category
=
EmojiCategory
.
CUSTOM
.
name
,
url
=
"$currentServer/emoji-custom/${customEmoji.name}.${customEmoji.extension}"
,
count
=
0
,
fitzpatrick
=
Fitzpatrick
.
Default
,
keywords
=
customEmoji
.
aliases
,
shortnameAlternates
=
customEmoji
.
aliases
,
siblings
=
mutableListOf
(),
unicode
=
""
))
}
EmojiRepository
.
load
(
view
as
Context
,
customEmojis
=
customEmojiList
)
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
EmojiRepository
.
load
(
view
as
Context
)
}
}
}
/**
/**
* Logout from current server.
* Logout from current server.
*/
*/
...
...
app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt
View file @
37b86ee9
...
@@ -77,6 +77,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
...
@@ -77,6 +77,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
presenter
.
connect
()
presenter
.
connect
()
presenter
.
loadServerAccounts
()
presenter
.
loadServerAccounts
()
presenter
.
loadCurrentInfo
()
presenter
.
loadCurrentInfo
()
presenter
.
loadEmojis
()
setupToolbar
()
setupToolbar
()
setupNavigationView
()
setupNavigationView
()
}
}
...
...
emoji/src/main/java/chat/rocket/android/emoji/Emoji.kt
View file @
37b86ee9
...
@@ -8,5 +8,6 @@ data class Emoji(
...
@@ -8,5 +8,6 @@ data class Emoji(
val
category
:
String
,
val
category
:
String
,
val
count
:
Int
=
0
,
val
count
:
Int
=
0
,
val
siblings
:
MutableCollection
<
Emoji
>
=
mutableListOf
(),
val
siblings
:
MutableCollection
<
Emoji
>
=
mutableListOf
(),
val
fitzpatrick
:
Fitzpatrick
=
Fitzpatrick
.
Default
val
fitzpatrick
:
Fitzpatrick
=
Fitzpatrick
.
Default
,
val
url
:
String
?
=
null
// Filled for custom emojis
)
)
emoji/src/main/java/chat/rocket/android/emoji/EmojiRepository.kt
View file @
37b86ee9
...
@@ -3,12 +3,8 @@ package chat.rocket.android.emoji
...
@@ -3,12 +3,8 @@ package chat.rocket.android.emoji
import
android.content.Context
import
android.content.Context
import
android.content.SharedPreferences
import
android.content.SharedPreferences
import
android.graphics.Typeface
import
android.graphics.Typeface
import
android.os.SystemClock
import
chat.rocket.android.emoji.internal.EmojiCategory
import
chat.rocket.android.emoji.internal.EmojiCategory
import
chat.rocket.android.emoji.internal.PREF_EMOJI_RECENTS
import
chat.rocket.android.emoji.internal.PREF_EMOJI_RECENTS
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.withContext
import
kotlinx.coroutines.experimental.yield
import
org.json.JSONArray
import
org.json.JSONArray
import
org.json.JSONObject
import
org.json.JSONObject
import
java.io.BufferedReader
import
java.io.BufferedReader
...
@@ -16,6 +12,7 @@ import java.io.InputStream
...
@@ -16,6 +12,7 @@ import java.io.InputStream
import
java.io.InputStreamReader
import
java.io.InputStreamReader
import
java.util.*
import
java.util.*
import
java.util.regex.Pattern
import
java.util.regex.Pattern
import
kotlin.collections.ArrayList
import
kotlin.coroutines.experimental.buildSequence
import
kotlin.coroutines.experimental.buildSequence
object
EmojiRepository
{
object
EmojiRepository
{
...
@@ -27,14 +24,24 @@ object EmojiRepository {
...
@@ -27,14 +24,24 @@ object EmojiRepository {
private
lateinit
var
preferences
:
SharedPreferences
private
lateinit
var
preferences
:
SharedPreferences
internal
lateinit
var
cachedTypeface
:
Typeface
internal
lateinit
var
cachedTypeface
:
Typeface
fun
load
(
context
:
Context
,
path
:
String
=
"emoji.json"
)
{
fun
load
(
context
:
Context
,
customEmojis
:
List
<
Emoji
>
=
emptyList
(),
path
:
String
=
"emoji.json"
)
{
preferences
=
context
.
getSharedPreferences
(
"emoji"
,
Context
.
MODE_PRIVATE
)
preferences
=
context
.
getSharedPreferences
(
"emoji"
,
Context
.
MODE_PRIVATE
)
ALL_EMOJIS
.
clear
()
ALL_EMOJIS
.
clear
()
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
).
also
{
emojis
.
forEach
{
emoji
->
it
.
addAll
(
customEmojis
)
}.
toList
()
for
(
emoji
in
emojis
)
{
val
unicodeIntList
=
mutableListOf
<
Int
>()
val
unicodeIntList
=
mutableListOf
<
Int
>()
// If empty it's a custom emoji.
if
(
emoji
.
unicode
.
isEmpty
())
{
ALL_EMOJIS
.
add
(
emoji
)
continue
}
emoji
.
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
)
{
...
@@ -95,7 +102,7 @@ object EmojiRepository {
...
@@ -95,7 +102,7 @@ object EmojiRepository {
internal
fun
getEmojiSequenceByCategory
(
category
:
EmojiCategory
):
Sequence
<
Emoji
>
{
internal
fun
getEmojiSequenceByCategory
(
category
:
EmojiCategory
):
Sequence
<
Emoji
>
{
val
list
=
ALL_EMOJIS
.
filter
{
it
.
category
.
toLowerCase
()
==
category
.
name
.
toLowerCase
()
}
val
list
=
ALL_EMOJIS
.
filter
{
it
.
category
.
toLowerCase
()
==
category
.
name
.
toLowerCase
()
}
return
buildSequence
{
return
buildSequence
{
list
.
forEach
{
list
.
forEach
{
yield
(
it
)
yield
(
it
)
}
}
...
@@ -163,7 +170,7 @@ object EmojiRepository {
...
@@ -163,7 +170,7 @@ object EmojiRepository {
return
result
return
result
}
}
private
fun
loadEmojis
(
stream
:
InputStream
):
List
<
Emoji
>
{
private
fun
loadEmojis
(
stream
:
InputStream
):
Mutable
List
<
Emoji
>
{
val
emojisJSON
=
JSONArray
(
inputStreamToString
(
stream
))
val
emojisJSON
=
JSONArray
(
inputStreamToString
(
stream
))
val
emojis
=
ArrayList
<
Emoji
>(
emojisJSON
.
length
());
val
emojis
=
ArrayList
<
Emoji
>(
emojisJSON
.
length
());
for
(
i
in
0
until
emojisJSON
.
length
())
{
for
(
i
in
0
until
emojisJSON
.
length
())
{
...
...
emoji/src/main/java/chat/rocket/android/emoji/internal/EmojiCategory.kt
View file @
37b86ee9
...
@@ -7,7 +7,7 @@ import chat.rocket.android.emoji.EmojiRepository
...
@@ -7,7 +7,7 @@ import chat.rocket.android.emoji.EmojiRepository
import
chat.rocket.android.emoji.EmojiTypefaceSpan
import
chat.rocket.android.emoji.EmojiTypefaceSpan
import
chat.rocket.android.emoji.R
import
chat.rocket.android.emoji.R
internal
enum
class
EmojiCategory
{
enum
class
EmojiCategory
{
RECENTS
{
RECENTS
{
override
fun
resourceIcon
()
=
R
.
drawable
.
ic_emoji_recents
override
fun
resourceIcon
()
=
R
.
drawable
.
ic_emoji_recents
...
...
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