Commit 593b38d8 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix a bug that keeps the emoji keyboard always opened after sendind a message...

Fix a bug that keeps the emoji keyboard always opened after sendind a message with a emoji at the end.
parent 49fecc78
...@@ -317,8 +317,8 @@ class ChatRoomPresenter @Inject constructor( ...@@ -317,8 +317,8 @@ class ChatRoomPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
try { try {
// ignore message for now, will receive it on the stream // ignore message for now, will receive it on the stream
val id = UUID.randomUUID().toString()
if (messageId == null) { if (messageId == null) {
val id = UUID.randomUUID().toString()
val username = userHelper.username() val username = userHelper.username()
val newMessage = Message( val newMessage = Message(
id = id, id = id,
...@@ -371,13 +371,12 @@ class ChatRoomPresenter @Inject constructor( ...@@ -371,13 +371,12 @@ class ChatRoomPresenter @Inject constructor(
} else { } else {
client.updateMessage(chatRoomId, messageId, text) client.updateMessage(chatRoomId, messageId, text)
} }
clearDraftMessage()
clearUnfinishedMessage()
view.enableSendMessageButton()
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.d(ex, "Error sending message...") Timber.e(ex, "Error sending message...")
jobSchedulerInteractor.scheduleSendingMessages() jobSchedulerInteractor.scheduleSendingMessages()
} finally { } finally {
view.clearMessageComposition(true)
view.enableSendMessageButton() view.enableSendMessageButton()
} }
} }
...@@ -1268,7 +1267,6 @@ class ChatRoomPresenter @Inject constructor( ...@@ -1268,7 +1267,6 @@ class ChatRoomPresenter @Inject constructor(
roles = chatRoles, isBroadcast = chatIsBroadcast, isRoom = true roles = chatRoles, isBroadcast = chatIsBroadcast, isRoom = true
) )
) )
val roomMessages = messagesRepository.getByRoomId(streamedMessage.roomId) val roomMessages = messagesRepository.getByRoomId(streamedMessage.roomId)
val index = roomMessages.indexOfFirst { msg -> msg.id == streamedMessage.id } val index = roomMessages.indexOfFirst { msg -> msg.id == streamedMessage.id }
if (index > -1) { if (index > -1) {
...@@ -1294,13 +1292,13 @@ class ChatRoomPresenter @Inject constructor( ...@@ -1294,13 +1292,13 @@ class ChatRoomPresenter @Inject constructor(
* *
* @param unfinishedMessage The unfinished message to save. * @param unfinishedMessage The unfinished message to save.
*/ */
fun saveUnfinishedMessage(unfinishedMessage: String) { fun saveDraftMessage(unfinishedMessage: String) {
if (unfinishedMessage.isNotBlank()) { if (unfinishedMessage.isNotBlank()) {
localRepository.save(draftKey, unfinishedMessage) localRepository.save(draftKey, unfinishedMessage)
} }
} }
fun clearUnfinishedMessage() { fun clearDraftMessage() {
localRepository.clear(draftKey) localRepository.clear(draftKey)
} }
/** /**
...@@ -1309,7 +1307,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -1309,7 +1307,7 @@ class ChatRoomPresenter @Inject constructor(
* *
* @return Returns the unfinished message, null otherwise. * @return Returns the unfinished message, null otherwise.
*/ */
fun getUnfinishedMessage(): String? { fun getDraftUnfinishedMessage(): String? {
return localRepository.get(draftKey) return localRepository.get(draftKey)
} }
} }
...@@ -307,7 +307,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -307,7 +307,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
showToolbarTitle(chatRoomName) showToolbarTitle(chatRoomName)
showToolbarChatRoomIcon(chatRoomType) showToolbarChatRoomIcon(chatRoomType)
} }
getUnfinishedMessage() getDraftMessage()
analyticsManager.logScreenView(ScreenViewEvent.ChatRoom) analyticsManager.logScreenView(ScreenViewEvent.ChatRoom)
} }
...@@ -322,7 +322,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -322,7 +322,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
recycler_view.removeOnScrollListener(onScrollListener) recycler_view.removeOnScrollListener(onScrollListener)
recycler_view.removeOnLayoutChangeListener(layoutChangeListener) recycler_view.removeOnLayoutChangeListener(layoutChangeListener)
presenter.saveUnfinishedMessage(text_message.text.toString()) presenter.saveDraftMessage(text_message.text.toString())
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
unsubscribeComposeTextMessage() unsubscribeComposeTextMessage()
presenter.disconnect() presenter.disconnect()
...@@ -436,6 +436,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -436,6 +436,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
presenter.loadActiveMembers(chatRoomId, chatRoomType, filterSelfOut = true) presenter.loadActiveMembers(chatRoomId, chatRoomType, filterSelfOut = true)
empty_chat_view.isVisible = adapter.itemCount == 0 empty_chat_view.isVisible = adapter.itemCount == 0
dismissEmojiKeyboard()
} }
} }
...@@ -444,6 +445,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -444,6 +445,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
adapter.clearData() adapter.clearData()
adapter.prependData(dataSet) adapter.prependData(dataSet)
empty_chat_view.isVisible = adapter.itemCount == 0 empty_chat_view.isVisible = adapter.itemCount == 0
dismissEmojiKeyboard()
} }
override fun onRoomUpdated(roomUiModel: RoomUiModel) { override fun onRoomUpdated(roomUiModel: RoomUiModel) {
...@@ -501,25 +503,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -501,25 +503,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
showMessage(getString(R.string.msg_invalid_file)) showMessage(getString(R.string.msg_invalid_file))
} }
override fun showNewMessage(message: List<BaseUiModel<*>>, isMessageReceived: Boolean) {
ui {
adapter.prependData(message)
if (isMessageReceived && button_fab.isVisible) {
newMessageCount++
if (newMessageCount <= 99)
text_count.text = newMessageCount.toString()
else
text_count.text = "99+"
text_count.isVisible = true
} else if (!button_fab.isVisible)
recycler_view.scrollToPosition(0)
verticalScrollOffset.set(0)
empty_chat_view.isVisible = adapter.itemCount == 0
}
}
override fun disableSendMessageButton() { override fun disableSendMessageButton() {
ui { button_send.isEnabled = false } ui { button_send.isEnabled = false }
} }
...@@ -543,6 +526,28 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -543,6 +526,28 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
} }
override fun showNewMessage(message: List<BaseUiModel<*>>, isMessageReceived: Boolean) {
ui {
adapter.prependData(message)
if (isMessageReceived && button_fab.isVisible) {
newMessageCount++
if (newMessageCount <= 99) {
text_count.text = newMessageCount.toString()
} else {
text_count.text = "99+"
}
text_count.isVisible = true
}
else if (!button_fab.isVisible) {
recycler_view.scrollToPosition(0)
}
verticalScrollOffset.set(0)
empty_chat_view.isVisible = adapter.itemCount == 0
dismissEmojiKeyboard()
}
}
override fun dispatchUpdateMessage(index: Int, message: List<BaseUiModel<*>>) { override fun dispatchUpdateMessage(index: Int, message: List<BaseUiModel<*>>) {
ui { ui {
// TODO - investigate WHY we get a empty list here // TODO - investigate WHY we get a empty list here
...@@ -555,6 +560,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -555,6 +560,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} else { } else {
showNewMessage(message, true) showNewMessage(message, true)
} }
dismissEmojiKeyboard()
} }
} }
...@@ -863,7 +869,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -863,7 +869,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
var textMessage = citation ?: "" var textMessage = citation ?: ""
textMessage += text_message.textContent textMessage += text_message.textContent
sendMessage(textMessage) sendMessage(textMessage)
clearMessageComposition(true)
} }
button_show_attachment_options.setOnClickListener { button_show_attachment_options.setOnClickListener {
...@@ -935,8 +940,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -935,8 +940,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
} }
private fun getUnfinishedMessage() { private fun getDraftMessage() {
val unfinishedMessage = presenter.getUnfinishedMessage() val unfinishedMessage = presenter.getDraftUnfinishedMessage()
if (unfinishedMessage.isNotNullNorEmpty()) { if (unfinishedMessage.isNotNullNorEmpty()) {
text_message.setText(unfinishedMessage) text_message.setText(unfinishedMessage)
} }
......
...@@ -25,9 +25,7 @@ import kotlinx.android.synthetic.main.dialog_skin_tone_chooser.view.* ...@@ -25,9 +25,7 @@ import kotlinx.android.synthetic.main.dialog_skin_tone_chooser.view.*
import kotlinx.coroutines.experimental.android.UI import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.launch
class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow(context, view) { class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow(context, view) {
private lateinit var viewPager: ViewPager private lateinit var viewPager: ViewPager
private lateinit var tabLayout: TabLayout private lateinit var tabLayout: TabLayout
private lateinit var searchView: View private lateinit var searchView: View
...@@ -84,7 +82,7 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow ...@@ -84,7 +82,7 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
.setCancelable(true) .setCancelable(true)
.create() .create()
with (view) { with(view) {
image_view_default_tone.setOnClickListener { image_view_default_tone.setOnClickListener {
dialog.dismiss() dialog.dismiss()
changeSkinTone(Fitzpatrick.Default) changeSkinTone(Fitzpatrick.Default)
...@@ -138,7 +136,10 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow ...@@ -138,7 +136,10 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
return when (tone) { return when (tone) {
Fitzpatrick.Default -> ContextCompat.getColor(context, R.color.tone_default) Fitzpatrick.Default -> ContextCompat.getColor(context, R.color.tone_default)
Fitzpatrick.LightTone -> ContextCompat.getColor(context, R.color.tone_light) Fitzpatrick.LightTone -> ContextCompat.getColor(context, R.color.tone_light)
Fitzpatrick.MediumLightTone -> ContextCompat.getColor(context, R.color.tone_medium_light) Fitzpatrick.MediumLightTone -> ContextCompat.getColor(
context,
R.color.tone_medium_light
)
Fitzpatrick.MediumTone -> ContextCompat.getColor(context, R.color.tone_medium) Fitzpatrick.MediumTone -> ContextCompat.getColor(context, R.color.tone_medium)
Fitzpatrick.MediumDarkTone -> ContextCompat.getColor(context, R.color.tone_medium_dark) Fitzpatrick.MediumDarkTone -> ContextCompat.getColor(context, R.color.tone_medium_dark)
Fitzpatrick.DarkTone -> ContextCompat.getColor(context, R.color.tone_dark) Fitzpatrick.DarkTone -> ContextCompat.getColor(context, R.color.tone_dark)
...@@ -151,7 +152,7 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow ...@@ -151,7 +152,7 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
is EmojiKeyboardListener -> it is EmojiKeyboardListener -> it
else -> { else -> {
val fragments = (it as AppCompatActivity).supportFragmentManager.fragments val fragments = (it as AppCompatActivity).supportFragmentManager.fragments
if (fragments.size == 0 || !(fragments[0] is EmojiKeyboardListener)) { if (fragments.size == 0 || fragments[0] !is EmojiKeyboardListener) {
// Since the app can arrive in an inconsistent state at this point, do not throw // Since the app can arrive in an inconsistent state at this point, do not throw
// throw IllegalStateException("activity/fragment should implement Listener interface") // throw IllegalStateException("activity/fragment should implement Listener interface")
null null
...@@ -190,7 +191,6 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow ...@@ -190,7 +191,6 @@ class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow
} }
class EmojiTextWatcher(private val editor: EditText) : TextWatcher { class EmojiTextWatcher(private val editor: EditText) : TextWatcher {
@Volatile @Volatile
private var emojiToRemove = mutableListOf<EmojiTypefaceSpan>() private var emojiToRemove = mutableListOf<EmojiTypefaceSpan>()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment