Skip to content

Commit 9ef235f

Browse files
authored
Merge pull request #5479 from vector-im/feature/mna/PSF-735-pinned-location
#5417: Pinned location sharing
2 parents a7639f4 + b72c87d commit 9ef235f

File tree

26 files changed

+540
-67
lines changed

26 files changed

+540
-67
lines changed

changelog.d/5417.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ability to pin a location on map for sharing

library/ui-styles/src/main/res/values/dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@
6464

6565
<!-- Location sharing -->
6666
<dimen name="location_sharing_option_default_padding">10dp</dimen>
67+
<dimen name="location_sharing_locate_button_margin_vertical">16dp</dimen>
68+
<dimen name="location_sharing_locate_button_margin_horizontal">12dp</dimen>
69+
<dimen name="location_sharing_compass_button_margin_horizontal">8dp</dimen>
6770
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<declare-styleable name="MapTilerMapView">
5+
<attr name="showLocateButton" format="boolean" />
6+
</declare-styleable>
7+
8+
</resources>

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationAsset.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ import com.squareup.moshi.JsonClass
2121

2222
@JsonClass(generateAdapter = true)
2323
data class LocationAsset(
24-
@Json(name = "type") val type: LocationAssetType? = null
24+
@Json(name = "type") val type: String? = null
2525
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/LocationAssetType.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@
1616

1717
package org.matrix.android.sdk.api.session.room.model.message
1818

19-
import com.squareup.moshi.Json
20-
import com.squareup.moshi.JsonClass
19+
/**
20+
* Define what particular asset is being referred to.
21+
* We don't use enum type since it is not limited to a specific set of values.
22+
* The way this type should be interpreted in client side is described in
23+
* [MSC3488](https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md)
24+
*/
25+
object LocationAssetType {
26+
/**
27+
* Used for user location sharing.
28+
**/
29+
const val SELF = "m.self"
2130

22-
@JsonClass(generateAdapter = false)
23-
enum class LocationAssetType {
24-
@Json(name = "m.self")
25-
SELF
31+
/**
32+
* Used for pin drop location sharing.
33+
**/
34+
const val PIN = "m.pin"
2635
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageLocationContent.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ data class MessageLocationContent(
4242
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
4343
@Json(name = "m.new_content") override val newContent: Content? = null,
4444
/**
45-
* See https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md
45+
* See [MSC3488](https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md)
4646
*/
4747
@Json(name = "org.matrix.msc3488.location") val unstableLocationInfo: LocationInfo? = null,
4848
@Json(name = "m.location") val locationInfo: LocationInfo? = null,
@@ -54,10 +54,11 @@ data class MessageLocationContent(
5454
@Json(name = "org.matrix.msc1767.text") val unstableText: String? = null,
5555
@Json(name = "m.text") val text: String? = null,
5656
/**
57-
* m.asset defines a generic asset that can be used for location tracking but also in other places like
57+
* Defines a generic asset that can be used for location tracking but also in other places like
5858
* inventories, geofencing, checkins/checkouts etc.
5959
* It should contain a mandatory namespaced type key defining what particular asset is being referred to.
6060
* For the purposes of user location tracking m.self should be used in order to avoid duplicating the mxid.
61+
* See [MSC3488](https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md)
6162
*/
6263
@Json(name = "org.matrix.msc3488.asset") val unstableLocationAsset: LocationAsset? = null,
6364
@Json(name = "m.asset") val locationAsset: LocationAsset? = null

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/SendService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ interface SendService {
142142
* @param latitude required latitude of the location
143143
* @param longitude required longitude of the location
144144
* @param uncertainty Accuracy of the location in meters
145+
* @param isUserLocation indicates whether the location data corresponds to the user location or not
145146
*/
146-
fun sendLocation(latitude: Double, longitude: Double, uncertainty: Double?): Cancelable
147+
fun sendLocation(latitude: Double, longitude: Double, uncertainty: Double?, isUserLocation: Boolean): Cancelable
147148

148149
/**
149150
* Remove this failed message from the timeline

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ internal class DefaultSendService @AssistedInject constructor(
128128
.let { sendEvent(it) }
129129
}
130130

131-
override fun sendLocation(latitude: Double, longitude: Double, uncertainty: Double?): Cancelable {
132-
return localEchoEventFactory.createLocationEvent(roomId, latitude, longitude, uncertainty)
131+
override fun sendLocation(latitude: Double, longitude: Double, uncertainty: Double?, isUserLocation: Boolean): Cancelable {
132+
return localEchoEventFactory.createLocationEvent(roomId, latitude, longitude, uncertainty, isUserLocation)
133133
.also { createLocalEcho(it) }
134134
.let { sendEvent(it) }
135135
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,15 @@ internal class LocalEchoEventFactory @Inject constructor(
227227
fun createLocationEvent(roomId: String,
228228
latitude: Double,
229229
longitude: Double,
230-
uncertainty: Double?): Event {
230+
uncertainty: Double?,
231+
isUserLocation: Boolean): Event {
231232
val geoUri = buildGeoUri(latitude, longitude, uncertainty)
233+
val assetType = if (isUserLocation) LocationAssetType.SELF else LocationAssetType.PIN
232234
val content = MessageLocationContent(
233235
geoUri = geoUri,
234236
body = geoUri,
235237
unstableLocationInfo = LocationInfo(geoUri = geoUri, description = geoUri),
236-
unstableLocationAsset = LocationAsset(type = LocationAssetType.SELF),
238+
unstableLocationAsset = LocationAsset(type = assetType),
237239
unstableTs = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()),
238240
unstableText = geoUri
239241
)

vector/src/main/java/im/vector/app/features/location/LocationPreviewFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class LocationPreviewFragment @Inject constructor(
123123
views.mapView.render(
124124
MapState(
125125
zoomOnlyOnce = true,
126-
pinLocationData = location,
126+
userLocationData = location,
127127
pinId = args.locationOwnerId ?: DEFAULT_PIN_ID,
128128
pinDrawable = pinDrawable
129129
)

0 commit comments

Comments
 (0)