mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Limit sticker size in the timeline
This commit is contained in:
parent
6652965e48
commit
4b0dfa49f4
5 changed files with 30 additions and 13 deletions
|
@ -7,6 +7,7 @@ Features ✨:
|
|||
Improvements 🙌:
|
||||
- Handle navigation to room via room alias (#201)
|
||||
- Open matrix.to link in RiotX (#57)
|
||||
- Limit sticker size in the timeline
|
||||
|
||||
Other changes:
|
||||
- Use same default room colors than Riot-Web
|
||||
|
|
|
@ -104,7 +104,7 @@ fun TimelineEvent.getLastMessageContent(): MessageContent? {
|
|||
root.getClearContent().toModel<MessageStickerContent>()
|
||||
} else {
|
||||
annotations?.editSummary?.aggregatedContent?.toModel()
|
||||
?: root.getClearContent().toModel()
|
||||
?: root.getClearContent().toModel()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ fun TimelineEvent.getLastMessageBody(): String? {
|
|||
|
||||
if (lastMessageContent != null) {
|
||||
return lastMessageContent.newContent?.toModel<MessageContent>()?.body
|
||||
?: lastMessageContent.body
|
||||
?: lastMessageContent.body
|
||||
}
|
||||
|
||||
return null
|
||||
|
|
|
@ -182,7 +182,9 @@ class MessageItemFactory @Inject constructor(
|
|||
.highlighted(highlight)
|
||||
.mediaData(data)
|
||||
.apply {
|
||||
if (messageContent.type != MessageType.MSGTYPE_STICKER_LOCAL) {
|
||||
if (messageContent.type == MessageType.MSGTYPE_STICKER_LOCAL) {
|
||||
mode(ImageContentRenderer.Mode.STICKER)
|
||||
} else {
|
||||
clickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onImageMessageClicked(messageContent, data, view)
|
||||
|
|
|
@ -36,6 +36,8 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
|
|||
@EpoxyAttribute
|
||||
var playable: Boolean = false
|
||||
@EpoxyAttribute
|
||||
var mode = ImageContentRenderer.Mode.THUMBNAIL
|
||||
@EpoxyAttribute
|
||||
var clickListener: View.OnClickListener? = null
|
||||
@EpoxyAttribute
|
||||
lateinit var imageContentRenderer: ImageContentRenderer
|
||||
|
@ -44,7 +46,7 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
|
|||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
imageContentRenderer.render(mediaData, ImageContentRenderer.Mode.THUMBNAIL, holder.imageView)
|
||||
imageContentRenderer.render(mediaData, mode, holder.imageView)
|
||||
if (!attributes.informationData.sendState.hasFailed()) {
|
||||
contentUploadStateTrackerBinder.bind(attributes.informationData.eventId, mediaData.isLocalFile(), holder.progressLayout)
|
||||
} else {
|
||||
|
|
|
@ -36,6 +36,7 @@ import im.vector.riotx.core.utils.isLocalFile
|
|||
import kotlinx.android.parcel.Parcelize
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.min
|
||||
|
||||
class ImageContentRenderer @Inject constructor(private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val dimensionConverter: DimensionConverter) {
|
||||
|
@ -56,7 +57,8 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
|
|||
|
||||
enum class Mode {
|
||||
FULL_SIZE,
|
||||
THUMBNAIL
|
||||
THUMBNAIL,
|
||||
STICKER
|
||||
}
|
||||
|
||||
fun render(data: Data, mode: Mode, imageView: ImageView) {
|
||||
|
@ -112,7 +114,8 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
|
|||
// Clear image
|
||||
val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver()
|
||||
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)
|
||||
}
|
||||
// Fallback to base url
|
||||
|
@ -149,18 +152,27 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
|
|||
val maxImageHeight = data.maxHeight
|
||||
val width = data.width ?: maxImageWidth
|
||||
val height = data.height ?: maxImageHeight
|
||||
var finalHeight = -1
|
||||
var finalWidth = -1
|
||||
var finalHeight = -1
|
||||
|
||||
// if the image size is known
|
||||
// compute the expected height
|
||||
if (width > 0 && height > 0) {
|
||||
if (mode == Mode.FULL_SIZE) {
|
||||
finalHeight = height
|
||||
finalWidth = width
|
||||
} else {
|
||||
finalHeight = Math.min(maxImageWidth * height / width, maxImageHeight)
|
||||
finalWidth = finalHeight * width / height
|
||||
when (mode) {
|
||||
Mode.FULL_SIZE -> {
|
||||
finalHeight = height
|
||||
finalWidth = width
|
||||
}
|
||||
Mode.THUMBNAIL -> {
|
||||
finalHeight = min(maxImageWidth * height / width, maxImageHeight)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue