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
1ee16334
Commit
1ee16334
authored
Feb 15, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement loading the emoji keyboard from the message composer
parent
be00b615
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
15 deletions
+74
-15
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+33
-14
KeyboardHelper.kt
...rc/main/java/chat/rocket/android/helper/KeyboardHelper.kt
+30
-0
Text.kt
...src/main/java/chat/rocket/android/util/extensions/Text.kt
+11
-1
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
1ee16334
...
...
@@ -18,8 +18,12 @@ import chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.presentation.ChatRoomView
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.KeyboardHelper
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.util.extensions.*
import
chat.rocket.android.widget.emoji.Emoji
import
chat.rocket.android.widget.emoji.EmojiBottomPicker
import
chat.rocket.android.widget.emoji.EmojiParser
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_attachment_options.*
...
...
@@ -43,7 +47,7 @@ private const val BUNDLE_CHAT_ROOM_TYPE = "chat_room_type"
private
const
val
BUNDLE_IS_CHAT_ROOM_READ_ONLY
=
"is_chat_room_read_only"
private
const
val
REQUEST_CODE_FOR_PERFORM_SAF
=
42
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
{
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
,
EmojiBottomPicker
.
OnEmojiClickCallback
{
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
parser
:
MessageParser
private
lateinit
var
adapter
:
ChatRoomAdapter
...
...
@@ -217,6 +221,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
}
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
.
setSelection
(
cursorPosition
+
emoji
.
unicode
.
length
)
KeyboardHelper
.
showSoftKeyboard
(
text_message
)
}
private
fun
setupComposer
()
{
if
(
isChatRoomReadOnly
)
{
text_room_is_read_only
.
setVisible
(
true
)
...
...
@@ -265,6 +277,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
hideAttachmentOptions
()
},
600
)
}
button_add_reaction
.
setOnClickListener
{
activity
?.
let
{
KeyboardHelper
.
hideSoftKeyboard
(
it
)
EmojiBottomPicker
().
show
(
it
.
supportFragmentManager
,
"EmojiBottomPicker"
)
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/helper/KeyboardHelper.kt
View file @
1ee16334
...
...
@@ -2,6 +2,11 @@ package chat.rocket.android.helper
import
android.graphics.Rect
import
android.view.View
import
android.content.Context.INPUT_METHOD_SERVICE
import
android.app.Activity
import
android.content.Context
import
android.view.inputmethod.InputMethodManager
object
KeyboardHelper
{
...
...
@@ -21,4 +26,29 @@ object KeyboardHelper {
val
heightDiff
=
rootView
.
bottom
-
rect
.
bottom
return
heightDiff
>
softKeyboardHeight
*
dm
.
density
}
/**
* Hide the soft keyboard.
*
* @param activity The current focused activity.
*/
fun
hideSoftKeyboard
(
activity
:
Activity
)
{
val
currentFocus
=
activity
.
currentFocus
if
(
currentFocus
!=
null
)
{
val
inputMethodManager
=
activity
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
inputMethodManager
.
hideSoftInputFromWindow
(
currentFocus
.
windowToken
,
0
)
}
}
/**
* Show the soft keyboard for the given view.
*
* @param view View to receive input focus.
*/
fun
showSoftKeyboard
(
view
:
View
)
{
if
(
view
.
requestFocus
())
{
val
inputMethodManager
=
view
.
context
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
inputMethodManager
.
toggleSoftInput
(
InputMethodManager
.
SHOW_FORCED
,
0
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/extensions/Text.kt
View file @
1ee16334
...
...
@@ -7,6 +7,10 @@ import android.widget.TextView
import
android.provider.OpenableColumns
import
android.webkit.MimeTypeMap
import
android.provider.MediaStore
import
android.text.Spannable
import
android.text.Spanned
import
android.text.TextUtils
import
chat.rocket.android.widget.emoji.EmojiParser
import
ru.noties.markwon.Markwon
fun
String
.
ifEmpty
(
value
:
String
):
String
{
...
...
@@ -40,7 +44,13 @@ var TextView.content: CharSequence
set
(
value
)
{
Markwon
.
unscheduleDrawables
(
this
)
Markwon
.
unscheduleTableRows
(
this
)
if
(
value
is
Spanned
)
{
val
result
=
EmojiParser
.
parse
(
value
.
toString
())
as
Spannable
TextUtils
.
copySpansFrom
(
value
,
0
,
value
.
length
,
Any
::
class
.
java
,
result
,
0
)
text
=
result
}
else
{
text
=
value
}
Markwon
.
scheduleDrawables
(
this
)
Markwon
.
scheduleTableRows
(
this
)
}
...
...
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