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.ClickableSpan
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import android.view.WindowMetrics
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.epoxy.ClickListener
|
import im.vector.app.core.epoxy.ClickListener
|
||||||
|
@ -199,7 +201,7 @@ class MessageItemFactory @Inject constructor(
|
||||||
informationData: MessageInformationData,
|
informationData: MessageInformationData,
|
||||||
highlight: Boolean,
|
highlight: Boolean,
|
||||||
attributes: AbsMessageItem.Attributes): MessageLocationItem? {
|
attributes: AbsMessageItem.Attributes): MessageLocationItem? {
|
||||||
val width = resources.displayMetrics.widthPixels - dimensionConverter.dpToPx(60)
|
val width = timelineMediaSizeProvider.getMaxSize().first
|
||||||
val height = dimensionConverter.dpToPx(200)
|
val height = dimensionConverter.dpToPx(200)
|
||||||
|
|
||||||
val locationUrl = locationContent.toLocationData()?.let {
|
val locationUrl = locationContent.toLocationData()?.let {
|
||||||
|
@ -209,6 +211,8 @@ class MessageItemFactory @Inject constructor(
|
||||||
return MessageLocationItem_()
|
return MessageLocationItem_()
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
.locationUrl(locationUrl)
|
.locationUrl(locationUrl)
|
||||||
|
.mapWidth(width)
|
||||||
|
.mapHeight(height)
|
||||||
.userId(informationData.senderId)
|
.userId(informationData.senderId)
|
||||||
.locationPinProvider(locationPinProvider)
|
.locationPinProvider(locationPinProvider)
|
||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
|
|
|
@ -16,13 +16,17 @@
|
||||||
|
|
||||||
package im.vector.app.features.home.room.detail.timeline.helper
|
package im.vector.app.features.home.room.detail.timeline.helper
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import dagger.hilt.android.scopes.ActivityScoped
|
import dagger.hilt.android.scopes.ActivityScoped
|
||||||
|
import im.vector.app.R
|
||||||
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@ActivityScoped
|
@ActivityScoped
|
||||||
class TimelineMediaSizeProvider @Inject constructor() {
|
class TimelineMediaSizeProvider @Inject constructor(private val resources: Resources,
|
||||||
|
private val vectorPreferences: VectorPreferences) {
|
||||||
|
|
||||||
var recyclerView: RecyclerView? = null
|
var recyclerView: RecyclerView? = null
|
||||||
private var cachedSize: Pair<Int, Int>? = null
|
private var cachedSize: Pair<Int, Int>? = null
|
||||||
|
@ -41,9 +45,14 @@ class TimelineMediaSizeProvider @Inject constructor() {
|
||||||
maxImageWidth = (width * 0.7f).roundToInt()
|
maxImageWidth = (width * 0.7f).roundToInt()
|
||||||
maxImageHeight = (height * 0.5f).roundToInt()
|
maxImageHeight = (height * 0.5f).roundToInt()
|
||||||
} else {
|
} else {
|
||||||
maxImageWidth = (width * 0.5f).roundToInt()
|
maxImageWidth = (width * 0.7f).roundToInt()
|
||||||
maxImageHeight = (height * 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
|
package im.vector.app.features.home.room.detail.timeline.item
|
||||||
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
import com.airbnb.epoxy.EpoxyAttribute
|
import com.airbnb.epoxy.EpoxyAttribute
|
||||||
import com.airbnb.epoxy.EpoxyModelClass
|
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.R
|
||||||
import im.vector.app.core.glide.GlideApp
|
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.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)
|
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
|
||||||
abstract class MessageLocationItem : AbsMessageItem<MessageLocationItem.Holder>() {
|
abstract class MessageLocationItem : AbsMessageItem<MessageLocationItem.Holder>() {
|
||||||
|
@ -33,6 +37,12 @@ abstract class MessageLocationItem : AbsMessageItem<MessageLocationItem.Holder>(
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var userId: String? = null
|
var userId: String? = null
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
var mapWidth: Int = 0
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
var mapHeight: Int = 0
|
||||||
|
|
||||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
||||||
var locationPinProvider: LocationPinProvider? = null
|
var locationPinProvider: LocationPinProvider? = null
|
||||||
|
|
||||||
|
@ -41,9 +51,20 @@ abstract class MessageLocationItem : AbsMessageItem<MessageLocationItem.Holder>(
|
||||||
renderSendState(holder.view, null)
|
renderSendState(holder.view, null)
|
||||||
val location = locationUrl ?: return
|
val location = locationUrl ?: return
|
||||||
val locationOwnerId = userId ?: 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)
|
GlideApp.with(holder.staticMapImageView)
|
||||||
.load(location)
|
.load(location)
|
||||||
.apply(RequestOptions.centerCropTransform())
|
.transform(imageCornerTransformation)
|
||||||
.into(holder.staticMapImageView)
|
.into(holder.staticMapImageView)
|
||||||
|
|
||||||
locationPinProvider?.create(locationOwnerId) { pinDrawable ->
|
locationPinProvider?.create(locationOwnerId) { pinDrawable ->
|
||||||
|
|
|
@ -53,7 +53,6 @@ class RoomWidgetPermissionBottomSheet :
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
setupViews()
|
setupViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
app:cardCornerRadius="8dp">
|
|
||||||
|
|
||||||
|
<!-- Size will be overrode -->
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/staticMapImageView"
|
android:id="@+id/staticMapImageView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="300dp"
|
||||||
android:layout_height="200dp"
|
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
|
<ImageView
|
||||||
android:id="@+id/staticMapPinImageView"
|
android:id="@+id/staticMapPinImageView"
|
||||||
|
@ -19,6 +24,10 @@
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginBottom="28dp"
|
android:layout_marginBottom="28dp"
|
||||||
android:importantForAccessibility="no"
|
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