Added support of left control + enter keys to send message
This commit is contained in:
parent
72ae8f2e67
commit
9d48a15bb6
3 changed files with 38 additions and 0 deletions
|
@ -21,6 +21,7 @@ Group changes to describe their impact on the project, as follows:
|
|||
- Ask Android to not process what user types in an encrypted chat room to improve privacy, see [IME_FLAG_NO_PERSONALIZED_LEARNING](https://developer.android.com/reference/android/view/inputmethod/EditorInfo#IME_FLAG_NO_PERSONALIZED_LEARNING)
|
||||
- New video call UI on foldable device like Galaxy Z Fold
|
||||
- Setting to automatically record all calls
|
||||
- When using a physical keyboard, use left control + enter keys to send message
|
||||
|
||||
### Changed
|
||||
- UI has been reworked around SlidingPane component to better handle tablets & foldable devices
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.linphone.activities.main.chat.adapters.ChatMessagesListAdapter
|
|||
import org.linphone.activities.main.chat.data.ChatMessageData
|
||||
import org.linphone.activities.main.chat.data.EventLogData
|
||||
import org.linphone.activities.main.chat.viewmodels.*
|
||||
import org.linphone.activities.main.chat.views.RichEditTextSendListener
|
||||
import org.linphone.activities.main.fragments.MasterFragment
|
||||
import org.linphone.activities.main.viewmodels.DialogViewModel
|
||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||
|
@ -511,6 +512,13 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
false
|
||||
}
|
||||
|
||||
binding.message.setControlEnterListener(object : RichEditTextSendListener {
|
||||
override fun onControlEnterPressedAndReleased() {
|
||||
Log.i("[Chat Room] Detected left control + enter key presses, sending message")
|
||||
chatSendingViewModel.sendMessage()
|
||||
}
|
||||
})
|
||||
|
||||
binding.setCancelReplyToClickListener {
|
||||
chatSendingViewModel.cancelReply()
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.linphone.activities.main.chat.views
|
|||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.KeyEvent
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
@ -35,6 +36,10 @@ import org.linphone.utils.Event
|
|||
* Allows for image input inside an EditText, usefull for keyboards with gif support for example.
|
||||
*/
|
||||
class RichEditText : AppCompatEditText {
|
||||
private var controlPressed = false
|
||||
|
||||
private var sendListener: RichEditTextSendListener? = null
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
initReceiveContentListener()
|
||||
}
|
||||
|
@ -51,6 +56,10 @@ class RichEditText : AppCompatEditText {
|
|||
initReceiveContentListener()
|
||||
}
|
||||
|
||||
fun setControlEnterListener(listener: RichEditTextSendListener) {
|
||||
sendListener = listener
|
||||
}
|
||||
|
||||
private fun initReceiveContentListener() {
|
||||
ViewCompat.setOnReceiveContentListener(
|
||||
this, RichContentReceiver.MIME_TYPES,
|
||||
|
@ -63,5 +72,25 @@ class RichEditText : AppCompatEditText {
|
|||
sharedViewModel.richContentUri.value = Event(uri)
|
||||
}
|
||||
)
|
||||
|
||||
setOnKeyListener { _, keyCode, event ->
|
||||
if (keyCode == KeyEvent.KEYCODE_CTRL_LEFT) {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
controlPressed = true
|
||||
} else if (event.action == KeyEvent.ACTION_UP) {
|
||||
controlPressed = false
|
||||
}
|
||||
false
|
||||
} else if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP && controlPressed) {
|
||||
sendListener?.onControlEnterPressedAndReleased()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface RichEditTextSendListener {
|
||||
fun onControlEnterPressedAndReleased()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue