Share message text to other apps

Signed-off-by: Sowjanya Kota <sowjanya.kch@gmail.com>
This commit is contained in:
Sowjanya Kota 2024-01-02 14:50:36 +01:00 committed by Marcel Hibbe
parent df9d30475b
commit ffda98632e
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 27 additions and 2 deletions

View File

@ -347,6 +347,7 @@ class ChatActivity :
private var isVoicePreviewPlaying: Boolean = false
private var recorder: MediaRecorder? = null
private enum class MediaRecorderState {
INITIAL,
INITIALIZED,
@ -356,6 +357,7 @@ class ChatActivity :
RELEASED,
ERROR
}
private var mediaRecorderState: MediaRecorderState = MediaRecorderState.INITIAL
private var voicePreviewMediaPlayer: MediaPlayer? = null
@ -4518,6 +4520,16 @@ class ChatActivity :
Log.d(TAG, " |-----------------------------------------------")
}
fun shareMessageText(message: String) {
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, message)
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, getString(R.string.share))
startActivity(shareIntent)
}
companion object {
private val TAG = ChatActivity::class.simpleName
private const val CONTENT_TYPE_CALL_STARTED: Byte = 1

View File

@ -79,6 +79,12 @@ class MessageActionsDialog(
private lateinit var popup: EmojiPopup
private val messageHasFileAttachment =
ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == message.getCalculateMessageType()
private val messageHasRegularText = ChatMessage.MessageType.REGULAR_TEXT_MESSAGE == message
.getCalculateMessageType() && !message.isDeleted
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication?.componentApplication?.inject(this)
@ -112,7 +118,7 @@ class MessageActionsDialog(
message.previousMessageId > NO_PREVIOUS_MESSAGE_ID &&
ChatMessage.MessageType.SYSTEM_MESSAGE != message.getCalculateMessageType()
)
initMenuShare(ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == message.getCalculateMessageType())
initMenuShare(messageHasFileAttachment || messageHasRegularText)
initMenuItemOpenNcApp(
ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == message.getCalculateMessageType()
)
@ -330,13 +336,20 @@ class MessageActionsDialog(
dialogMessageActionsBinding.menuTranslateMessage.visibility = getVisibility(visible)
}
private fun initMenuShare(visible: Boolean) {
if (visible) {
if (messageHasFileAttachment) {
dialogMessageActionsBinding.menuShare.setOnClickListener {
chatActivity.checkIfSharable(message)
dismiss()
}
}
if (messageHasRegularText) {
dialogMessageActionsBinding.menuShare.setOnClickListener {
message.message?.let { messageText -> chatActivity.shareMessageText(messageText) }
dismiss()
}
}
dialogMessageActionsBinding.menuShare.visibility = getVisibility(visible)
}