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
80cacca2
Commit
80cacca2
authored
Feb 16, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix backspace deleting
parent
1023ed18
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
12 deletions
+65
-12
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+6
-3
Text.kt
...src/main/java/chat/rocket/android/util/extensions/Text.kt
+2
-1
EmojiBottomPicker.kt
...ava/chat/rocket/android/widget/emoji/EmojiBottomPicker.kt
+49
-0
EmojiLoader.kt
...main/java/chat/rocket/android/widget/emoji/EmojiLoader.kt
+4
-4
EmojiParser.kt
...main/java/chat/rocket/android/widget/emoji/EmojiParser.kt
+4
-4
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
80cacca2
...
...
@@ -223,8 +223,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiBottomPicker.OnEmojiClic
override
fun
onEmojiAdded
(
emoji
:
Emoji
)
{
val
cursorPosition
=
text_message
.
selectionStart
val
text
=
text_message
.
text
.
insert
(
cursorPosition
,
emoji
.
shortname
).
toString
()
text_message
.
content
=
EmojiParser
.
parse
(
text
)
text_message
.
text
.
insert
(
cursorPosition
,
EmojiParser
.
parse
(
emoji
.
shortname
))
text_message
.
setSelection
(
cursorPosition
+
emoji
.
unicode
.
length
)
KeyboardHelper
.
showSoftKeyboard
(
text_message
)
}
...
...
@@ -281,7 +280,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiBottomPicker.OnEmojiClic
button_add_reaction
.
setOnClickListener
{
activity
?.
let
{
KeyboardHelper
.
hideSoftKeyboard
(
it
)
EmojiBottomPicker
().
show
(
it
.
supportFragmentManager
,
"EmojiBottomPicker"
)
val
emojiBottomPicker
=
EmojiBottomPicker
()
text_message
.
apply
{
addTextChangedListener
(
EmojiBottomPicker
.
EmojiTextWatcher
(
this
))
}
emojiBottomPicker
.
show
(
it
.
supportFragmentManager
,
"EmojiBottomPicker"
)
}
}
}
...
...
app/src/main/java/chat/rocket/android/util/extensions/Text.kt
View file @
80cacca2
...
...
@@ -49,7 +49,8 @@ var TextView.content: CharSequence
TextUtils
.
copySpansFrom
(
value
,
0
,
value
.
length
,
Any
::
class
.
java
,
result
,
0
)
text
=
result
}
else
{
text
=
value
val
result
=
EmojiParser
.
parse
(
value
.
toString
())
as
Spannable
text
=
result
}
Markwon
.
scheduleDrawables
(
this
)
Markwon
.
scheduleTableRows
(
this
)
...
...
app/src/main/java/chat/rocket/android/widget/emoji/EmojiBottomPicker.kt
View file @
80cacca2
...
...
@@ -7,12 +7,17 @@ import android.support.design.widget.BottomSheetDialog
import
android.support.design.widget.TabLayout
import
android.support.v4.app.DialogFragment
import
android.support.v4.view.ViewPager
import
android.text.Editable
import
android.text.TextWatcher
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewTreeObserver
import
android.widget.EditText
import
android.widget.TextView
import
chat.rocket.android.R
import
java.util.concurrent.atomic.AtomicReference
import
java.util.function.UnaryOperator
open
class
EmojiBottomPicker
:
DialogFragment
()
{
...
...
@@ -90,6 +95,50 @@ open class EmojiBottomPicker : DialogFragment() {
return
BottomSheetDialog
(
context
!!
,
theme
)
}
class
EmojiTextWatcher
(
val
editor
:
EditText
)
:
TextWatcher
{
@Volatile
private
var
emojiToRemove
=
mutableListOf
<
EmojiTypefaceSpan
>()
override
fun
afterTextChanged
(
s
:
Editable
)
{
val
message
=
editor
.
getEditableText
()
// Commit the emoticons to be removed.
for
(
span
in
emojiToRemove
.
toList
())
{
val
start
=
message
.
getSpanStart
(
span
)
val
end
=
message
.
getSpanEnd
(
span
)
// Remove the span
message
.
removeSpan
(
span
)
// Remove the remaining emoticon text.
if
(
start
!=
end
)
{
message
.
delete
(
start
,
end
)
}
break
}
emojiToRemove
.
clear
()
}
override
fun
beforeTextChanged
(
s
:
CharSequence
,
start
:
Int
,
count
:
Int
,
after
:
Int
)
{
if
(
after
<
count
)
{
val
end
=
start
+
count
val
message
=
editor
.
getEditableText
()
val
list
=
message
.
getSpans
(
start
,
end
,
EmojiTypefaceSpan
::
class
.
java
)
for
(
span
in
list
)
{
val
spanStart
=
message
.
getSpanStart
(
span
)
val
spanEnd
=
message
.
getSpanEnd
(
span
)
if
(
spanStart
<
end
&&
spanEnd
>
start
)
{
// Add to remove list
emojiToRemove
.
add
(
span
)
}
}
}
}
override
fun
onTextChanged
(
s
:
CharSequence
,
start
:
Int
,
before
:
Int
,
count
:
Int
)
{
}
}
interface
OnEmojiClickCallback
{
/**
* Callback triggered after an emoji is selected on the picker.
...
...
app/src/main/java/chat/rocket/android/widget/emoji/EmojiLoader.kt
View file @
80cacca2
...
...
@@ -112,10 +112,10 @@ class EmojiLoader {
/**
* Replace shortnames to unicode characters.
*/
fun
shortnameToUnicode
(
input
:
String
,
removeIfUnsupported
:
Boolean
):
String
{
fun
shortnameToUnicode
(
input
:
CharSequence
,
removeIfUnsupported
:
Boolean
):
String
{
val
matcher
=
SHORTNAME_PATTERN
.
matcher
(
input
)
val
supported
=
Build
.
VERSION
.
SDK_INT
>=
16
var
result
:
String
=
input
var
result
:
String
=
input
.
toString
()
while
(
matcher
.
find
())
{
val
unicode
=
shortNameToUnicode
.
get
(
":${matcher.group(1)}:"
)
...
...
@@ -124,9 +124,9 @@ class EmojiLoader {
}
if
(
supported
)
{
result
=
inpu
t
.
replace
(
":"
+
matcher
.
group
(
1
)
+
":"
,
unicode
)
result
=
resul
t
.
replace
(
":"
+
matcher
.
group
(
1
)
+
":"
,
unicode
)
}
else
if
(!
supported
&&
removeIfUnsupported
)
{
result
=
inpu
t
.
replace
(
":"
+
matcher
.
group
(
1
)
+
":"
,
""
)
result
=
resul
t
.
replace
(
":"
+
matcher
.
group
(
1
)
+
":"
,
""
)
}
}
...
...
app/src/main/java/chat/rocket/android/widget/emoji/EmojiParser.kt
View file @
80cacca2
...
...
@@ -10,10 +10,10 @@ class EmojiParser {
* Spannable.
*
* @param text The text to parse
*
*
smiley = D83D DE03
* @return A rendered Spannable containing any supported emoji.
*/
fun
parse
(
text
:
String
):
CharSequence
{
fun
parse
(
text
:
CharSequence
):
CharSequence
{
val
unicodedText
=
EmojiLoader
.
shortnameToUnicode
(
text
,
true
)
val
spannableString
=
SpannableString
.
valueOf
(
unicodedText
)
// Look for groups of emojis, set a CustomTypefaceSpan with the emojione font
...
...
@@ -32,14 +32,14 @@ class EmojiParser {
}
else
{
if
(
inEmoji
)
{
spannableString
.
setSpan
(
EmojiTypefaceSpan
(
"sans-serif"
,
EmojiLoader
.
cachedTypeface
),
emojiStart
,
offset
,
Spanned
.
SPAN_
INCLUSIVE_IN
CLUSIVE
)
emojiStart
,
offset
,
Spanned
.
SPAN_
EXCLUSIVE_EX
CLUSIVE
)
}
inEmoji
=
false
}
offset
+=
count
if
(
offset
>=
length
&&
inEmoji
)
{
spannableString
.
setSpan
(
EmojiTypefaceSpan
(
"sans-serif"
,
EmojiLoader
.
cachedTypeface
),
emojiStart
,
offset
,
Spanned
.
SPAN_
INCLUSIVE_IN
CLUSIVE
)
emojiStart
,
offset
,
Spanned
.
SPAN_
EXCLUSIVE_EX
CLUSIVE
)
}
}
return
spannableString
...
...
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