6077: Implement SDK for live sharing timeline cell

This commit is contained in:
MaximeE 2022-04-27 16:21:42 +02:00
parent 168e141586
commit 8004aecf06
4 changed files with 88 additions and 51 deletions

View file

@ -427,6 +427,6 @@ final class BuildSettings: NSObject {
}
// Do not enable live location sharing atm
return false
return true
}
}

View file

@ -168,8 +168,8 @@ NSString *const URLPreviewDidUpdateNotification = @"URLPreviewDidUpdateNotificat
self.collapsed = NO;
[self updateBeaconInfoSummaryWithEventId:event.eventId];
}
break;
}
case MXEventTypeCustom:
{
if ([event.type isEqualToString:kWidgetMatrixEventTypeString]

View file

@ -25,7 +25,7 @@ protocol RoomTimelineLocationViewDelegate: AnyObject {
}
struct RoomTimelineLocationViewData {
let location: CLLocationCoordinate2D
let location: CLLocationCoordinate2D?
let userAvatarData: AvatarViewData?
let mapStyleURL: URL
}
@ -162,11 +162,12 @@ class RoomTimelineLocationView: UIView, NibLoadable, Themable, MGLMapViewDelegat
// MARK: - Private
private func displayLocation(_ location: CLLocationCoordinate2D,
private func displayLocation(_ location: CLLocationCoordinate2D?,
userAvatarData: AvatarViewData? = nil,
mapStyleURL: URL,
bannerViewData: LiveLocationBannerViewData? = nil) {
if let location = location {
mapView.styleURL = mapStyleURL
annotationView = LocationMarkerView.loadFromNib()
@ -185,6 +186,9 @@ class RoomTimelineLocationView: UIView, NibLoadable, Themable, MGLMapViewDelegat
let pointAnnotation = MGLPointAnnotation()
pointAnnotation.coordinate = location
mapView.addAnnotation(pointAnnotation)
} else {
mapView.isHidden = true
}
// Configure live location banner
guard let bannerViewData = bannerViewData else {

View file

@ -26,18 +26,26 @@ class LocationPlainCell: SizableBaseRoomCell, RoomCellReactionsDisplayable, Room
super.render(cellData)
guard #available(iOS 14.0, *),
let bubbleData = cellData as? RoomBubbleCellData,
let event = bubbleData.events.last
let bubbleData = cellData as? RoomBubbleCellData
else {
return
}
self.event = event
locationView.update(theme: ThemeService.shared().theme)
// Comment this line and uncomment next one to test UI of live location tile
if bubbleData.cellDataTag == .location,
let event = bubbleData.events.last {
self.event = event
renderStaticLocation(event)
// renderLiveLocation(event)
} else if bubbleData.cellDataTag == .liveLocation,
let beaconInfoSummary = bubbleData.beaconInfoSummary {
if bubbleData.mxSession.myUserId == beaconInfoSummary.userId {
renderOutgoingLiveLocation(beaconInfoSummary)
} else if bubbleData.senderId == beaconInfoSummary.userId {
renderIncomingLiveLocation(beaconInfoSummary)
}
}
}
private func renderStaticLocation(_ event: MXEvent) {
@ -66,31 +74,56 @@ class LocationPlainCell: SizableBaseRoomCell, RoomCellReactionsDisplayable, Room
locationView.displayStaticLocation(with: RoomTimelineLocationViewData(location: location, userAvatarData: avatarViewData, mapStyleURL: mapStyleURL))
}
private func renderLiveLocation(_ event: MXEvent) {
// TODO: - Render live location cell when live location event is handled
// This code is only for testing live location cell
// Will be completed when the live location event is handled
guard let locationContent = event.location else {
return
}
locationView.locationDescription = locationContent.locationDescription
let location = CLLocationCoordinate2D(latitude: locationContent.latitude, longitude: locationContent.longitude)
let mapStyleURL = bubbleData.mxSession.vc_homeserverConfiguration().tileServer.mapStyleURL
private func renderIncomingLiveLocation(_ beaconInfoSummary: MXBeaconInfoSummaryProtocol) {
let liveLocationStatus: IncomingLiveLocationSharingStatus
var location: CLLocationCoordinate2D?
let avatarViewData = AvatarViewData(matrixItemId: bubbleData.senderId,
displayName: bubbleData.senderDisplayName,
avatarUrl: bubbleData.senderAvatarUrl,
mediaManager: bubbleData.mxSession.mediaManager,
fallbackImage: .matrixItem(bubbleData.senderId, bubbleData.senderDisplayName))
let futurDateTimeInterval = Date(timeIntervalSinceNow: 3734).timeIntervalSince1970 * 1000
let mapStyleURL = bubbleData.mxSession.vc_homeserverConfiguration().tileServer.mapStyleURL
if beaconInfoSummary.lastBeacon == nil {
liveLocationStatus = .starting
} else if beaconInfoSummary.hasStopped || beaconInfoSummary.hasExpired {
liveLocationStatus = .stopped
} else {
liveLocationStatus = .started(TimeInterval(beaconInfoSummary.expiryTimestamp))
}
if let mxLocation = beaconInfoSummary.lastBeacon?.location {
location = CLLocationCoordinate2D(latitude: mxLocation.latitude, longitude: mxLocation.longitude)
}
locationView.displayLiveLocation(with: RoomTimelineLocationViewData(location: location, userAvatarData: avatarViewData, mapStyleURL: mapStyleURL),
liveLocationViewState: .outgoing(.started(futurDateTimeInterval)))
liveLocationViewState: .incoming(liveLocationStatus))
}
private func renderOutgoingLiveLocation(_ beaconInfoSummary: MXBeaconInfoSummaryProtocol) {
let liveLocationStatus: OutgoingLiveLocationSharingStatus
var location: CLLocationCoordinate2D?
let avatarViewData = AvatarViewData(matrixItemId: bubbleData.senderId,
displayName: bubbleData.senderDisplayName,
avatarUrl: bubbleData.senderAvatarUrl,
mediaManager: bubbleData.mxSession.mediaManager,
fallbackImage: .matrixItem(bubbleData.senderId, bubbleData.senderDisplayName))
let mapStyleURL = bubbleData.mxSession.vc_homeserverConfiguration().tileServer.mapStyleURL
if beaconInfoSummary.lastBeacon == nil {
liveLocationStatus = .starting
} else if beaconInfoSummary.hasStopped || beaconInfoSummary.hasExpired {
liveLocationStatus = .stopped
} else {
liveLocationStatus = .started(TimeInterval(beaconInfoSummary.expiryTimestamp))
}
if let mxLocation = beaconInfoSummary.lastBeacon?.location {
location = CLLocationCoordinate2D(latitude: mxLocation.latitude, longitude: mxLocation.longitude)
}
locationView.displayLiveLocation(with: RoomTimelineLocationViewData(location: location, userAvatarData: avatarViewData, mapStyleURL: mapStyleURL),
liveLocationViewState: .outgoing(liveLocationStatus))
}
override func setupViews() {