mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-26 23:25:20 +03:00
Image keyboard support in chat
Receive images (usually GIFs) from keyboard and upload them to the current chat. Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
parent
7a15f7ca78
commit
385edf35a2
3 changed files with 83 additions and 1 deletions
|
@ -148,6 +148,7 @@ import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
|
|||
import com.nextcloud.talk.utils.ContactUtils
|
||||
import com.nextcloud.talk.utils.DateUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.ImageEmojiEditText
|
||||
import com.nextcloud.talk.utils.KeyboardUtils
|
||||
import com.nextcloud.talk.utils.MagicCharPolicy
|
||||
import com.nextcloud.talk.utils.NotificationUtils
|
||||
|
@ -668,6 +669,12 @@ class ChatController(args: Bundle) :
|
|||
}
|
||||
})
|
||||
|
||||
// Image keyboard support
|
||||
// See: https://developer.android.com/guide/topics/text/image-keyboard
|
||||
(binding.messageInputView.inputEditText as ImageEmojiEditText).onCommitContentListener = {
|
||||
uploadFiles(mutableListOf(it.toString()), false)
|
||||
}
|
||||
|
||||
showMicrophoneButton(true)
|
||||
|
||||
binding.messageInputView.messageInput.doAfterTextChanged {
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Dariusz Olszewski
|
||||
* Copyright (C) 2021 Dariusz Olszewski <starypatyk@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputConnection
|
||||
import androidx.core.view.inputmethod.EditorInfoCompat
|
||||
import androidx.core.view.inputmethod.InputConnectionCompat
|
||||
import androidx.emoji.widget.EmojiEditText
|
||||
|
||||
/*
|
||||
Subclass of EmojiEditText with support for image keyboards - primarily for GIF handling. ;-)
|
||||
Implementation based on this example:
|
||||
https://developer.android.com/guide/topics/text/image-keyboard
|
||||
*/
|
||||
class ImageEmojiEditText : EmojiEditText {
|
||||
|
||||
// Callback function to be called when the user selects an image, pass image Uri
|
||||
lateinit var onCommitContentListener: ((Uri) -> Unit)
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
override fun onCreateInputConnection(editorInfo: EditorInfo): InputConnection {
|
||||
|
||||
val ic: InputConnection = super.onCreateInputConnection(editorInfo)
|
||||
|
||||
EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/gif", "image/jpeg", "image/png"))
|
||||
|
||||
val callback =
|
||||
InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, _ ->
|
||||
|
||||
val lacksPermission = (flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && lacksPermission) {
|
||||
try {
|
||||
inputContentInfo.requestPermission()
|
||||
} catch (e: Exception) {
|
||||
return@OnCommitContentListener false
|
||||
}
|
||||
}
|
||||
|
||||
if (::onCommitContentListener.isInitialized) {
|
||||
onCommitContentListener.invoke(inputContentInfo.contentUri)
|
||||
return@OnCommitContentListener true
|
||||
} else {
|
||||
return@OnCommitContentListener false
|
||||
}
|
||||
}
|
||||
|
||||
return InputConnectionCompat.createWrapper(ic, editorInfo, callback)
|
||||
}
|
||||
|
||||
}
|
|
@ -65,7 +65,7 @@
|
|||
app:tint="?attr/colorControlNormal"
|
||||
android:contentDescription="@string/nc_add_emojis" />
|
||||
|
||||
<androidx.emoji.widget.EmojiEditText
|
||||
<com.nextcloud.talk.utils.ImageEmojiEditText
|
||||
android:id="@id/messageInput"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in a new issue