Introduce MatrixMediaSource

This commit is contained in:
ganfra 2023-05-05 19:47:10 +02:00
parent c3a1297c18
commit 4236b69705
27 changed files with 298 additions and 84 deletions

View file

@ -20,5 +20,5 @@ data class FileInfo(
val mimetype: String?,
val size: Long?,
val thumbnailInfo: ThumbnailInfo?,
val thumbnailUrl: String?
val thumbnailSource: MatrixMediaSource?
)

View file

@ -22,6 +22,6 @@ data class ImageInfo(
val mimetype: String?,
val size: Long?,
val thumbnailInfo: ThumbnailInfo?,
val thumbnailUrl: String?,
val thumbnailSource: MatrixMediaSource?,
val blurhash: String?
)

View file

@ -16,14 +16,14 @@
package io.element.android.libraries.matrix.api.media
import java.nio.file.Path
import android.net.Uri
interface MatrixMediaLoader {
/**
* @param url to fetch the content for.
* @return a [Result] of ByteArray. It contains the binary data for the media.
*/
suspend fun loadMediaContent(url: String): Result<ByteArray>
suspend fun loadMediaContent(source: MatrixMediaSource): Result<ByteArray>
/**
* @param url to fetch the data for.
@ -31,12 +31,12 @@ interface MatrixMediaLoader {
* @param height: the desired height for rescaling the media as thumbnail
* @return a [Result] of ByteArray. It contains the binary data for the media.
*/
suspend fun loadMediaThumbnail(url: String, width: Long, height: Long): Result<ByteArray>
suspend fun loadMediaThumbnail(source: MatrixMediaSource, width: Long, height: Long): Result<ByteArray>
/**
* @param url to fetch the data for.
* @param mimeType: optional mime type
* @return a [Result] of [Path]. It's the path to the downloaded file.
* @return a [Result] of [Uri]. It's the uri of the downloaded file.
*/
suspend fun loadMediaFile(url: String, mimeType: String?): Result<Path>
suspend fun loadMediaFile(source: MatrixMediaSource, mimeType: String?): Result<Uri>
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.api.media
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
@Parcelize
data class MatrixMediaSource(
val url: String
) : Parcelable

View file

@ -23,6 +23,6 @@ data class VideoInfo(
val mimetype: String?,
val size: Long?,
val thumbnailInfo: ThumbnailInfo?,
val thumbnailUrl: String?,
val thumbnailSource: MatrixMediaSource?,
val blurhash: String?
)

View file

@ -21,6 +21,7 @@ import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.media.AudioInfo
import io.element.android.libraries.matrix.api.media.FileInfo
import io.element.android.libraries.matrix.api.media.ImageInfo
import io.element.android.libraries.matrix.api.media.MatrixMediaSource
import io.element.android.libraries.matrix.api.media.VideoInfo
sealed interface EventContent
@ -106,25 +107,25 @@ data class EmoteMessageType(
data class ImageMessageType(
val body: String,
val url: String,
val source: MatrixMediaSource,
val info: ImageInfo?
) : MessageType
data class AudioMessageType(
var body: String,
var url: String,
var info: AudioInfo?
val body: String,
val source: MatrixMediaSource,
val info: AudioInfo?
) : MessageType
data class VideoMessageType(
val body: String,
val url: String,
val source: MatrixMediaSource,
val info: VideoInfo?
) : MessageType
data class FileMessageType(
val body: String,
val url: String,
val source: MatrixMediaSource,
val info: FileInfo?
) : MessageType