diff --git a/CHANGES.md b/CHANGES.md index 1ed4d31224..c067050cda 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Cross-Signing | Support SSSS secret sharing (#944) - Cross-Signing | Verify new session from existing session (#1134) - Cross-Signing | Bootstraping cross signing with 4S from mobile (#985) - + - Save media files to Gallery (#973) Improvements 🙌: - Verification DM / Handle concurrent .start after .ready (#794) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index f34a578832..ffb71a38c5 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -279,6 +279,7 @@ class MessageItemFactory @Inject constructor( attributes: AbsMessageItem.Attributes): MessageImageVideoItem? { val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize() val data = ImageContentRenderer.Data( + eventId = informationData.eventId, filename = messageContent.body, url = messageContent.getFileUrl(), elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(), @@ -314,6 +315,7 @@ class MessageItemFactory @Inject constructor( attributes: AbsMessageItem.Attributes): MessageImageVideoItem? { val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize() val thumbnailData = ImageContentRenderer.Data( + eventId = informationData.eventId, filename = messageContent.body, url = messageContent.videoInfo?.thumbnailFile?.url ?: messageContent.videoInfo?.thumbnailUrl, diff --git a/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt index 737549d5b8..becb714bf4 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/ImageContentRenderer.kt @@ -46,6 +46,7 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder: @Parcelize data class Data( + val eventId: String, val filename: String, val url: String?, val elementToDecrypt: ElementToDecrypt?, diff --git a/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt index 8ba21468b7..ca6510a897 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt @@ -21,10 +21,12 @@ import android.content.Intent import android.graphics.drawable.Drawable import android.os.Build import android.os.Bundle +import android.view.MenuItem import android.view.View import android.view.ViewTreeObserver import androidx.annotation.RequiresApi import androidx.appcompat.widget.Toolbar +import androidx.core.net.toUri import androidx.core.transition.addListener import androidx.core.view.ViewCompat import androidx.core.view.isInvisible @@ -36,15 +38,23 @@ import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator import com.github.piasy.biv.view.GlideImageViewFactory +import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.file.FileService +import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.glide.GlideApp +import im.vector.riotx.core.intent.getMimeTypeFromUri import im.vector.riotx.core.platform.VectorBaseActivity +import im.vector.riotx.core.utils.shareMedia import kotlinx.android.synthetic.main.activity_image_media_viewer.* import timber.log.Timber +import java.io.File import javax.inject.Inject class ImageMediaViewerActivity : VectorBaseActivity() { + @Inject lateinit var session: Session @Inject lateinit var imageContentRenderer: ImageContentRenderer private lateinit var mediaData: ImageContentRenderer.Data @@ -110,6 +120,33 @@ class ImageMediaViewerActivity : VectorBaseActivity() { } } + override fun getMenuRes() = R.menu.vector_media_viewer + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.mediaViewerShareAction -> { + onShareActionClicked() + return true + } + } + return super.onOptionsItemSelected(item) + } + + private fun onShareActionClicked() { + session.downloadFile( + FileService.DownloadMode.FOR_EXTERNAL_SHARE, + mediaData.eventId, + mediaData.filename, + mediaData.url, + mediaData.elementToDecrypt, + object : MatrixCallback { + override fun onSuccess(data: File) { + shareMedia(this@ImageMediaViewerActivity, data, getMimeTypeFromUri(this@ImageMediaViewerActivity, data.toUri())) + } + } + ) + } + private fun configureToolbar(toolbar: Toolbar, mediaData: ImageContentRenderer.Data) { setSupportActionBar(toolbar) supportActionBar?.apply { diff --git a/vector/src/main/res/menu/vector_media_viewer.xml b/vector/src/main/res/menu/vector_media_viewer.xml new file mode 100644 index 0000000000..09b6cedacd --- /dev/null +++ b/vector/src/main/res/menu/vector_media_viewer.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file