mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 03:39:00 +00:00
Fix emojis in chat. Fixes #975
This commit is contained in:
parent
42a851ee9c
commit
2ab544d03e
2 changed files with 76 additions and 7 deletions
|
|
@ -34,7 +34,7 @@
|
|||
app:hintEnabled="false"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"
|
||||
android:layout_marginTop="@dimen/spacing_medium">
|
||||
<android.support.v7.widget.AppCompatEditText
|
||||
<net.pherth.android.emoji_library.EmojiEditText
|
||||
android:id="@+id/chatEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -7,24 +7,29 @@ import android.support.v7.widget.AppCompatEditText
|
|||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.AttributeSet
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.*
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.ui.helpers.NavbarUtils
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import net.pherth.android.emoji_library.EmojiEditText
|
||||
import net.pherth.android.emoji_library.EmojiPopup
|
||||
import net.pherth.android.emoji_library.EmojiTextView
|
||||
|
||||
class ChatBarView : FrameLayout {
|
||||
|
||||
private val chatBarContainer: LinearLayout by bindView(R.id.chatBarContainer)
|
||||
private val sendButton: ImageButton by bindView(R.id.sendButton)
|
||||
private val chatEditText: AppCompatEditText by bindView(R.id.chatEditText)
|
||||
private val chatEditText: EmojiEditText by bindView(R.id.chatEditText)
|
||||
private val textIndicator: TextView by bindView(R.id.text_indicator)
|
||||
private val indicatorSpacing: View by bindView(R.id.indicator_spacing)
|
||||
|
||||
private val emojiButton: ImageButton by bindView(R.id.emojiButton)
|
||||
private val popup: EmojiPopup by lazy {
|
||||
EmojiPopup(emojiButton.rootView, context, ContextCompat.getColor(context, R.color.brand))
|
||||
}
|
||||
private var navBarAccountedHeightCalculated = false
|
||||
|
||||
internal var maxChatLength = 3000
|
||||
|
|
@ -57,6 +62,40 @@ class ChatBarView : FrameLayout {
|
|||
|
||||
sendButton.setOnClickListener { sendButtonPressed() }
|
||||
|
||||
emojiButton.setOnClickListener(EmojiClickListener(chatEditText))
|
||||
|
||||
popup.setSizeForSoftKeyboard()
|
||||
popup.setOnDismissListener { changeEmojiKeyboardIcon(false) }
|
||||
popup.setOnSoftKeyboardOpenCloseListener(object : EmojiPopup.OnSoftKeyboardOpenCloseListener {
|
||||
|
||||
override fun onKeyboardOpen(keyBoardHeight: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onKeyboardClose() {
|
||||
if (popup.isShowing) {
|
||||
popup.dismiss()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
popup.setOnEmojiconClickedListener { emojicon ->
|
||||
val start = chatEditText.selectionStart
|
||||
val end = chatEditText.selectionEnd
|
||||
if (start < 0) {
|
||||
chatEditText.append(emojicon.emoji)
|
||||
} else {
|
||||
chatEditText.text?.replace(Math.min(start, end),
|
||||
Math.max(start, end), emojicon.emoji, 0,
|
||||
emojicon.emoji.length)
|
||||
}
|
||||
}
|
||||
|
||||
popup.setOnEmojiconBackspaceClickedListener {
|
||||
val event = KeyEvent(
|
||||
0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL)
|
||||
chatEditText.dispatchKeyEvent(event)
|
||||
}
|
||||
resizeForDrawingUnderNavbar()
|
||||
}
|
||||
|
||||
|
|
@ -118,4 +157,34 @@ class ChatBarView : FrameLayout {
|
|||
sendAction?.invoke(chatText)
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeEmojiKeyboardIcon(keyboardOpened: Boolean) {
|
||||
if (keyboardOpened) {
|
||||
emojiButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_keyboard_grey600_24dp))
|
||||
} else {
|
||||
emojiButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_emoticon_grey600_24dp))
|
||||
}
|
||||
}
|
||||
|
||||
private inner class EmojiClickListener internal constructor(internal var view: EmojiEditText) : View.OnClickListener {
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (!popup.isShowing) {
|
||||
if (popup.isKeyBoardOpen == true) {
|
||||
popup.showAtBottom()
|
||||
changeEmojiKeyboardIcon(true)
|
||||
} else {
|
||||
view.isFocusableInTouchMode = true
|
||||
view.requestFocus()
|
||||
popup.showAtBottomPending()
|
||||
val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
inputMethodManager?.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
changeEmojiKeyboardIcon(true)
|
||||
}
|
||||
} else {
|
||||
popup.dismiss()
|
||||
changeEmojiKeyboardIcon(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue