Merge pull request #2303 from vector-im/feature/bca/enter_to_send

Add preference to send with enter + support hardware keyboard send
This commit is contained in:
Valere 2020-10-27 16:19:00 +01:00 committed by GitHub
commit 50fcf0731b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 17 deletions

View File

@ -7,6 +7,8 @@ Features ✨:
Improvements 🙌:
- Rework sending Event management (#154)
- New room creation screen: set topic and avatar in the room creation form (#2078)
- Add option to send with enter (#1195)
- Use Hardware keyboard enter to send message (use shift-enter for new line) (#1881, #1440)
Bugfix 🐛:
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)

View File

@ -20,6 +20,7 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Typeface
import android.net.Uri
import android.os.Build
@ -27,11 +28,13 @@ import android.os.Bundle
import android.os.Parcelable
import android.text.Spannable
import android.view.HapticFeedbackConstants
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
@ -1058,10 +1061,33 @@ class RoomDetailFragment @Inject constructor(
}
private fun setupComposer() {
autoCompleter.setup(composerLayout.composerEditText)
val composerEditText = composerLayout.composerEditText
autoCompleter.setup(composerEditText)
observerUserTyping()
if (vectorPreferences.sendMessageWithEnter()) {
// imeOptions="actionSend" only works with single line, so we remove multiline inputType
composerEditText.inputType = composerEditText.inputType and EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE.inv()
composerEditText.imeOptions = EditorInfo.IME_ACTION_SEND
}
composerEditText.setOnEditorActionListener { v, actionId, keyEvent ->
val imeActionId = actionId and EditorInfo.IME_MASK_ACTION
if (EditorInfo.IME_ACTION_DONE == imeActionId || EditorInfo.IME_ACTION_SEND == imeActionId) {
sendTextMessage(v.text)
true
}
// Add external keyboard functionality (to send messages)
else if (null != keyEvent
&& !keyEvent.isShiftPressed
&& keyEvent.keyCode == KeyEvent.KEYCODE_ENTER
&& resources.configuration.keyboard != Configuration.KEYBOARD_NOKEYS) {
sendTextMessage(v.text)
true
} else false
}
composerLayout.callback = object : TextComposerView.Callback {
override fun onAddAttachment() {
if (!::attachmentTypeSelector.isInitialized) {
@ -1071,16 +1097,7 @@ class RoomDetailFragment @Inject constructor(
}
override fun onSendMessage(text: CharSequence) {
if (lockSendButton) {
Timber.w("Send button is locked")
return
}
if (text.isNotBlank()) {
// We collapse ASAP, if not there will be a slight anoying delay
composerLayout.collapse(true)
lockSendButton = true
roomDetailViewModel.handle(RoomDetailAction.SendMessage(text, vectorPreferences.isMarkdownEnabled()))
}
sendTextMessage(text)
}
override fun onCloseRelatedMessage() {
@ -1100,6 +1117,19 @@ class RoomDetailFragment @Inject constructor(
}
}
private fun sendTextMessage(text: CharSequence) {
if (lockSendButton) {
Timber.w("Send button is locked")
return
}
if (text.isNotBlank()) {
// We collapse ASAP, if not there will be a slight anoying delay
composerLayout.collapse(true)
lockSendButton = true
roomDetailViewModel.handle(RoomDetailAction.SendMessage(text, vectorPreferences.isMarkdownEnabled()))
}
}
private fun observerUserTyping() {
composerLayout.composerEditText.textChanges()
.skipInitialValue()

View File

@ -43,6 +43,12 @@
android:summary="@string/settings_send_typing_notifs_summary"
android:title="@string/settings_send_typing_notifs" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_SEND_MESSAGE_WITH_ENTER"
android:summary="@string/settings_send_message_with_enter_summary"
android:title="@string/settings_send_message_with_enter" />
</im.vector.app.core.preference.VectorPreferenceCategory>
<im.vector.app.core.preference.VectorPreferenceCategory android:title="@string/settings_category_timeline">
@ -100,12 +106,6 @@
android:title="@string/settings_vibrate_on_mention"
app:isPreferenceVisible="@bool/false_not_implemented" />
<im.vector.app.core.preference.VectorSwitchPreference
android:key="SETTINGS_SEND_MESSAGE_WITH_ENTER"
android:summary="@string/settings_send_message_with_enter_summary"
android:title="@string/settings_send_message_with_enter"
app:isPreferenceVisible="@bool/false_not_implemented" />
<im.vector.app.core.preference.VectorListPreference
android:defaultValue="always"
android:entries="@array/show_info_area_entries"