Commit 7db7a3ae authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix closing keyboard behavior and rename few methods

parent b6b8ada6
...@@ -4,7 +4,6 @@ import android.content.Context ...@@ -4,7 +4,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.helper.KeyboardHelper import chat.rocket.android.helper.KeyboardHelper
import chat.rocket.android.util.extensions.addFragment import chat.rocket.android.util.extensions.addFragment
...@@ -68,13 +67,13 @@ class ChatRoomActivity : SwipeBackActivity(), HasSupportFragmentInjector { ...@@ -68,13 +67,13 @@ class ChatRoomActivity : SwipeBackActivity(), HasSupportFragmentInjector {
} }
override fun onBackPressed() { override fun onBackPressed() {
super.onBackPressed()
val frag = supportFragmentManager.findFragmentByTag(EmojiFragment.TAG) as EmojiFragment? val frag = supportFragmentManager.findFragmentByTag(EmojiFragment.TAG) as EmojiFragment?
if (frag != null && frag.isShown()) { if (frag != null && frag.isExpanded()) {
frag.hide() frag.collapse()
} else { } else {
KeyboardHelper.hideSoftKeyboard(this) KeyboardHelper.hideSoftKeyboard(this)
finishActivity() finishActivity()
super.onBackPressed()
} }
} }
......
...@@ -261,7 +261,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -261,7 +261,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
} }
} }
override fun onKeyPressed(keyCode: Int) { override fun onNonEmojiKeyPressed(keyCode: Int) {
when (keyCode) { when (keyCode) {
KeyEvent.KEYCODE_BACK -> with(text_message) { KeyEvent.KEYCODE_BACK -> with(text_message) {
if (selectionStart > 0) text.delete(selectionStart - 1, selectionStart) if (selectionStart > 0) text.delete(selectionStart - 1, selectionStart)
...@@ -270,6 +270,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -270,6 +270,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
} }
} }
override fun onEmojiPanelCollapsed() {
setReactionButtonIcon(R.drawable.ic_reaction_24dp)
}
override fun onEmojiPanelExpanded() {
}
private fun setReactionButtonIcon(@DrawableRes drawableId: Int) { private fun setReactionButtonIcon(@DrawableRes drawableId: Int) {
button_add_reaction.setImageResource(drawableId) button_add_reaction.setImageResource(drawableId)
button_add_reaction.setTag(drawableId) button_add_reaction.setTag(drawableId)
...@@ -278,7 +286,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -278,7 +286,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
private fun hideAllKeyboards() { private fun hideAllKeyboards() {
activity?.let { activity?.let {
KeyboardHelper.hideSoftKeyboard(it) KeyboardHelper.hideSoftKeyboard(it)
attachOrGetEmojiFragment()?.hide() attachOrGetEmojiFragment()?.collapse()
setReactionButtonIcon(R.drawable.ic_reaction_24dp) setReactionButtonIcon(R.drawable.ic_reaction_24dp)
} }
} }
...@@ -328,7 +336,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -328,7 +336,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
activity?.let { activity?.let {
val fragment = EmojiFragment.getOrAttach(it, R.id.emoji_fragment_placeholder, composer) val fragment = EmojiFragment.getOrAttach(it, R.id.emoji_fragment_placeholder, composer)
if (fragment.isCollapsed()) { if (fragment.isCollapsed()) {
fragment.openHidden() fragment.expandHidden()
} }
setReactionButtonIcon(R.drawable.ic_reaction_24dp) setReactionButtonIcon(R.drawable.ic_reaction_24dp)
} }
...@@ -353,7 +361,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -353,7 +361,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
sendMessage(textMessage) sendMessage(textMessage)
attachOrGetEmojiFragment()?.let { attachOrGetEmojiFragment()?.let {
if (it.softKeyboardVisible) { if (it.softKeyboardVisible) {
it.hide() it.collapse()
} }
} }
clearMessageComposition() clearMessageComposition()
...@@ -390,7 +398,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -390,7 +398,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
when (tag) { when (tag) {
R.drawable.ic_reaction_24dp -> { R.drawable.ic_reaction_24dp -> {
KeyboardHelper.hideSoftKeyboard(it) KeyboardHelper.hideSoftKeyboard(it)
if (!emojiFragment.isShown()) { if (!emojiFragment.isExpanded()) {
emojiFragment.show() emojiFragment.show()
} }
setReactionButtonIcon(R.drawable.ic_keyboard_black_24dp) setReactionButtonIcon(R.drawable.ic_keyboard_black_24dp)
...@@ -402,6 +410,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi ...@@ -402,6 +410,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiFragment.EmojiKeyboardLi
} }
} }
} }
text_message.requestFocus()
} }
} }
......
...@@ -13,7 +13,6 @@ import android.view.* ...@@ -13,7 +13,6 @@ import android.view.*
import android.widget.EditText import android.widget.EditText
import android.widget.ImageView import android.widget.ImageView
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.util.extensions.setVisible
class EmojiFragment : Fragment() { class EmojiFragment : Fragment() {
...@@ -98,6 +97,9 @@ class EmojiFragment : Fragment() { ...@@ -98,6 +97,9 @@ class EmojiFragment : Fragment() {
EmojiRepository.saveKeyboardHeight(currentKeyboardHeight) EmojiRepository.saveKeyboardHeight(currentKeyboardHeight)
setKeyboardHeight(currentKeyboardHeight) setKeyboardHeight(currentKeyboardHeight)
softKeyboardVisible = true softKeyboardVisible = true
parentContainer.postDelayed({
expandHidden()
}, 100)
} else if (lastVisibleDecorViewHeight + MIN_KEYBOARD_HEIGHT_PX < visibleDecorViewHeight) { } else if (lastVisibleDecorViewHeight + MIN_KEYBOARD_HEIGHT_PX < visibleDecorViewHeight) {
// Notify listener about keyboard being hidden. // Notify listener about keyboard being hidden.
softKeyboardVisible = false softKeyboardVisible = false
...@@ -122,7 +124,7 @@ class EmojiFragment : Fragment() { ...@@ -122,7 +124,7 @@ class EmojiFragment : Fragment() {
} }
backspaceView.setOnClickListener { backspaceView.setOnClickListener {
listener?.onKeyPressed(KeyEvent.KEYCODE_BACK) listener?.onNonEmojiKeyPressed(KeyEvent.KEYCODE_BACK)
} }
} }
...@@ -139,7 +141,15 @@ class EmojiFragment : Fragment() { ...@@ -139,7 +141,15 @@ class EmojiFragment : Fragment() {
} }
} }
viewPager.adapter = CategoryPagerAdapter(object : EmojiKeyboardListener { viewPager.adapter = CategoryPagerAdapter(object : EmojiKeyboardListener {
override fun onKeyPressed(keyCode: Int) { override fun onEmojiPanelExpanded() {
// do nothing
}
override fun onEmojiPanelCollapsed() {
// do nothing
}
override fun onNonEmojiKeyPressed(keyCode: Int) {
// do nothing // do nothing
} }
...@@ -215,25 +225,35 @@ class EmojiFragment : Fragment() { ...@@ -215,25 +225,35 @@ class EmojiFragment : Fragment() {
} }
} }
private fun setKeyboardVisibility(visibility: Int) {
if (visibility != parentContainer.visibility) {
parentContainer.visibility = visibility
}
}
/** /**
* Show the emoji keyboard. * Show the emoji keyboard.
*/ */
fun show() { fun show() {
parentContainer.setVisible(true) setKeyboardVisibility(View.VISIBLE)
} }
fun openHidden() { /**
parentContainer.visibility = View.INVISIBLE * Expand the emoji keyboard with invisible contents.
*/
fun expandHidden() {
setKeyboardVisibility(View.INVISIBLE)
} }
/** /**
* Hide the emoji keyboard. * Hide the emoji keyboard.
*/ */
fun hide() { fun collapse() {
// Since the emoji keyboard is always behind the soft keyboard assume it's also dismissed // Since the emoji keyboard is always behind the soft keyboard assume it's also dismissed
// when the emoji one is about to get close. Hence we should invoke our listener to update // when the emoji one is about to get close. Hence we should invoke our listener to update
// the UI as if the soft keyboard is hidden. // the UI as if the soft keyboard is hidden.
parentContainer.setVisible(false) listener?.onEmojiPanelCollapsed()
setKeyboardVisibility(View.GONE)
} }
/** /**
...@@ -241,7 +261,7 @@ class EmojiFragment : Fragment() { ...@@ -241,7 +261,7 @@ class EmojiFragment : Fragment() {
* *
* @return <code>true</code> if opened. * @return <code>true</code> if opened.
*/ */
fun isShown() = parentContainer.visibility == View.VISIBLE fun isExpanded() = parentContainer.visibility == View.VISIBLE
/** /**
* Whether the emoji keyboard is collapsed. * Whether the emoji keyboard is collapsed.
...@@ -265,6 +285,10 @@ class EmojiFragment : Fragment() { ...@@ -265,6 +285,10 @@ class EmojiFragment : Fragment() {
* *
* @see android.view.KeyEvent * @see android.view.KeyEvent
*/ */
fun onKeyPressed(keyCode: Int) fun onNonEmojiKeyPressed(keyCode: Int)
fun onEmojiPanelCollapsed()
fun onEmojiPanelExpanded()
} }
} }
\ 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