From ad2abd5cdd41b6cc8dadc5930a9b5c1cec9904ea Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Jan 2019 18:40:02 +0100 Subject: [PATCH] Fix messages content info can be null --- .../detail/timeline/MessageItemFactory.kt | 10 +++---- .../features/media/MediaContentRenderer.kt | 26 +++++++++---------- .../session/room/model/message/AudioInfo.kt | 4 +-- .../session/room/model/message/FileInfo.kt | 2 +- .../session/room/model/message/ImageInfo.kt | 3 +-- .../room/model/message/LocationInfo.kt | 4 +-- .../room/model/message/MessageAudioContent.kt | 2 +- .../room/model/message/MessageFileContent.kt | 2 +- .../room/model/message/MessageImageContent.kt | 2 +- .../model/message/MessageLocationContent.kt | 2 +- .../room/model/message/MessageVideoContent.kt | 2 +- .../room/model/message/ThumbnailInfo.kt | 6 ++--- .../session/room/model/message/VideoInfo.kt | 8 +++--- 13 files changed, 36 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt index ecb783b7..35b55933 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt @@ -21,11 +21,11 @@ import android.text.util.Linkify import im.vector.matrix.android.api.permalinks.MatrixLinkify import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan import im.vector.matrix.android.api.session.events.model.EventType -import im.vector.matrix.android.api.session.room.timeline.TimelineEvent 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.MessageImageContent import im.vector.matrix.android.api.session.room.model.message.MessageTextContent +import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.riotredesign.core.extensions.localDateTime import im.vector.riotredesign.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider import im.vector.riotredesign.features.media.MediaContentRenderer @@ -76,12 +76,12 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize() val data = MediaContentRenderer.Data( url = messageContent.url, - height = messageContent.info.height, + height = messageContent.info?.height, maxHeight = maxHeight, - width = messageContent.info.width, + width = messageContent.info?.width, maxWidth = maxWidth, - rotation = messageContent.info.rotation, - orientation = messageContent.info.orientation + rotation = messageContent.info?.rotation, + orientation = messageContent.info?.orientation ) return MessageImageItem(data, informationData) } diff --git a/app/src/main/java/im/vector/riotredesign/features/media/MediaContentRenderer.kt b/app/src/main/java/im/vector/riotredesign/features/media/MediaContentRenderer.kt index 0130a846..9a97ad6b 100644 --- a/app/src/main/java/im/vector/riotredesign/features/media/MediaContentRenderer.kt +++ b/app/src/main/java/im/vector/riotredesign/features/media/MediaContentRenderer.kt @@ -26,12 +26,12 @@ object MediaContentRenderer { data class Data( val url: String?, - val height: Int, + val height: Int?, val maxHeight: Int, - val width: Int, - val maxWidth: Int = width, - val orientation: Int, - val rotation: Int + val width: Int?, + val maxWidth: Int, + val orientation: Int?, + val rotation: Int? ) enum class Mode { @@ -46,10 +46,10 @@ object MediaContentRenderer { val contentUrlResolver = Matrix.getInstance().currentSession.contentUrlResolver() val resolvedUrl = when (mode) { - Mode.FULL_SIZE -> contentUrlResolver.resolveFullSize(data.url) - Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE) - } - ?: return + Mode.FULL_SIZE -> contentUrlResolver.resolveFullSize(data.url) + Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE) + } + ?: return GlideApp .with(imageView) @@ -61,10 +61,10 @@ object MediaContentRenderer { private fun processSize(data: Data, mode: Mode): Pair { val maxImageWidth = data.maxWidth val maxImageHeight = data.maxHeight - val rotationAngle = data.rotation - val orientation = data.orientation - var width = data.width - var height = data.height + val rotationAngle = data.rotation ?: 0 + val orientation = data.orientation ?: ExifInterface.ORIENTATION_NORMAL + var width = data.width ?: maxImageWidth + var height = data.height ?: maxImageHeight var finalHeight = -1 var finalWidth = -1 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt index 0c45f92f..6a28a1b3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt @@ -22,6 +22,6 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class AudioInfo( @Json(name = "mimetype") val mimeType: String, - @Json(name = "size") val size: Long, - @Json(name = "duration") val duration: Int + @Json(name = "size") val size: Long = 0, + @Json(name = "duration") val duration: Int = 0 ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt index 29d7e94c..2a115a58 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt @@ -22,7 +22,7 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class FileInfo( @Json(name = "mimetype") val mimeType: String, - @Json(name = "size") val size: Long, + @Json(name = "size") val size: Long = 0, @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null, @Json(name = "thumbnail_url") val thumbnailUrl: String? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt index a3b042c7..513a4366 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt @@ -16,7 +16,6 @@ package im.vector.matrix.android.api.session.room.model.message -import android.media.ExifInterface import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @@ -27,7 +26,7 @@ data class ImageInfo( @Json(name = "h") val height: Int = 0, @Json(name = "size") val size: Int = 0, @Json(name = "rotation") val rotation: Int = 0, - @Json(name = "orientation") val orientation: Int = ExifInterface.ORIENTATION_NORMAL, + @Json(name = "orientation") val orientation: Int = 0, @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null, @Json(name = "thumbnail_url") val thumbnailUrl: String? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt index bb0cd5f0..0f911a9b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt @@ -21,6 +21,6 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class LocationInfo( - @Json(name = "thumbnail_url") val thumbnailUrl: String, - @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo + @Json(name = "thumbnail_url") val thumbnailUrl: String? = null, + @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt index 03e2c56c..ffae8eef 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt @@ -23,6 +23,6 @@ import com.squareup.moshi.JsonClass data class MessageAudioContent( @Json(name = "msgtype") override val type: String, @Json(name = "body") override val body: String, - @Json(name = "info") val info: AudioInfo, + @Json(name = "info") val info: AudioInfo? = null, @Json(name = "url") val url: String? = null ) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt index 263caa62..505aee7a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt @@ -24,6 +24,6 @@ data class MessageFileContent( @Json(name = "msgtype") override val type: String, @Json(name = "body") override val body: String, @Json(name = "filename") val filename: String? = null, - @Json(name = "info") val info: FileInfo, + @Json(name = "info") val info: FileInfo? = null, @Json(name = "url") val url: String? = null ) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt index ecc0ee77..a3e2f661 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt @@ -23,6 +23,6 @@ import com.squareup.moshi.JsonClass data class MessageImageContent( @Json(name = "msgtype") override val type: String, @Json(name = "body") override val body: String, - @Json(name = "info") val info: ImageInfo, + @Json(name = "info") val info: ImageInfo? = null, @Json(name = "url") val url: String? = null ) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt index 6842e96d..b17bfae1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt @@ -24,5 +24,5 @@ data class MessageLocationContent( @Json(name = "msgtype") override val type: String, @Json(name = "body") override val body: String, @Json(name = "geo_uri") val geoUri: String, - @Json(name = "info") val info: LocationInfo + @Json(name = "info") val info: LocationInfo? = null ) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt index 43e35f11..319a9493 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt @@ -23,6 +23,6 @@ import com.squareup.moshi.JsonClass data class MessageVideoContent( @Json(name = "msgtype") override val type: String, @Json(name = "body") override val body: String, - @Json(name = "info") val info: VideoInfo, + @Json(name = "info") val info: VideoInfo? = null, @Json(name = "url") val url: String? = null ) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt index 29438c29..aa68d8f0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt @@ -21,8 +21,8 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class ThumbnailInfo( - @Json(name = "w") val width: Int, - @Json(name = "h") val height: Int, - @Json(name = "size") val size: Long, + @Json(name = "w") val width: Int = 0, + @Json(name = "h") val height: Int = 0, + @Json(name = "size") val size: Long = 0, @Json(name = "mimetype") val mimeType: String ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt index dcbafbe0..1a0768df 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt @@ -22,10 +22,10 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class VideoInfo( @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 = "duration") val duration: Int, + @Json(name = "w") val w: Int = 0, + @Json(name = "h") val h: Int = 0, + @Json(name = "size") val size: Long = 0, + @Json(name = "duration") val duration: Int = 0, @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null, @Json(name = "thumbnail_url") val thumbnailUrl: String? = null ) \ No newline at end of file