mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
commit
6c335c7df1
5 changed files with 45 additions and 21 deletions
|
@ -10,6 +10,7 @@ Improvements 🙌:
|
||||||
- PIN code: request PIN code if phone has been locked
|
- PIN code: request PIN code if phone has been locked
|
||||||
- Small optimisation of scrolling experience in timeline (#2114)
|
- Small optimisation of scrolling experience in timeline (#2114)
|
||||||
- Allow user to reset cross signing if he has no way to recover (#2052)
|
- Allow user to reset cross signing if he has no way to recover (#2052)
|
||||||
|
- Ability to share text
|
||||||
- Create home shortcut for any room (#1525)
|
- Create home shortcut for any room (#1525)
|
||||||
- Can't confirm email due to killing by Android (#2021)
|
- Can't confirm email due to killing by Android (#2021)
|
||||||
- Add a menu item to open the setting in room list and in room (#2171)
|
- Add a menu item to open the setting in room list and in room (#2171)
|
||||||
|
|
|
@ -300,11 +300,24 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) {
|
||||||
sendIntent.type = mediaMimeType
|
sendIntent.type = mediaMimeType
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, mediaUri)
|
sendIntent.putExtra(Intent.EXTRA_STREAM, mediaUri)
|
||||||
|
|
||||||
try {
|
sendShareIntent(context, sendIntent)
|
||||||
context.startActivity(sendIntent)
|
}
|
||||||
} catch (activityNotFoundException: ActivityNotFoundException) {
|
}
|
||||||
context.toast(R.string.error_no_external_application_found)
|
|
||||||
}
|
fun shareText(context: Context, text: String) {
|
||||||
|
val sendIntent = Intent()
|
||||||
|
sendIntent.action = Intent.ACTION_SEND
|
||||||
|
sendIntent.type = "text/plain"
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_TEXT, text)
|
||||||
|
|
||||||
|
sendShareIntent(context, sendIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendShareIntent(context: Context, intent: Intent) {
|
||||||
|
try {
|
||||||
|
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share)))
|
||||||
|
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||||
|
context.toast(R.string.error_no_external_application_found)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ import im.vector.app.core.utils.openUrlInExternalBrowser
|
||||||
import im.vector.app.core.utils.registerForPermissionsResult
|
import im.vector.app.core.utils.registerForPermissionsResult
|
||||||
import im.vector.app.core.utils.saveMedia
|
import im.vector.app.core.utils.saveMedia
|
||||||
import im.vector.app.core.utils.shareMedia
|
import im.vector.app.core.utils.shareMedia
|
||||||
|
import im.vector.app.core.utils.shareText
|
||||||
import im.vector.app.core.utils.toast
|
import im.vector.app.core.utils.toast
|
||||||
import im.vector.app.features.attachments.AttachmentTypeSelectorView
|
import im.vector.app.features.attachments.AttachmentTypeSelectorView
|
||||||
import im.vector.app.features.attachments.AttachmentsHelper
|
import im.vector.app.features.attachments.AttachmentsHelper
|
||||||
|
@ -1587,21 +1588,25 @@ class RoomDetailFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
||||||
session.fileService().downloadFile(
|
if (action.messageContent is MessageTextContent) {
|
||||||
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
|
shareText(requireContext(), action.messageContent.body)
|
||||||
id = action.eventId,
|
} else if (action.messageContent is MessageWithAttachmentContent) {
|
||||||
fileName = action.messageContent.body,
|
session.fileService().downloadFile(
|
||||||
mimeType = action.messageContent.mimeType,
|
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
|
||||||
url = action.messageContent.getFileUrl(),
|
id = action.eventId,
|
||||||
elementToDecrypt = action.messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
fileName = action.messageContent.body,
|
||||||
callback = object : MatrixCallback<File> {
|
mimeType = action.messageContent.mimeType,
|
||||||
override fun onSuccess(data: File) {
|
url = action.messageContent.getFileUrl(),
|
||||||
if (isAdded) {
|
elementToDecrypt = action.messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
||||||
shareMedia(requireContext(), data, getMimeTypeFromUri(requireContext(), data.toUri()))
|
callback = object : MatrixCallback<File> {
|
||||||
|
override fun onSuccess(data: File) {
|
||||||
|
if (isAdded) {
|
||||||
|
shareMedia(requireContext(), data, getMimeTypeFromUri(requireContext(), data.toUri()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val saveActionActivityResultLauncher = registerForPermissionsResult { allGranted ->
|
private val saveActionActivityResultLauncher = registerForPermissionsResult { allGranted ->
|
||||||
|
|
|
@ -21,6 +21,7 @@ import androidx.annotation.StringRes
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.platform.VectorSharedAction
|
import im.vector.app.core.platform.VectorSharedAction
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent
|
import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent
|
||||||
|
|
||||||
sealed class EventSharedAction(@StringRes val titleRes: Int,
|
sealed class EventSharedAction(@StringRes val titleRes: Int,
|
||||||
|
@ -47,7 +48,7 @@ sealed class EventSharedAction(@StringRes val titleRes: Int,
|
||||||
data class Reply(val eventId: String) :
|
data class Reply(val eventId: String) :
|
||||||
EventSharedAction(R.string.reply, R.drawable.ic_reply)
|
EventSharedAction(R.string.reply, R.drawable.ic_reply)
|
||||||
|
|
||||||
data class Share(val eventId: String, val messageContent: MessageWithAttachmentContent) :
|
data class Share(val eventId: String, val messageContent: MessageContent) :
|
||||||
EventSharedAction(R.string.share, R.drawable.ic_share)
|
EventSharedAction(R.string.share, R.drawable.ic_share)
|
||||||
|
|
||||||
data class Save(val eventId: String, val messageContent: MessageWithAttachmentContent) :
|
data class Save(val eventId: String, val messageContent: MessageWithAttachmentContent) :
|
||||||
|
|
|
@ -275,8 +275,8 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
add(EventSharedAction.ViewEditHistory(informationData))
|
add(EventSharedAction.ViewEditHistory(informationData))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canShare(msgType) && messageContent is MessageWithAttachmentContent) {
|
if (canShare(msgType)) {
|
||||||
add(EventSharedAction.Share(timelineEvent.eventId, messageContent))
|
add(EventSharedAction.Share(timelineEvent.eventId, messageContent!!))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canSave(msgType) && messageContent is MessageWithAttachmentContent) {
|
if (canSave(msgType) && messageContent is MessageWithAttachmentContent) {
|
||||||
|
@ -409,6 +409,10 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
|
|
||||||
private fun canShare(msgType: String?): Boolean {
|
private fun canShare(msgType: String?): Boolean {
|
||||||
return when (msgType) {
|
return when (msgType) {
|
||||||
|
MessageType.MSGTYPE_TEXT,
|
||||||
|
MessageType.MSGTYPE_NOTICE,
|
||||||
|
MessageType.MSGTYPE_EMOTE,
|
||||||
|
MessageType.MSGTYPE_LOCATION,
|
||||||
MessageType.MSGTYPE_IMAGE,
|
MessageType.MSGTYPE_IMAGE,
|
||||||
MessageType.MSGTYPE_AUDIO,
|
MessageType.MSGTYPE_AUDIO,
|
||||||
MessageType.MSGTYPE_VIDEO,
|
MessageType.MSGTYPE_VIDEO,
|
||||||
|
|
Loading…
Reference in a new issue