@@ -6,7 +6,6 @@ import android.content.ClipData
66import android.content.ClipboardManager
77import android.content.Context
88import android.content.Intent
9- import android.content.res.Configuration
109import android.graphics.drawable.Drawable
1110import android.net.Uri
1211import android.os.Bundle
@@ -308,7 +307,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
308307 showToolbarTitle(chatRoomName)
309308 showToolbarChatRoomIcon(chatRoomType)
310309 }
311- getUnfinishedMessage ()
310+ getDraftMessage ()
312311
313312 analyticsManager.logScreenView(ScreenViewEvent .ChatRoom )
314313 }
@@ -323,7 +322,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
323322 recycler_view.removeOnScrollListener(onScrollListener)
324323 recycler_view.removeOnLayoutChangeListener(layoutChangeListener)
325324
326- presenter.saveUnfinishedMessage (text_message.text.toString())
325+ presenter.saveDraftMessage (text_message.text.toString())
327326 handler.removeCallbacksAndMessages(null )
328327 unsubscribeComposeTextMessage()
329328 presenter.disconnect()
@@ -437,6 +436,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
437436 }
438437 presenter.loadActiveMembers(chatRoomId, chatRoomType, filterSelfOut = true )
439438 empty_chat_view.isVisible = adapter.itemCount == 0
439+ dismissEmojiKeyboard()
440440 }
441441 }
442442
@@ -445,6 +445,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
445445 adapter.clearData()
446446 adapter.prependData(dataSet)
447447 empty_chat_view.isVisible = adapter.itemCount == 0
448+ dismissEmojiKeyboard()
448449 }
449450
450451 override fun onRoomUpdated (roomUiModel : RoomUiModel ) {
@@ -502,25 +503,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
502503 showMessage(getString(R .string.msg_invalid_file))
503504 }
504505
505- override fun showNewMessage (message : List <BaseUiModel <* >>, isMessageReceived : Boolean ) {
506- ui {
507- adapter.prependData(message)
508- if (isMessageReceived && button_fab.isVisible) {
509- newMessageCount++
510-
511- if (newMessageCount <= 99 )
512- text_count.text = newMessageCount.toString()
513- else
514- text_count.text = " 99+"
515-
516- text_count.isVisible = true
517- } else if (! button_fab.isVisible)
518- recycler_view.scrollToPosition(0 )
519- verticalScrollOffset.set(0 )
520- empty_chat_view.isVisible = adapter.itemCount == 0
521- }
522- }
523-
524506 override fun disableSendMessageButton () {
525507 ui { button_send.isEnabled = false }
526508 }
@@ -544,6 +526,28 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
544526 }
545527 }
546528
529+ override fun showNewMessage (message : List <BaseUiModel <* >>, isMessageReceived : Boolean ) {
530+ ui {
531+ adapter.prependData(message)
532+ if (isMessageReceived && button_fab.isVisible) {
533+ newMessageCount++
534+ if (newMessageCount <= 99 ) {
535+ text_count.text = newMessageCount.toString()
536+ } else {
537+ text_count.text = " 99+"
538+ }
539+ text_count.isVisible = true
540+ }
541+
542+ else if (! button_fab.isVisible) {
543+ recycler_view.scrollToPosition(0 )
544+ }
545+ verticalScrollOffset.set(0 )
546+ empty_chat_view.isVisible = adapter.itemCount == 0
547+ dismissEmojiKeyboard()
548+ }
549+ }
550+
547551 override fun dispatchUpdateMessage (index : Int , message : List <BaseUiModel <* >>) {
548552 ui {
549553 // TODO - investigate WHY we get a empty list here
@@ -556,6 +560,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
556560 } else {
557561 showNewMessage(message, true )
558562 }
563+ dismissEmojiKeyboard()
559564 }
560565 }
561566
@@ -723,8 +728,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
723728 }
724729
725730 private fun setReactionButtonIcon (@DrawableRes drawableId : Int ) {
726- button_add_reaction .setImageResource(drawableId)
727- button_add_reaction .tag = drawableId
731+ button_add_reaction_or_show_keyboard .setImageResource(drawableId)
732+ button_add_reaction_or_show_keyboard .tag = drawableId
728733 }
729734
730735 override fun showFileSelection (filter : Array <String >? ) {
@@ -841,9 +846,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
841846
842847 subscribeComposeTextMessage()
843848 emojiKeyboardPopup = EmojiKeyboardPopup (activity!! , activity!! .findViewById(R .id.fragment_container))
849+
844850 emojiKeyboardPopup.listener = this
851+
845852 text_message.listener = object : ComposerEditText .ComposerEditTextListener {
846- override fun onKeyboardOpened () {}
853+ override fun onKeyboardOpened () {
854+ KeyboardHelper .showSoftKeyboard(text_message)
855+ }
847856
848857 override fun onKeyboardClosed () {
849858 activity?.let {
@@ -860,7 +869,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
860869 var textMessage = citation ? : " "
861870 textMessage + = text_message.textContent
862871 sendMessage(textMessage)
863- clearMessageComposition(true )
864872 }
865873
866874 button_show_attachment_options.setOnClickListener {
@@ -875,9 +883,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
875883 hideAttachmentOptions()
876884 }
877885
878- button_add_reaction.setOnClickListener { _ ->
879- openEmojiKeyboardPopup()
880- }
886+ button_add_reaction_or_show_keyboard.setOnClickListener { toggleKeyboard() }
881887
882888 button_take_a_photo.setOnClickListener {
883889 dispatchTakePictureIntent()
@@ -934,8 +940,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
934940 }
935941 }
936942
937- private fun getUnfinishedMessage () {
938- val unfinishedMessage = presenter.getUnfinishedMessage ()
943+ private fun getDraftMessage () {
944+ val unfinishedMessage = presenter.getDraftUnfinishedMessage ()
939945 if (unfinishedMessage.isNotNullNorEmpty()) {
940946 text_message.setText(unfinishedMessage)
941947 }
@@ -969,19 +975,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
969975 presenter.loadCommands()
970976 }
971977
972- private fun openEmojiKeyboardPopup () {
978+ // Shows the emoji or the system keyboard.
979+ private fun toggleKeyboard () {
973980 if (! emojiKeyboardPopup.isShowing) {
974- // If keyboard is visible, simply show the popup
975- if (emojiKeyboardPopup.isKeyboardOpen) {
976- emojiKeyboardPopup.showAtBottom()
977- } else {
978- // Open the text keyboard first and immediately after that show the emoji popup
979- text_message.isFocusableInTouchMode = true
980- text_message.requestFocus()
981- emojiKeyboardPopup.showAtBottomPending()
982- KeyboardHelper .showSoftKeyboard(text_message)
983- }
984- setReactionButtonIcon(R .drawable.ic_keyboard_black_24dp)
981+ openEmojiKeyboard()
985982 } else {
986983 // If popup is showing, simply dismiss it to show the underlying text keyboard
987984 dismissEmojiKeyboard()
@@ -1149,6 +1146,20 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
11491146 description = " This message was reported by a user from the Android app" )
11501147 }
11511148
1149+ fun openEmojiKeyboard () {
1150+ // If keyboard is visible, simply show the popup
1151+ if (emojiKeyboardPopup.isKeyboardOpen) {
1152+ emojiKeyboardPopup.showAtBottom()
1153+ } else {
1154+ // Open the text keyboard first and immediately after that show the emoji popup
1155+ text_message.isFocusableInTouchMode = true
1156+ text_message.requestFocus()
1157+ emojiKeyboardPopup.showAtBottomPending()
1158+ KeyboardHelper .showSoftKeyboard(text_message)
1159+ }
1160+ setReactionButtonIcon(R .drawable.ic_keyboard_black_24dp)
1161+ }
1162+
11521163 fun dismissEmojiKeyboard () {
11531164 // Check if the keyboard was ever initialized.
11541165 // It may be the case when you are looking a not joined room
0 commit comments