Skip to content
Snippets Groups Projects
Commit c99d257b authored by Raphaël Brulé's avatar Raphaël Brulé
Browse files

location sharing: ui improvements

Each location sharing bubble shows both users of
the conversation if both are sharing location at
the same time.

Change-Id: Iea6fc4ae790b1c786434a634cd506990f4bbbdc5
parent c1e7b37f
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,8 @@ import RxCocoa ...@@ -24,6 +24,8 @@ import RxCocoa
class MessageCellLocationSharing: MessageCell { class MessageCellLocationSharing: MessageCell {
typealias MarkerAndComponentObject = (marker: MaplyScreenMarker, componentObject: MaplyComponentObject?)
private static let osmCopyrightAndLicenseURL = "https://www.openstreetmap.org/copyright" private static let osmCopyrightAndLicenseURL = "https://www.openstreetmap.org/copyright"
private static let remoteTileSourceBaseUrl = MessageCellLocationSharing.getBaseURL() private static let remoteTileSourceBaseUrl = MessageCellLocationSharing.getBaseURL()
...@@ -159,9 +161,11 @@ extension MessageCellLocationSharing { ...@@ -159,9 +161,11 @@ extension MessageCellLocationSharing {
imageData: Data?, imageData: Data?,
username: String?, username: String?,
marker: MaplyScreenMarker, marker: MaplyScreenMarker,
markerDump: MaplyComponentObject?) -> MaplyComponentObject? { markerDump: MaplyComponentObject?,
tryToAnimateToMarker: Bool = true) -> MaplyComponentObject? {
// only the first time // only the first time
if markerDump != nil { if markerDump == nil {
marker.layoutImportance = MAXFLOAT
if let imageData = imageData, let circledImage = UIImage(data: imageData)?.circleMasked { if let imageData = imageData, let circledImage = UIImage(data: imageData)?.circleMasked {
marker.image = circledImage marker.image = circledImage
} else { } else {
...@@ -183,7 +187,7 @@ extension MessageCellLocationSharing { ...@@ -183,7 +187,7 @@ extension MessageCellLocationSharing {
} }
dumpToReturn = self.maplyViewController!.addScreenMarkers([marker], desc: nil) dumpToReturn = self.maplyViewController!.addScreenMarkers([marker], desc: nil)
if !locationTapped.value.1 { if tryToAnimateToMarker && !locationTapped.value.1 {
mapViewC.animate(toPosition: maplyCoordonate, time: 0.1) mapViewC.animate(toPosition: maplyCoordonate, time: 0.1)
} }
} }
......
...@@ -23,8 +23,10 @@ import Reusable ...@@ -23,8 +23,10 @@ import Reusable
class MessageCellLocationSharingReceived: MessageCellLocationSharing { class MessageCellLocationSharingReceived: MessageCellLocationSharing {
private var myContactsLocationMarker = MaplyScreenMarker() /// Primary location
private var markerComponentObject: MaplyComponentObject? private var myContactsLocation: MarkerAndComponentObject = (marker: MaplyScreenMarker(), componentObject: nil)
/// Secondary location
private var myLocation: MarkerAndComponentObject = (marker: MaplyScreenMarker(), componentObject: nil)
@IBOutlet weak var receivedBubbleLeading: NSLayoutConstraint! @IBOutlet weak var receivedBubbleLeading: NSLayoutConstraint!
@IBOutlet weak var receivedBubbleTrailling: NSLayoutConstraint! @IBOutlet weak var receivedBubbleTrailling: NSLayoutConstraint!
...@@ -32,15 +34,36 @@ class MessageCellLocationSharingReceived: MessageCellLocationSharing { ...@@ -32,15 +34,36 @@ class MessageCellLocationSharingReceived: MessageCellLocationSharing {
override func configureFromItem(_ conversationViewModel: ConversationViewModel, _ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) { override func configureFromItem(_ conversationViewModel: ConversationViewModel, _ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) {
super.configureFromItem(conversationViewModel, items, cellForRowAt: indexPath) super.configureFromItem(conversationViewModel, items, cellForRowAt: indexPath)
// Primary location
conversationViewModel.myContactsLocation conversationViewModel.myContactsLocation
.subscribe(onNext: { [weak self, weak conversationViewModel] location in .subscribe(onNext: { [weak self, weak conversationViewModel] location in
guard let self = self, let location = location else { return } guard let self = self, let location = location else { return }
self.markerComponentObject = self.updateLocationAndMarker(location: location, self.myContactsLocation.componentObject = self.updateLocationAndMarker(location: location,
imageData: conversationViewModel?.profileImageData.value, imageData: conversationViewModel?.profileImageData.value,
username: conversationViewModel?.userName.value, username: conversationViewModel?.userName.value,
marker: self.myContactsLocationMarker, marker: self.myContactsLocation.marker,
markerDump: self.markerComponentObject) markerDump: self.myContactsLocation.componentObject)
})
.disposed(by: self.disposeBag)
// Secondary location
conversationViewModel.myLocation
.subscribe(onNext: { [weak self, weak conversationViewModel] location in
guard let self = self else { return }
if let location = location?.coordinate {
self.myLocation.componentObject = self.updateLocationAndMarker(location: location,
imageData: conversationViewModel?.myOwnProfileImageData,
username: conversationViewModel?.userName.value,
marker: self.myLocation.marker,
markerDump: self.myLocation.componentObject,
tryToAnimateToMarker: false)
} else if let componentObject = self.myLocation.componentObject,
let maplyViewController = self.maplyViewController {
maplyViewController.remove(componentObject)
self.myLocation.componentObject = nil
}
}) })
.disposed(by: self.disposeBag) .disposed(by: self.disposeBag)
} }
......
...@@ -24,8 +24,10 @@ import RxCocoa ...@@ -24,8 +24,10 @@ import RxCocoa
class MessageCellLocationSharingSent: MessageCellLocationSharing { class MessageCellLocationSharingSent: MessageCellLocationSharing {
private var myLocationMarker = MaplyScreenMarker() /// Primary location
private var markerComponentObject: MaplyComponentObject? private var myLocation: MarkerAndComponentObject = (marker: MaplyScreenMarker(), componentObject: nil)
/// Secondary location
private var myContactsLocation: MarkerAndComponentObject = (marker: MaplyScreenMarker(), componentObject: nil)
@IBOutlet weak var sentBubbleLeading: NSLayoutConstraint! @IBOutlet weak var sentBubbleLeading: NSLayoutConstraint!
...@@ -37,15 +39,36 @@ class MessageCellLocationSharingSent: MessageCellLocationSharing { ...@@ -37,15 +39,36 @@ class MessageCellLocationSharingSent: MessageCellLocationSharing {
override func configureFromItem(_ conversationViewModel: ConversationViewModel, _ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) { override func configureFromItem(_ conversationViewModel: ConversationViewModel, _ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) {
super.configureFromItem(conversationViewModel, items, cellForRowAt: indexPath) super.configureFromItem(conversationViewModel, items, cellForRowAt: indexPath)
// Primary location
conversationViewModel.myLocation conversationViewModel.myLocation
.subscribe(onNext: { [weak self, weak conversationViewModel] location in .subscribe(onNext: { [weak self, weak conversationViewModel] location in
guard let self = self, let location = location?.coordinate else { return } guard let self = self, let location = location?.coordinate else { return }
self.markerComponentObject = self.updateLocationAndMarker(location: location, self.myLocation.componentObject = self.updateLocationAndMarker(location: location,
imageData: conversationViewModel?.myOwnProfileImageData, imageData: conversationViewModel?.myOwnProfileImageData,
username: conversationViewModel?.userName.value, username: conversationViewModel?.userName.value,
marker: self.myLocationMarker, marker: self.myLocation.marker,
markerDump: self.markerComponentObject) markerDump: self.myLocation.componentObject)
})
.disposed(by: self.disposeBag)
// Secondary location
conversationViewModel.myContactsLocation
.subscribe(onNext: { [weak self, weak conversationViewModel] location in
guard let self = self else { return }
if let location = location {
self.myContactsLocation.componentObject = self.updateLocationAndMarker(location: location,
imageData: conversationViewModel?.profileImageData.value,
username: conversationViewModel?.userName.value,
marker: self.myContactsLocation.marker,
markerDump: self.myContactsLocation.componentObject,
tryToAnimateToMarker: false)
} else if let componentObject = self.myContactsLocation.componentObject,
let maplyViewController = self.maplyViewController {
maplyViewController.remove(componentObject)
self.myContactsLocation.componentObject = nil
}
}) })
.disposed(by: self.disposeBag) .disposed(by: self.disposeBag)
...@@ -61,7 +84,7 @@ class MessageCellLocationSharingSent: MessageCellLocationSharing { ...@@ -61,7 +84,7 @@ class MessageCellLocationSharingSent: MessageCellLocationSharing {
override func myPositionButtonAction(sender: UIButton!) { override func myPositionButtonAction(sender: UIButton!) {
if let mapViewC = self.maplyViewController as? MaplyViewController { if let mapViewC = self.maplyViewController as? MaplyViewController {
mapViewC.animate(toPosition: self.myLocationMarker.loc, time: 0.5) mapViewC.animate(toPosition: self.myLocation.marker.loc, time: 0.5)
} }
} }
......
...@@ -111,7 +111,8 @@ class ConversationViewModel: Stateable, ViewModel { ...@@ -111,7 +111,8 @@ class ConversationViewModel: Stateable, ViewModel {
self.locationSharingService self.locationSharingService
.peerUriAndLocationReceived .peerUriAndLocationReceived
.subscribe(onNext: { [weak self] tuple in .subscribe(onNext: { [weak self] tuple in
guard let self = self, let peerUri = tuple.0, let coordinates = tuple.1, let conversation = self.conversation else { return } guard let self = self, let peerUri = tuple.0, let conversation = self.conversation else { return }
let coordinates = tuple.1
if peerUri == conversation.value.participantUri { if peerUri == conversation.value.participantUri {
self.myContactsLocation.onNext(coordinates) self.myContactsLocation.onNext(coordinates)
} }
......
...@@ -250,6 +250,7 @@ extension LocationSharingService { ...@@ -250,6 +250,7 @@ extension LocationSharingService {
if self.outgoingInstances.isEmpty { if self.outgoingInstances.isEmpty {
self.locationManager.stopUpdatingLocation() self.locationManager.stopUpdatingLocation()
self.currentLocation.accept(nil)
} }
self.triggerDeleteLocation(accountId: accountId, peerUri: contactUri, incoming: false, shouldRefreshConversations: true) self.triggerDeleteLocation(accountId: accountId, peerUri: contactUri, incoming: false, shouldRefreshConversations: true)
...@@ -304,6 +305,8 @@ extension LocationSharingService { ...@@ -304,6 +305,8 @@ extension LocationSharingService {
} }
func stopReceivingLocation(accountId: String, contactUri: String) { func stopReceivingLocation(accountId: String, contactUri: String) {
self.peerUriAndLocationReceived.accept((contactUri, nil))
self.triggerDeleteLocation(accountId: accountId, peerUri: contactUri, incoming: true, shouldRefreshConversations: true) self.triggerDeleteLocation(accountId: accountId, peerUri: contactUri, incoming: true, shouldRefreshConversations: true)
_ = self.incomingInstances.remove(accountId, contactUri) _ = self.incomingInstances.remove(accountId, contactUri)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment