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 {
}
override fun onDestroyView() {
presenter.saveUnfinishedMessage(chatRoomId, text_message.text.toString())
presenter.unsubscribeMessages(chatRoomId)
handler.removeCallbacksAndMessages(null)
unsubscribeTextMessage()
......@@ -350,6 +351,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
button_show_attachment_options.alpha = 1f
button_show_attachment_options.setVisible(true)
getUnfinishedMessage()
subscribeTextMessage()
emojiKeyboardPopup = EmojiKeyboardPopup(activity!!, activity!!.findViewById(R.id.fragment_container))
emojiKeyboardPopup.listener = this
......@@ -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() {
if (!emojiKeyboardPopup.isShowing()) {
// If keyboard is visible, simply show the popup
......
......@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import android.graphics.Rect
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
......@@ -50,4 +51,15 @@ object KeyboardHelper {
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