mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Add preference to send with enter + keyboard support
This commit is contained in:
parent
2963828a07
commit
0399677a01
2 changed files with 47 additions and 17 deletions
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue