Commit 531c5a0f authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Draft messages improvements

parent 61318332
...@@ -123,6 +123,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -123,6 +123,7 @@ class ChatRoomPresenter @Inject constructor(
private var lastState = manager.state private var lastState = manager.state
private var typingStatusList = arrayListOf<String>() private var typingStatusList = arrayListOf<String>()
private val roomChangesChannel = Channel<Room>(Channel.CONFLATED) private val roomChangesChannel = Channel<Room>(Channel.CONFLATED)
private lateinit var unfinishedMessageKey: String
fun setupChatRoom( fun setupChatRoom(
roomId: String, roomId: String,
...@@ -132,9 +133,12 @@ class ChatRoomPresenter @Inject constructor( ...@@ -132,9 +133,12 @@ class ChatRoomPresenter @Inject constructor(
) { ) {
launch(CommonPool + strategy.jobs) { launch(CommonPool + strategy.jobs) {
try { try {
unfinishedMessageKey = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$roomId"
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) { chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName) client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else emptyList() } else {
emptyList()
}
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
Timber.e(ex) Timber.e(ex)
chatRoles = emptyList() chatRoles = emptyList()
...@@ -364,6 +368,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -364,6 +368,7 @@ class ChatRoomPresenter @Inject constructor(
client.updateMessage(chatRoomId, messageId, text) client.updateMessage(chatRoomId, messageId, text)
} }
clearUnfinishedMessage()
view.enableSendMessageButton() view.enableSendMessageButton()
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.d(ex, "Error sending message...") Timber.d(ex, "Error sending message...")
...@@ -1281,31 +1286,26 @@ class ChatRoomPresenter @Inject constructor( ...@@ -1281,31 +1286,26 @@ class ChatRoomPresenter @Inject constructor(
} }
/** /**
* Save unfinished message, when user left chat room without sending a message. It also clears * Save unfinished message, when user left chat room without sending a message.
* saved message from local repository when unfinishedMessage is blank.
* *
* @param chatRoomId Chat room Id.
* @param unfinishedMessage The unfinished message to save. * @param unfinishedMessage The unfinished message to save.
*/ */
fun saveUnfinishedMessage(chatRoomId: String, unfinishedMessage: String) { fun saveUnfinishedMessage(unfinishedMessage: String) {
val key = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$chatRoomId"
if (unfinishedMessage.isNotBlank()) { if (unfinishedMessage.isNotBlank()) {
localRepository.save(key, unfinishedMessage) localRepository.save(unfinishedMessageKey, unfinishedMessage)
} else {
localRepository.clear(key)
} }
} }
fun clearUnfinishedMessage() {
localRepository.clear(unfinishedMessageKey)
}
/** /**
* Get unfinished message from local repository, when user left chat room without * Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back. * sending a message and now the user is back.
* *
* @param chatRoomId Chat room Id. * @return Returns the unfinished message, null otherwise.
*
* @return Returns the unfinished message.
*/ */
fun getUnfinishedMessage(chatRoomId: String): String { fun getUnfinishedMessage(): String? {
val key = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$chatRoomId" return localRepository.get(unfinishedMessageKey)
return localRepository.get(key) ?: ""
} }
} }
...@@ -76,6 +76,7 @@ import chat.rocket.android.util.extensions.fadeOut ...@@ -76,6 +76,7 @@ import chat.rocket.android.util.extensions.fadeOut
import chat.rocket.android.util.extensions.getBitmpap import chat.rocket.android.util.extensions.getBitmpap
import chat.rocket.android.util.extensions.hideKeyboard import chat.rocket.android.util.extensions.hideKeyboard
import chat.rocket.android.util.extensions.inflate import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.isNotNullNorEmpty
import chat.rocket.android.util.extensions.rotateBy import chat.rocket.android.util.extensions.rotateBy
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
...@@ -242,6 +243,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -242,6 +243,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
presenter.setupChatRoom(chatRoomId, chatRoomName, chatRoomType, chatRoomMessage) presenter.setupChatRoom(chatRoomId, chatRoomName, chatRoomType, chatRoomMessage)
presenter.loadChatRooms() presenter.loadChatRooms()
getUnfinishedMessage()
setupRecyclerView() setupRecyclerView()
setupFab() setupFab()
setupSuggestionsView() setupSuggestionsView()
...@@ -264,9 +266,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -264,9 +266,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
recycler_view.removeOnScrollListener(onScrollListener) recycler_view.removeOnScrollListener(onScrollListener)
recycler_view.removeOnLayoutChangeListener(layoutChangeListener) recycler_view.removeOnLayoutChangeListener(layoutChangeListener)
presenter.disconnect() presenter.saveUnfinishedMessage(text_message.text.toString())
presenter.saveUnfinishedMessage(chatRoomId, text_message.text.toString())
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
presenter.disconnect()
unsubscribeComposeTextMessage() unsubscribeComposeTextMessage()
// Hides the keyboard (if it's opened) before going to any view. // Hides the keyboard (if it's opened) before going to any view.
...@@ -953,15 +955,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -953,15 +955,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
private fun getUnfinishedMessage() { private fun getUnfinishedMessage() {
val unfinishedMessage = presenter.getUnfinishedMessage(chatRoomId) val unfinishedMessage = presenter.getUnfinishedMessage()
if (unfinishedMessage.isNotBlank()) { if (unfinishedMessage.isNotNullNorEmpty()) {
text_message.setText(unfinishedMessage) text_message.setText(unfinishedMessage)
val orientation = resources.configuration.orientation
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
KeyboardHelper.showSoftKeyboard(text_message)
} else {
//TODO show keyboard in full screen mode when landscape orientation
}
} }
} }
......
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