Timeline : start to handle media images/gif. Still a lot to do, but it's a first step.

This commit is contained in:
ganfra
2019-01-22 18:43:15 +01:00
parent dbb812ad84
commit 1d400180bc
12 changed files with 266 additions and 49 deletions

View File

@ -0,0 +1,31 @@
package im.vector.matrix.android.api.session.content
object ContentUrlResolver {
private const val MATRIX_CONTENT_URI_SCHEME = "mxc://"
private const val MEDIA_URL = "https://matrix.org/_matrix/media/v1/download/"
/**
* Get the actual URL for accessing the full-size image of a Matrix media content URI.
*
* @param contentUrl the Matrix media content URI (in the form of "mxc://...").
* @return the URL to access the described resource, or null if the url is invalid.
*/
fun resolve(contentUrl: String?): String? {
if (contentUrl.isValidMatrixContentUrl()) {
return contentUrl?.replace(MATRIX_CONTENT_URI_SCHEME, MEDIA_URL)
}
return null
}
/**
* Check whether an url is a valid matrix content url.
*
* @param contentUrl the content URL (in the form of "mxc://...").
* @return true if contentUrl is valid.
*/
private fun String?.isValidMatrixContentUrl(): Boolean {
return !this.isNullOrEmpty() && startsWith(MATRIX_CONTENT_URI_SCHEME)
}
}

View File

@ -6,9 +6,9 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class ImageInfo(
@Json(name = "mimetype") val mimeType: String,
@Json(name = "w") val w: Int,
@Json(name = "h") val h: Int,
@Json(name = "size") val size: Long,
@Json(name = "w") val width: Int,
@Json(name = "h") val height: Int,
@Json(name = "size") val size: Int,
@Json(name = "rotation") val rotation: Int? = null,
@Json(name = "orientation") val orientation: Int? = null,
@Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null,

View File

@ -129,16 +129,8 @@ public final class RuntimeJsonAdapterFactory<T> implements JsonAdapter.Factory {
Object jsonValue = reader.readJsonValue();
Map<String, Object> jsonObject = (Map<String, Object>) jsonValue;
Object label = jsonObject.get(labelKey);
if (label == null) {
throw new JsonDataException("Missing label for " + labelKey);
}
if (!(label instanceof String)) {
throw new JsonDataException("Label for '"
+ labelKey
+ "' must be a string but was "
+ label
+ ", a "
+ label.getClass());
return null;
}
JsonAdapter<Object> adapter = labelToAdapter.get(label);
if (adapter == null) {