Fix messages content info can be null

This commit is contained in:
ganfra 2019-01-25 18:40:02 +01:00
parent 9b1277485e
commit ad2abd5cdd
13 changed files with 36 additions and 37 deletions

View File

@ -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)
}

View File

@ -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<Int, Int> {
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


View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
)

View File

@ -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
)