diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index cedcb66ef3..eda0fb925c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -25,6 +25,8 @@ import android.text.style.AbsoluteSizeSpan import android.text.style.ClickableSpan import android.text.style.ForegroundColorSpan import android.view.View +import android.view.WindowManager +import android.view.WindowMetrics import dagger.Lazy import im.vector.app.R import im.vector.app.core.epoxy.ClickListener @@ -199,7 +201,7 @@ class MessageItemFactory @Inject constructor( informationData: MessageInformationData, highlight: Boolean, attributes: AbsMessageItem.Attributes): MessageLocationItem? { - val width = resources.displayMetrics.widthPixels - dimensionConverter.dpToPx(60) + val width = timelineMediaSizeProvider.getMaxSize().first val height = dimensionConverter.dpToPx(200) val locationUrl = locationContent.toLocationData()?.let { @@ -209,6 +211,8 @@ class MessageItemFactory @Inject constructor( return MessageLocationItem_() .attributes(attributes) .locationUrl(locationUrl) + .mapWidth(width) + .mapHeight(height) .userId(informationData.senderId) .locationPinProvider(locationPinProvider) .highlighted(highlight) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt index 9ec61e6054..53c2f6c0d4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt @@ -16,13 +16,17 @@ package im.vector.app.features.home.room.detail.timeline.helper +import android.content.res.Resources import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.scopes.ActivityScoped +import im.vector.app.R +import im.vector.app.features.settings.VectorPreferences import javax.inject.Inject import kotlin.math.roundToInt @ActivityScoped -class TimelineMediaSizeProvider @Inject constructor() { +class TimelineMediaSizeProvider @Inject constructor(private val resources: Resources, + private val vectorPreferences: VectorPreferences) { var recyclerView: RecyclerView? = null private var cachedSize: Pair? = null @@ -41,9 +45,14 @@ class TimelineMediaSizeProvider @Inject constructor() { maxImageWidth = (width * 0.7f).roundToInt() maxImageHeight = (height * 0.5f).roundToInt() } else { - maxImageWidth = (width * 0.5f).roundToInt() + maxImageWidth = (width * 0.7f).roundToInt() maxImageHeight = (height * 0.7f).roundToInt() } - return Pair(maxImageWidth, maxImageHeight) + return if (vectorPreferences.useMessageBubblesLayout()) { + val bubbleMaxImageWidth = maxImageWidth.coerceAtMost(resources.getDimensionPixelSize(R.dimen.chat_bubble_fixed_size)) + Pair(bubbleMaxImageWidth, maxImageHeight) + } else { + Pair(maxImageWidth, maxImageHeight) + } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt index 11faad8f13..6632b4ef30 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt @@ -17,12 +17,16 @@ package im.vector.app.features.home.room.detail.timeline.item import android.widget.ImageView +import androidx.core.view.updateLayoutParams import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass -import com.bumptech.glide.request.RequestOptions +import com.bumptech.glide.load.resource.bitmap.RoundedCorners import im.vector.app.R import im.vector.app.core.glide.GlideApp +import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider +import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout +import im.vector.app.features.home.room.detail.timeline.style.granularRoundedCorners @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageLocationItem : AbsMessageItem() { @@ -33,6 +37,12 @@ abstract class MessageLocationItem : AbsMessageItem( @EpoxyAttribute var userId: String? = null + @EpoxyAttribute + var mapWidth: Int = 0 + + @EpoxyAttribute + var mapHeight: Int = 0 + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var locationPinProvider: LocationPinProvider? = null @@ -41,9 +51,20 @@ abstract class MessageLocationItem : AbsMessageItem( renderSendState(holder.view, null) val location = locationUrl ?: return val locationOwnerId = userId ?: return + val messageLayout = attributes.informationData.messageLayout + val dimensionConverter = DimensionConverter(holder.view.resources) + val imageCornerTransformation = if (messageLayout is TimelineMessageLayout.Bubble) { + messageLayout.cornersRadius.granularRoundedCorners() + } else { + RoundedCorners(dimensionConverter.dpToPx(8)) + } + holder.staticMapImageView.updateLayoutParams { + width = mapWidth + height = mapHeight + } GlideApp.with(holder.staticMapImageView) .load(location) - .apply(RequestOptions.centerCropTransform()) + .transform(imageCornerTransformation) .into(holder.staticMapImageView) locationPinProvider?.create(locationOwnerId) { pinDrawable -> diff --git a/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt b/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt index 58cfebba94..91371b1f73 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt @@ -53,7 +53,6 @@ class RoomWidgetPermissionBottomSheet : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setupViews() } diff --git a/vector/src/main/res/layout/item_timeline_event_location_stub.xml b/vector/src/main/res/layout/item_timeline_event_location_stub.xml index 316470b5f1..77c7b932ce 100644 --- a/vector/src/main/res/layout/item_timeline_event_location_stub.xml +++ b/vector/src/main/res/layout/item_timeline_event_location_stub.xml @@ -1,16 +1,21 @@ - + android:layout_height="wrap_content"> + + android:contentDescription="@string/a11y_static_map_image" + android:scaleType="centerCrop" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:src="@tools:sample/backgrounds/scenic" /> + android:src="@drawable/bg_map_user_pin" + app:layout_constraintBottom_toBottomOf="@id/staticMapImageView" + app:layout_constraintEnd_toEndOf="@id/staticMapImageView" + app:layout_constraintStart_toStartOf="@id/staticMapImageView" + app:layout_constraintTop_toTopOf="@id/staticMapImageView" /> - +