Bubbles: update media sizing (including LocationItem)
This commit is contained in:
parent
825c2ca989
commit
50810065a2
|
@ -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)
|
||||
|
|
|
@ -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<Int, Int>? = 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MessageLocationItem.Holder>() {
|
||||
|
@ -33,6 +37,12 @@ abstract class MessageLocationItem : AbsMessageItem<MessageLocationItem.Holder>(
|
|||
@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<MessageLocationItem.Holder>(
|
|||
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 ->
|
||||
|
|
|
@ -53,7 +53,6 @@ class RoomWidgetPermissionBottomSheet :
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupViews()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="8dp">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<!-- Size will be overrode -->
|
||||
<ImageView
|
||||
android:id="@+id/staticMapImageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="200dp"
|
||||
android:contentDescription="@string/a11y_static_map_image" />
|
||||
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" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/staticMapPinImageView"
|
||||
|
@ -19,6 +24,10 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="28dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/bg_map_user_pin" />
|
||||
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" />
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
Loading…
Reference in New Issue