Skip to content

Commit 6ea0129

Browse files
committed
Location sharing: use Room member avatar instead of profile avatar.
1 parent c6bb054 commit 6ea0129

File tree

18 files changed

+91
-56
lines changed

18 files changed

+91
-56
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/livelocation/LiveLocationShareAggregatedSummary.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocati
2222
* Aggregation info concerning a live location share.
2323
*/
2424
data class LiveLocationShareAggregatedSummary(
25+
val roomId: String?,
2526
val userId: String?,
2627
/**
2728
* Indicate whether the live is currently running.

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/LiveLocationShareAggregatedSummaryMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal class LiveLocationShareAggregatedSummaryMapper @Inject constructor() :
2828

2929
override fun map(entity: LiveLocationShareAggregatedSummaryEntity): LiveLocationShareAggregatedSummary {
3030
return LiveLocationShareAggregatedSummary(
31+
roomId = entity.roomId,
3132
userId = entity.userId,
3233
isActive = entity.isActive,
3334
endOfLiveTimestampMillis = entity.endOfLiveTimestampMillis,

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/LiveLocationShareAggregatedSummaryMapperTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.session.room.model.message.LocationInfo
2424
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
2525
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity
2626

27+
private const val ANY_ROOM_ID = "a-room-id"
2728
private const val ANY_USER_ID = "a-user-id"
2829
private const val ANY_ACTIVE_STATE = true
2930
private const val ANY_TIMEOUT = 123L
@@ -40,6 +41,7 @@ class LiveLocationShareAggregatedSummaryMapperTest {
4041
val summary = mapper.map(entity)
4142

4243
summary shouldBeEqualTo LiveLocationShareAggregatedSummary(
44+
roomId = ANY_ROOM_ID,
4345
userId = ANY_USER_ID,
4446
isActive = ANY_ACTIVE_STATE,
4547
endOfLiveTimestampMillis = ANY_TIMEOUT,
@@ -48,6 +50,7 @@ class LiveLocationShareAggregatedSummaryMapperTest {
4850
}
4951

5052
private fun anEntity(content: MessageBeaconLocationDataContent) = LiveLocationShareAggregatedSummaryEntity(
53+
roomId = ANY_ROOM_ID,
5154
userId = ANY_USER_ID,
5255
isActive = ANY_ACTIVE_STATE,
5356
endOfLiveTimestampMillis = ANY_TIMEOUT,

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/location/DefaultLocationSharingServiceTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ internal class DefaultLocationSharingServiceTest {
229229
fun `livedata of live summaries is correctly computed`() {
230230
val entity = LiveLocationShareAggregatedSummaryEntity()
231231
val summary = LiveLocationShareAggregatedSummary(
232+
roomId = A_ROOM_ID,
232233
userId = "",
233234
isActive = true,
234235
endOfLiveTimestampMillis = 123,
@@ -255,6 +256,7 @@ internal class DefaultLocationSharingServiceTest {
255256
fun `given an event id when getting livedata on corresponding live summary then it is correctly computed`() {
256257
val entity = LiveLocationShareAggregatedSummaryEntity()
257258
val summary = LiveLocationShareAggregatedSummary(
259+
roomId = A_ROOM_ID,
258260
userId = "",
259261
isActive = true,
260262
endOfLiveTimestampMillis = 123,

vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetMessagePreviewItem.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
103103
.apply(RequestOptions.centerCropTransform())
104104
.into(holder.staticMapImageView)
105105

106-
safeLocationUiData.locationPinProvider.create(safeLocationUiData.locationOwnerId) { pinDrawable ->
106+
val pinMatrixItem = matrixItem.takeIf { safeLocationUiData.locationOwnerId != null }
107+
safeLocationUiData.locationPinProvider.create(pinMatrixItem) { pinDrawable ->
107108
// we are not using Glide since it does not display it correctly when there is no user photo
108109
holder.staticMapPinImageView.setImageDrawable(pinDrawable)
109110
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/LiveLocationShareMessageItemFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class LiveLocationShareMessageItemFactory @Inject constructor(
114114
.locationUrl(locationUrl)
115115
.mapWidth(width)
116116
.mapHeight(height)
117-
.locationUserId(attributes.informationData.senderId)
117+
.pinMatrixItem(attributes.informationData.matrixItem)
118118
.locationPinProvider(locationPinProvider)
119119
.highlighted(highlight)
120120
.leftGuideline(avatarSizeProvider.leftGuideline)

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ class MessageItemFactory @Inject constructor(
233233
urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, width, height)
234234
}
235235

236-
val locationUserId = if (locationContent.isSelfLocation()) informationData.senderId else null
236+
val pinMatrixItem = if (locationContent.isSelfLocation()) informationData.matrixItem else null
237237

238238
return MessageLocationItem_()
239239
.attributes(attributes)
240240
.locationUrl(locationUrl)
241241
.mapWidth(width)
242242
.mapHeight(height)
243-
.locationUserId(locationUserId)
243+
.pinMatrixItem(pinMatrixItem)
244244
.locationPinProvider(locationPinProvider)
245245
.highlighted(highlight)
246246
.leftGuideline(avatarSizeProvider.leftGuideline)

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/LocationPinProvider.kt

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ import androidx.core.graphics.drawable.DrawableCompat
2525
import com.bumptech.glide.request.target.CustomTarget
2626
import com.bumptech.glide.request.transition.Transition
2727
import im.vector.app.R
28-
import im.vector.app.core.di.ActiveSessionHolder
2928
import im.vector.app.core.glide.GlideApp
3029
import im.vector.app.core.utils.DimensionConverter
3130
import im.vector.app.features.home.AvatarRenderer
32-
import org.matrix.android.sdk.api.session.getUserOrDefault
3331
import org.matrix.android.sdk.api.util.MatrixItem
34-
import org.matrix.android.sdk.api.util.toMatrixItem
3532
import timber.log.Timber
3633
import javax.inject.Inject
3734
import javax.inject.Singleton
@@ -44,61 +41,53 @@ private data class CachedDrawable(
4441
@Singleton
4542
class LocationPinProvider @Inject constructor(
4643
private val context: Context,
47-
private val activeSessionHolder: ActiveSessionHolder,
4844
private val dimensionConverter: DimensionConverter,
4945
private val avatarRenderer: AvatarRenderer,
5046
private val matrixItemColorProvider: MatrixItemColorProvider
5147
) {
52-
private val cache = LruCache<MatrixItem.UserItem, CachedDrawable>(32)
48+
private val cache = LruCache<MatrixItem, CachedDrawable>(32)
5349

5450
private val glideRequests by lazy {
5551
GlideApp.with(context)
5652
}
5753

5854
/**
5955
* Creates a pin drawable. If userId is null then a generic pin drawable will be created.
60-
* @param userId userId that will be used to retrieve user avatar
56+
* @param matrixUser user that will be used to retrieve user avatar
6157
* @param callback Pin drawable will be sent through the callback
6258
*/
63-
fun create(userId: String?, callback: (Drawable) -> Unit) {
64-
if (userId == null) {
59+
fun create(matrixUser: MatrixItem?, callback: (Drawable) -> Unit) {
60+
if (matrixUser == null) {
6561
callback(ContextCompat.getDrawable(context, R.drawable.ic_location_pin)!!)
6662
return
6763
}
64+
val size = dimensionConverter.dpToPx(44)
65+
avatarRenderer.render(glideRequests, matrixUser, object : CustomTarget<Drawable>(size, size) {
66+
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
67+
Timber.d("## Location: onResourceReady")
68+
val pinDrawable = createPinDrawable(matrixUser, resource, isError = false)
69+
callback(pinDrawable)
70+
}
6871

69-
activeSessionHolder
70-
.getActiveSession()
71-
.getUserOrDefault(userId)
72-
.toMatrixItem()
73-
.let { userItem ->
74-
val size = dimensionConverter.dpToPx(44)
75-
avatarRenderer.render(glideRequests, userItem, object : CustomTarget<Drawable>(size, size) {
76-
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
77-
Timber.d("## Location: onResourceReady")
78-
val pinDrawable = createPinDrawable(userItem, resource, isError = false)
79-
callback(pinDrawable)
80-
}
72+
override fun onLoadCleared(placeholder: Drawable?) {
73+
// Is it possible? Put placeholder instead?
74+
// FIXME The doc says it has to be implemented and should free resources
75+
Timber.d("## Location: onLoadCleared")
76+
}
8177

82-
override fun onLoadCleared(placeholder: Drawable?) {
83-
// Is it possible? Put placeholder instead?
84-
// FIXME The doc says it has to be implemented and should free resources
85-
Timber.d("## Location: onLoadCleared")
86-
}
87-
88-
override fun onLoadFailed(errorDrawable: Drawable?) {
89-
// Note: `onLoadFailed` is also called when the user has no avatarUrl
90-
// and the errorDrawable is actually the placeholder.
91-
Timber.w("## Location: onLoadFailed")
92-
errorDrawable ?: return
93-
val pinDrawable = createPinDrawable(userItem, errorDrawable, isError = true)
94-
callback(pinDrawable)
95-
}
96-
})
97-
}
78+
override fun onLoadFailed(errorDrawable: Drawable?) {
79+
// Note: `onLoadFailed` is also called when the user has no avatarUrl
80+
// and the errorDrawable is actually the placeholder.
81+
Timber.w("## Location: onLoadFailed")
82+
errorDrawable ?: return
83+
val pinDrawable = createPinDrawable(matrixUser, errorDrawable, isError = true)
84+
callback(pinDrawable)
85+
}
86+
})
9887
}
9988

10089
private fun createPinDrawable(
101-
userItem: MatrixItem.UserItem,
90+
userItem: MatrixItem,
10291
drawable: Drawable,
10392
isError: Boolean,
10493
): Drawable {

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageLocationItem.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLay
3838
import im.vector.app.features.home.room.detail.timeline.style.granularRoundedCorners
3939
import im.vector.app.features.location.MapLoadingErrorView
4040
import im.vector.app.features.location.MapLoadingErrorViewState
41+
import org.matrix.android.sdk.api.util.MatrixItem
4142

4243
abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>(
4344
@LayoutRes layoutId: Int = R.layout.item_timeline_event_base
@@ -47,7 +48,7 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>(
4748
var locationUrl: String? = null
4849

4950
@EpoxyAttribute
50-
var locationUserId: String? = null
51+
var pinMatrixItem: MatrixItem? = null
5152

5253
@EpoxyAttribute
5354
var mapWidth: Int = 0
@@ -103,7 +104,7 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>(
103104
dataSource: DataSource?,
104105
isFirstResource: Boolean
105106
): Boolean {
106-
locationPinProvider?.create(locationUserId) { pinDrawable ->
107+
locationPinProvider?.create(pinMatrixItem) { pinDrawable ->
107108
// we are not using Glide since it does not display it correctly when there is no user photo
108109
holder.staticMapPinImageView.setImageDrawable(pinDrawable)
109110
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLiveLocationItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract class MessageLiveLocationItem : AbsMessageLocationItem<MessageLiveLocat
4949

5050
private fun bindLiveLocationBanner(holder: Holder) {
5151
// TODO in a future PR add check on device id to confirm that is the one that sent the beacon
52-
val isEmitter = currentUserId != null && currentUserId == locationUserId
52+
val isEmitter = currentUserId != null && currentUserId == pinMatrixItem?.id
5353
val messageLayout = attributes.informationData.messageLayout
5454
val viewState = buildViewState(holder, messageLayout, isEmitter)
5555
holder.liveLocationRunningBanner.isVisible = true

0 commit comments

Comments
 (0)