Commit f9ab2126 authored by pancor's avatar pancor

add show soft keyboard at activity start functionality

parent 7f80a50b
...@@ -115,6 +115,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { ...@@ -115,6 +115,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
} }
override fun onDestroyView() { override fun onDestroyView() {
presenter.saveUnfinishedMessage(chatRoomId, text_message.text.toString())
presenter.unsubscribeMessages(chatRoomId) presenter.unsubscribeMessages(chatRoomId)
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
unsubscribeTextMessage() unsubscribeTextMessage()
...@@ -350,6 +351,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { ...@@ -350,6 +351,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
button_show_attachment_options.alpha = 1f button_show_attachment_options.alpha = 1f
button_show_attachment_options.setVisible(true) button_show_attachment_options.setVisible(true)
getUnfinishedMessage()
subscribeTextMessage() subscribeTextMessage()
emojiKeyboardPopup = EmojiKeyboardPopup(activity!!, activity!!.findViewById(R.id.fragment_container)) emojiKeyboardPopup = EmojiKeyboardPopup(activity!!, activity!!.findViewById(R.id.fragment_container))
emojiKeyboardPopup.listener = this emojiKeyboardPopup.listener = this
...@@ -410,6 +412,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { ...@@ -410,6 +412,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
} }
} }
private fun getUnfinishedMessage() {
val unfinishedMessage = presenter.getUnfinishedMessage(chatRoomId)
if (unfinishedMessage.isNotBlank() && activity != null) {
text_message.setText(unfinishedMessage)
KeyboardHelper.showSoftKeyboardOnActivityStart(activity!!, text_message)
}
}
private fun openEmojiKeyboardPopup() { private fun openEmojiKeyboardPopup() {
if (!emojiKeyboardPopup.isShowing()) { if (!emojiKeyboardPopup.isShowing()) {
// If keyboard is visible, simply show the popup // If keyboard is visible, simply show the popup
......
...@@ -4,6 +4,7 @@ import android.app.Activity ...@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.graphics.Rect import android.graphics.Rect
import android.view.View import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
...@@ -50,4 +51,15 @@ object KeyboardHelper { ...@@ -50,4 +51,15 @@ object KeyboardHelper {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.SHOW_IMPLICIT) inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.SHOW_IMPLICIT)
} }
} }
/**
* Show the soft keyboard for the given view at the start of activity or fragment.
*
* @param view View to receive input focus.
*/
fun showSoftKeyboardOnActivityStart(activity: Activity, view: View) {
if (view.requestFocus()) {
activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_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