Commit 68932d74 authored by pancor's avatar pancor

refactor code and add clear message possibility

parent f9ab2126
...@@ -362,15 +362,18 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -362,15 +362,18 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
} }
/** /**
* Save unfinished message, when user left chat room without sending a message. * Save unfinished message, when user left chat room without sending a message. It also clears
* saved message from local repository when unfinishedMessage is blank.
* *
* @param chatRoomId Chat room Id. * @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(chatRoomId: String, unfinishedMessage: String) {
if (unfinishedMessage.isNotBlank()) {
val key = LocalRepository.UNFINISHED_MSG_KEY + chatRoomId val key = LocalRepository.UNFINISHED_MSG_KEY + chatRoomId
if (unfinishedMessage.isNotBlank()) {
localRepository.save(key, unfinishedMessage) localRepository.save(key, unfinishedMessage)
} else {
localRepository.clear(key)
} }
} }
......
...@@ -5,6 +5,7 @@ import android.content.ClipData ...@@ -5,6 +5,7 @@ import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Configuration
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
...@@ -416,7 +417,12 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { ...@@ -416,7 +417,12 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
val unfinishedMessage = presenter.getUnfinishedMessage(chatRoomId) val unfinishedMessage = presenter.getUnfinishedMessage(chatRoomId)
if (unfinishedMessage.isNotBlank() && activity != null) { if (unfinishedMessage.isNotBlank() && activity != null) {
text_message.setText(unfinishedMessage) text_message.setText(unfinishedMessage)
val orientation = resources.configuration.orientation
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
KeyboardHelper.showSoftKeyboardOnActivityStart(activity!!, text_message) KeyboardHelper.showSoftKeyboardOnActivityStart(activity!!, text_message)
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
text_message.requestFocus()
}
} }
} }
......
...@@ -59,7 +59,7 @@ object KeyboardHelper { ...@@ -59,7 +59,7 @@ object KeyboardHelper {
*/ */
fun showSoftKeyboardOnActivityStart(activity: Activity, view: View) { fun showSoftKeyboardOnActivityStart(activity: Activity, view: View) {
if (view.requestFocus()) { if (view.requestFocus()) {
activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
} }
} }
} }
\ No newline at end of file
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