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
8d85f6a2
Commit
8d85f6a2
authored
Jul 03, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save and restore selected skin color to preferences
parent
260f76fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
19 deletions
+35
-19
EmojiKeyboardPopup.kt
...main/java/chat/rocket/android/emoji/EmojiKeyboardPopup.kt
+12
-4
EmojiRepository.kt
...rc/main/java/chat/rocket/android/emoji/EmojiRepository.kt
+5
-15
Fitzpatrick.kt
emoji/src/main/java/chat/rocket/android/emoji/Fitzpatrick.kt
+14
-0
Preferences.kt
...in/java/chat/rocket/android/emoji/internal/Preferences.kt
+4
-0
No files found.
emoji/src/main/java/chat/rocket/android/emoji/EmojiKeyboardPopup.kt
View file @
8d85f6a2
...
...
@@ -14,10 +14,12 @@ import androidx.annotation.ColorInt
import
androidx.appcompat.app.AlertDialog
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.content.ContextCompat
import
androidx.core.content.edit
import
androidx.core.graphics.drawable.DrawableCompat
import
androidx.viewpager.widget.ViewPager
import
chat.rocket.android.emoji.internal.EmojiCategory
import
chat.rocket.android.emoji.internal.EmojiPagerAdapter
import
chat.rocket.android.emoji.internal.PREF_EMOJI_SKIN_TONE
import
com.google.android.material.tabs.TabLayout
...
...
@@ -62,6 +64,11 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
changeColorView
.
setOnClickListener
{
showSkinToneChooser
()
}
val
sharedPreferences
=
context
.
getSharedPreferences
(
"emoji"
,
Context
.
MODE_PRIVATE
)
sharedPreferences
.
getString
(
PREF_EMOJI_SKIN_TONE
,
""
)
?.
let
{
changeSkinTone
(
Fitzpatrick
.
valueOf
(
it
))
}
}
private
fun
showSkinToneChooser
()
{
...
...
@@ -110,10 +117,15 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
DrawableCompat
.
setTint
(
wrappedDrawable
,
getFitzpatrickColor
(
tone
))
(
changeColorView
as
ImageView
).
setImageDrawable
(
wrappedDrawable
)
adapter
.
setFitzpatrick
(
tone
)
}
@ColorInt
private
fun
getFitzpatrickColor
(
tone
:
Fitzpatrick
):
Int
{
val
sharedPreferences
=
context
.
getSharedPreferences
(
"emoji"
,
Context
.
MODE_PRIVATE
)
sharedPreferences
.
edit
{
putString
(
PREF_EMOJI_SKIN_TONE
,
tone
.
type
)
}
return
when
(
tone
)
{
Fitzpatrick
.
Default
->
ContextCompat
.
getColor
(
context
,
R
.
color
.
tone_default
)
Fitzpatrick
.
LightTone
->
ContextCompat
.
getColor
(
context
,
R
.
color
.
tone_light
)
...
...
@@ -204,8 +216,4 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
override
fun
onTextChanged
(
s
:
CharSequence
,
start
:
Int
,
before
:
Int
,
count
:
Int
)
{
}
}
companion
object
{
const
val
PREF_EMOJI_RECENTS
=
"PREF_EMOJI_RECENTS"
}
}
\ No newline at end of file
emoji/src/main/java/chat/rocket/android/emoji/EmojiRepository.kt
View file @
8d85f6a2
...
...
@@ -4,6 +4,7 @@ import android.content.Context
import
android.content.SharedPreferences
import
android.graphics.Typeface
import
chat.rocket.android.emoji.internal.EmojiCategory
import
chat.rocket.android.emoji.internal.PREF_EMOJI_RECENTS
import
org.json.JSONArray
import
org.json.JSONObject
import
java.io.BufferedReader
...
...
@@ -45,7 +46,7 @@ object EmojiRepository {
if
(
hasFitzpatrick
(
emoji
.
shortname
))
{
val
matchResult
=
FITZPATRICK_REGEX
.
find
(
emoji
.
shortname
)
val
prefix
=
matchResult
!!
.
groupValues
[
1
]
+
":"
val
fitzpatrick
=
getFitzpatrick
(
matchResult
.
groupValues
[
2
])
val
fitzpatrick
=
Fitzpatrick
.
valueOf
(
matchResult
.
groupValues
[
2
])
val
defaultEmoji
=
ALL_EMOJIS
.
firstOrNull
{
it
.
shortname
==
prefix
}
val
emojiWithFitzpatrick
=
emojiWithUnicode
.
copy
(
fitzpatrick
=
fitzpatrick
)
if
(
defaultEmoji
!=
null
)
{
...
...
@@ -69,17 +70,6 @@ object EmojiRepository {
return
FITZPATRICK_REGEX
matches
shortname
}
private
fun
getFitzpatrick
(
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
}
}
/**
* Get all loaded emojis as list of Emoji objects.
*
...
...
@@ -112,14 +102,14 @@ object EmojiRepository {
*/
internal
fun
addToRecents
(
emoji
:
Emoji
)
{
val
emojiShortname
=
emoji
.
shortname
val
recentsJson
=
JSONObject
(
preferences
.
getString
(
EmojiKeyboardPopup
.
PREF_EMOJI_RECENTS
,
"{}"
))
val
recentsJson
=
JSONObject
(
preferences
.
getString
(
PREF_EMOJI_RECENTS
,
"{}"
))
if
(
recentsJson
.
has
(
emojiShortname
))
{
val
useCount
=
recentsJson
.
getInt
(
emojiShortname
)
recentsJson
.
put
(
emojiShortname
,
useCount
+
1
)
}
else
{
recentsJson
.
put
(
emojiShortname
,
1
)
}
preferences
.
edit
().
putString
(
EmojiKeyboardPopup
.
PREF_EMOJI_RECENTS
,
recentsJson
.
toString
()).
apply
()
preferences
.
edit
().
putString
(
PREF_EMOJI_RECENTS
,
recentsJson
.
toString
()).
apply
()
}
/**
...
...
@@ -129,7 +119,7 @@ object EmojiRepository {
*/
internal
fun
getRecents
():
List
<
Emoji
>
{
val
list
=
mutableListOf
<
Emoji
>()
val
recentsJson
=
JSONObject
(
preferences
.
getString
(
EmojiKeyboardPopup
.
PREF_EMOJI_RECENTS
,
"{}"
))
val
recentsJson
=
JSONObject
(
preferences
.
getString
(
PREF_EMOJI_RECENTS
,
"{}"
))
for
(
shortname
in
recentsJson
.
keys
())
{
val
emoji
=
getEmojiByShortname
(
shortname
)
emoji
?.
let
{
...
...
emoji/src/main/java/chat/rocket/android/emoji/Fitzpatrick.kt
View file @
8d85f6a2
...
...
@@ -13,4 +13,18 @@ sealed class Fitzpatrick(val type: String) {
object
MediumTone
:
Fitzpatrick
(
"tone3"
)
object
MediumDarkTone
:
Fitzpatrick
(
"tone4"
)
object
DarkTone
:
Fitzpatrick
(
"tone5"
)
companion
object
{
fun
valueOf
(
type
:
String
):
Fitzpatrick
{
return
when
(
type
)
{
""
->
Default
"tone1"
->
LightTone
"tone2"
->
MediumLightTone
"tone3"
->
MediumTone
"tone4"
->
MediumDarkTone
"tone5"
->
DarkTone
else
->
throw
IllegalArgumentException
(
"Fitzpatrick type '$type' is invalid"
)
}
}
}
}
\ No newline at end of file
emoji/src/main/java/chat/rocket/android/emoji/internal/Preferences.kt
0 → 100644
View file @
8d85f6a2
package
chat.rocket.android.emoji.internal
internal
const
val
PREF_EMOJI_RECENTS
=
"PREF_EMOJI_RECENTS"
internal
const
val
PREF_EMOJI_SKIN_TONE
=
"PREF_EMOJI_SKIN_TONE"
\ 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