Limit sticker size in the timeline

This commit is contained in:
Benoit Marty 2019-12-19 11:44:07 +01:00
parent 6652965e48
commit 4b0dfa49f4
5 changed files with 30 additions and 13 deletions

View file

@ -7,6 +7,7 @@ Features ✨:
Improvements 🙌: Improvements 🙌:
- Handle navigation to room via room alias (#201) - Handle navigation to room via room alias (#201)
- Open matrix.to link in RiotX (#57) - Open matrix.to link in RiotX (#57)
- Limit sticker size in the timeline
Other changes: Other changes:
- Use same default room colors than Riot-Web - Use same default room colors than Riot-Web

View file

@ -182,7 +182,9 @@ class MessageItemFactory @Inject constructor(
.highlighted(highlight) .highlighted(highlight)
.mediaData(data) .mediaData(data)
.apply { .apply {
if (messageContent.type != MessageType.MSGTYPE_STICKER_LOCAL) { if (messageContent.type == MessageType.MSGTYPE_STICKER_LOCAL) {
mode(ImageContentRenderer.Mode.STICKER)
} else {
clickListener( clickListener(
DebouncedClickListener(View.OnClickListener { view -> DebouncedClickListener(View.OnClickListener { view ->
callback?.onImageMessageClicked(messageContent, data, view) callback?.onImageMessageClicked(messageContent, data, view)

View file

@ -36,6 +36,8 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
@EpoxyAttribute @EpoxyAttribute
var playable: Boolean = false var playable: Boolean = false
@EpoxyAttribute @EpoxyAttribute
var mode = ImageContentRenderer.Mode.THUMBNAIL
@EpoxyAttribute
var clickListener: View.OnClickListener? = null var clickListener: View.OnClickListener? = null
@EpoxyAttribute @EpoxyAttribute
lateinit var imageContentRenderer: ImageContentRenderer lateinit var imageContentRenderer: ImageContentRenderer
@ -44,7 +46,7 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
imageContentRenderer.render(mediaData, ImageContentRenderer.Mode.THUMBNAIL, holder.imageView) imageContentRenderer.render(mediaData, mode, holder.imageView)
if (!attributes.informationData.sendState.hasFailed()) { if (!attributes.informationData.sendState.hasFailed()) {
contentUploadStateTrackerBinder.bind(attributes.informationData.eventId, mediaData.isLocalFile(), holder.progressLayout) contentUploadStateTrackerBinder.bind(attributes.informationData.eventId, mediaData.isLocalFile(), holder.progressLayout)
} else { } else {

View file

@ -36,6 +36,7 @@ import im.vector.riotx.core.utils.isLocalFile
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.min
class ImageContentRenderer @Inject constructor(private val activeSessionHolder: ActiveSessionHolder, class ImageContentRenderer @Inject constructor(private val activeSessionHolder: ActiveSessionHolder,
private val dimensionConverter: DimensionConverter) { private val dimensionConverter: DimensionConverter) {
@ -56,7 +57,8 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
enum class Mode { enum class Mode {
FULL_SIZE, FULL_SIZE,
THUMBNAIL THUMBNAIL,
STICKER
} }
fun render(data: Data, mode: Mode, imageView: ImageView) { fun render(data: Data, mode: Mode, imageView: ImageView) {
@ -112,7 +114,8 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
// Clear image // Clear image
val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver() val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver()
val resolvedUrl = when (mode) { val resolvedUrl = when (mode) {
Mode.FULL_SIZE -> contentUrlResolver.resolveFullSize(data.url) Mode.FULL_SIZE,
Mode.STICKER -> contentUrlResolver.resolveFullSize(data.url)
Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE) Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE)
} }
// Fallback to base url // Fallback to base url
@ -149,19 +152,28 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
val maxImageHeight = data.maxHeight val maxImageHeight = data.maxHeight
val width = data.width ?: maxImageWidth val width = data.width ?: maxImageWidth
val height = data.height ?: maxImageHeight val height = data.height ?: maxImageHeight
var finalHeight = -1
var finalWidth = -1 var finalWidth = -1
var finalHeight = -1
// if the image size is known // if the image size is known
// compute the expected height // compute the expected height
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
if (mode == Mode.FULL_SIZE) { when (mode) {
Mode.FULL_SIZE -> {
finalHeight = height finalHeight = height
finalWidth = width finalWidth = width
} else { }
finalHeight = Math.min(maxImageWidth * height / width, maxImageHeight) Mode.THUMBNAIL -> {
finalHeight = min(maxImageWidth * height / width, maxImageHeight)
finalWidth = finalHeight * width / height finalWidth = finalHeight * width / height
} }
Mode.STICKER -> {
// limit on width
val maxWidthDp = min(dimensionConverter.dpToPx(120), maxImageWidth / 2)
finalWidth = min(dimensionConverter.dpToPx(width), maxWidthDp)
finalHeight = finalWidth * height / width
}
}
} }
// ensure that some values are properly initialized // ensure that some values are properly initialized
if (finalHeight < 0) { if (finalHeight < 0) {