Merge pull request #3554 from nextcloud/feature/share_message_text_to_other_apps

Share message text to other apps
This commit is contained in:
Marcel Hibbe 2024-01-04 11:19:44 +01:00 committed by GitHub
commit fc00f1dcad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
}