mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 10:55:55 +03:00
Support sharing other media types.
This commit is contained in:
parent
7158554ee2
commit
26d387cc12
5 changed files with 33 additions and 32 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.internal.session
|
package im.vector.matrix.android.internal.session
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import arrow.core.Try
|
import arrow.core.Try
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
|
@ -25,7 +26,6 @@ import im.vector.matrix.android.api.util.Cancelable
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
|
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
|
||||||
import im.vector.matrix.android.internal.di.SessionCacheDirectory
|
import im.vector.matrix.android.internal.di.SessionCacheDirectory
|
||||||
import im.vector.matrix.android.internal.di.SessionFilesDirectory
|
|
||||||
import im.vector.matrix.android.internal.di.Unauthenticated
|
import im.vector.matrix.android.internal.di.Unauthenticated
|
||||||
import im.vector.matrix.android.internal.extensions.foldToCallback
|
import im.vector.matrix.android.internal.extensions.foldToCallback
|
||||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||||
|
@ -42,10 +42,9 @@ import java.io.IOException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class DefaultFileService @Inject constructor(
|
internal class DefaultFileService @Inject constructor(
|
||||||
|
private val context: Context,
|
||||||
@SessionCacheDirectory
|
@SessionCacheDirectory
|
||||||
private val cacheDirectory: File,
|
private val cacheDirectory: File,
|
||||||
@SessionFilesDirectory
|
|
||||||
private val filesDirectory: File,
|
|
||||||
private val contentUrlResolver: ContentUrlResolver,
|
private val contentUrlResolver: ContentUrlResolver,
|
||||||
@Unauthenticated
|
@Unauthenticated
|
||||||
private val okHttpClient: OkHttpClient,
|
private val okHttpClient: OkHttpClient,
|
||||||
|
@ -71,7 +70,7 @@ internal class DefaultFileService @Inject constructor(
|
||||||
File(folder, fileName)
|
File(folder, fileName)
|
||||||
}.flatMap { destFile ->
|
}.flatMap { destFile ->
|
||||||
if (!destFile.exists()) {
|
if (!destFile.exists()) {
|
||||||
val resolvedUrl = contentUrlResolver.resolveFullSize(url) ?: throw IllegalArgumentException("url is null")
|
val resolvedUrl = contentUrlResolver.resolveFullSize(url) ?: return@flatMap Try.Failure(IllegalArgumentException("url is null"))
|
||||||
|
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url(resolvedUrl)
|
.url(resolvedUrl)
|
||||||
|
@ -102,9 +101,9 @@ internal class DefaultFileService @Inject constructor(
|
||||||
|
|
||||||
private fun copyFile(file: File, downloadMode: FileService.DownloadMode): File {
|
private fun copyFile(file: File, downloadMode: FileService.DownloadMode): File {
|
||||||
return when (downloadMode) {
|
return when (downloadMode) {
|
||||||
FileService.DownloadMode.TO_EXPORT -> file.copyTo(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), true)
|
FileService.DownloadMode.TO_EXPORT -> file.copyTo(File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), file.name), true)
|
||||||
FileService.DownloadMode.FOR_INTERNAL_USE -> file.copyTo(File(filesDirectory, "ext_share"), true)
|
FileService.DownloadMode.FOR_EXTERNAL_SHARE -> file.copyTo(File(File(context.cacheDir, "ext_share"), file.name), true)
|
||||||
FileService.DownloadMode.FOR_EXTERNAL_SHARE -> file
|
FileService.DownloadMode.FOR_INTERNAL_USE -> file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.app.ActivityOptionsCompat
|
import androidx.core.app.ActivityOptionsCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.core.text.buildSpannedString
|
import androidx.core.text.buildSpannedString
|
||||||
import androidx.core.util.Pair
|
import androidx.core.util.Pair
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
|
@ -95,6 +96,7 @@ import im.vector.riotx.core.extensions.setTextOrHide
|
||||||
import im.vector.riotx.core.extensions.showKeyboard
|
import im.vector.riotx.core.extensions.showKeyboard
|
||||||
import im.vector.riotx.core.files.addEntryToDownloadManager
|
import im.vector.riotx.core.files.addEntryToDownloadManager
|
||||||
import im.vector.riotx.core.glide.GlideApp
|
import im.vector.riotx.core.glide.GlideApp
|
||||||
|
import im.vector.riotx.core.intent.getMimeTypeFromUri
|
||||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||||
import im.vector.riotx.core.resources.ColorProvider
|
import im.vector.riotx.core.resources.ColorProvider
|
||||||
import im.vector.riotx.core.ui.views.JumpToReadMarkerView
|
import im.vector.riotx.core.ui.views.JumpToReadMarkerView
|
||||||
|
@ -1126,6 +1128,23 @@ class RoomDetailFragment @Inject constructor(
|
||||||
roomDetailViewModel.handle(RoomDetailAction.EnterTrackingUnreadMessagesState)
|
roomDetailViewModel.handle(RoomDetailAction.EnterTrackingUnreadMessagesState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
||||||
|
session.downloadFile(
|
||||||
|
FileService.DownloadMode.FOR_EXTERNAL_SHARE,
|
||||||
|
action.eventId,
|
||||||
|
action.messageContent.body,
|
||||||
|
action.messageContent.getFileUrl(),
|
||||||
|
action.messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
||||||
|
object : MatrixCallback<File> {
|
||||||
|
override fun onSuccess(data: File) {
|
||||||
|
if (isAdded) {
|
||||||
|
shareMedia(requireContext(), data, getMimeTypeFromUri(requireContext(), data.toUri()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleActions(action: EventSharedAction) {
|
private fun handleActions(action: EventSharedAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is EventSharedAction.OpenUserProfile -> {
|
is EventSharedAction.OpenUserProfile -> {
|
||||||
|
@ -1147,20 +1166,7 @@ class RoomDetailFragment @Inject constructor(
|
||||||
promptConfirmationToRedactEvent(action)
|
promptConfirmationToRedactEvent(action)
|
||||||
}
|
}
|
||||||
is EventSharedAction.Share -> {
|
is EventSharedAction.Share -> {
|
||||||
session.downloadFile(
|
onShareActionClicked(action)
|
||||||
FileService.DownloadMode.FOR_EXTERNAL_SHARE,
|
|
||||||
action.eventId,
|
|
||||||
action.messageContent.body,
|
|
||||||
action.messageContent.getFileUrl(),
|
|
||||||
action.messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
|
||||||
object : MatrixCallback<File> {
|
|
||||||
override fun onSuccess(data: File) {
|
|
||||||
if (isAdded) {
|
|
||||||
shareMedia(requireContext(), data, "image/*")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
is EventSharedAction.ViewEditHistory -> {
|
is EventSharedAction.ViewEditHistory -> {
|
||||||
onEditedDecorationClicked(action.messageInformationData)
|
onEditedDecorationClicked(action.messageInformationData)
|
||||||
|
|
|
@ -18,7 +18,7 @@ package im.vector.riotx.features.home.room.detail.timeline.action
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageImageContent
|
import im.vector.matrix.android.api.session.room.model.message.MessageEncryptedContent
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.platform.VectorSharedAction
|
import im.vector.riotx.core.platform.VectorSharedAction
|
||||||
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
|
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
|
||||||
|
@ -47,7 +47,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: MessageImageContent) :
|
data class Share(val eventId: String, val messageContent: MessageEncryptedContent) :
|
||||||
EventSharedAction(R.string.share, R.drawable.ic_share)
|
EventSharedAction(R.string.share, R.drawable.ic_share)
|
||||||
|
|
||||||
data class Resend(val eventId: String) :
|
data class Resend(val eventId: String) :
|
||||||
|
|
|
@ -29,8 +29,8 @@ import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.isTextMessage
|
import im.vector.matrix.android.api.session.events.model.isTextMessage
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
||||||
|
import im.vector.matrix.android.api.session.room.model.message.MessageEncryptedContent
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageFormat
|
import im.vector.matrix.android.api.session.room.model.message.MessageFormat
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageImageContent
|
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageTextContent
|
import im.vector.matrix.android.api.session.room.model.message.MessageTextContent
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageType
|
import im.vector.matrix.android.api.session.room.model.message.MessageType
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageVerificationRequestContent
|
import im.vector.matrix.android.api.session.room.model.message.MessageVerificationRequestContent
|
||||||
|
@ -261,10 +261,9 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canShare(msgType)) {
|
if (canShare(msgType)) {
|
||||||
if (messageContent is MessageImageContent) {
|
if (messageContent is MessageEncryptedContent) {
|
||||||
add(EventSharedAction.Share(timelineEvent.eventId, messageContent))
|
add(EventSharedAction.Share(timelineEvent.eventId, messageContent))
|
||||||
}
|
}
|
||||||
// TODO Support other media types
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timelineEvent.root.sendState == SendState.SENT) {
|
if (timelineEvent.root.sendState == SendState.SENT) {
|
||||||
|
@ -372,8 +371,9 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
||||||
return when (msgType) {
|
return when (msgType) {
|
||||||
MessageType.MSGTYPE_IMAGE,
|
MessageType.MSGTYPE_IMAGE,
|
||||||
MessageType.MSGTYPE_AUDIO,
|
MessageType.MSGTYPE_AUDIO,
|
||||||
MessageType.MSGTYPE_VIDEO -> true
|
MessageType.MSGTYPE_VIDEO,
|
||||||
else -> false
|
MessageType.MSGTYPE_FILE -> true
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,4 @@
|
||||||
<cache-path
|
<cache-path
|
||||||
name="shared"
|
name="shared"
|
||||||
path="/" />
|
path="/" />
|
||||||
|
|
||||||
<files-path
|
|
||||||
name="ext_share"
|
|
||||||
path="ext_share/" />
|
|
||||||
</paths>
|
</paths>
|
Loading…
Reference in a new issue