Location view fixes

This commit is contained in:
Ilya Laktyushin 2020-10-28 22:40:51 +04:00
parent 72074f971b
commit 25b7b685ec
7 changed files with 2724 additions and 2644 deletions

View File

@ -5845,8 +5845,9 @@ Any member of this group will be able to see messages in the channel.";
"Location.ProximityNotification.Notify" = "Notify me within %@";
"Location.ProximityNotification.NotifyLong" = "Notify when %1$@ is within %2$@";
"Location.ProximityNotification.AlreadyClose" = "You are already closer than %@";
"Location.ProximityNotification.DistanceKM" = "KM";
"Location.ProximityNotification.DistanceMI" = "MI";
"Location.ProximityNotification.DistanceKM" = "km";
"Location.ProximityNotification.DistanceM" = "m";
"Location.ProximityNotification.DistanceMI" = "mi";
"Location.ProximityTip" = "Alert when %@ is close";
"Location.ProximityGroupTip" = "Alert when any group member is close";

View File

@ -187,6 +187,8 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
private let doneButton: SolidRoundedButtonNode
private var pickerView: TimerPickerView?
private let unitLabelNode: ImmediateTextNode
private let smallUnitLabelNode: ImmediateTextNode
private var containerLayout: (ContainerViewLayout, CGFloat)?
@ -253,11 +255,18 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
self.doneButton = SolidRoundedButtonNode(theme: SolidRoundedButtonTheme(theme: self.presentationData.theme), height: 52.0, cornerRadius: 11.0, gloss: false)
self.doneButton.title = self.presentationData.strings.Conversation_Timer_Send
self.unitLabelNode = ImmediateTextNode()
self.smallUnitLabelNode = ImmediateTextNode()
super.init()
self.backgroundColor = nil
self.isOpaque = false
self.unitLabelNode.attributedText = NSAttributedString(string: self.usesMetricSystem ? self.presentationData.strings.Location_ProximityNotification_DistanceKM : self.presentationData.strings.Location_ProximityNotification_DistanceMI, font: Font.regular(15.0), textColor: textColor)
self.smallUnitLabelNode.attributedText = NSAttributedString(string: self.usesMetricSystem ? self.presentationData.strings.Location_ProximityNotification_DistanceM : "", font: Font.regular(15.0), textColor: textColor)
self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture(_:))))
self.addSubnode(self.dimNode)
@ -274,6 +283,9 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
self.contentContainerNode.addSubnode(self.cancelButton)
self.contentContainerNode.addSubnode(self.doneButton)
self.contentContainerNode.addSubnode(self.unitLabelNode)
self.contentContainerNode.addSubnode(self.smallUnitLabelNode)
self.cancelButton.addTarget(self, action: #selector(self.cancelButtonPressed), forControlEvents: .touchUpInside)
self.doneButton.pressed = { [weak self] in
if let strongSelf = self, let pickerView = strongSelf.pickerView {
@ -282,7 +294,7 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
let largeValue = unitValues[pickerView.selectedRow(inComponent: 0)]
let smallValue = smallUnitValues[pickerView.selectedRow(inComponent: 1)]
var value = largeValue * 1000 + smallValue * 10
if !strongSelf.usesMetricSystem() {
if !strongSelf.usesMetricSystem {
value = Int32(Double(value) * 1.60934)
}
strongSelf.completion?(value)
@ -315,18 +327,21 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
pickerView.delegate = self
pickerView.selectRow(0, inComponent: 0, animated: false)
if self.usesMetricSystem() {
pickerView.selectRow(50, inComponent: 1, animated: false)
if self.usesMetricSystem {
pickerView.selectRow(6, inComponent: 1, animated: false)
} else {
pickerView.selectRow(30, inComponent: 1, animated: false)
pickerView.selectRow(4, inComponent: 1, animated: false)
}
self.contentContainerNode.view.addSubview(pickerView)
self.pickerView = pickerView
self.contentContainerNode.addSubnode(self.unitLabelNode)
self.contentContainerNode.addSubnode(self.smallUnitLabelNode)
self.updateDoneButtonTitle()
}
private func usesMetricSystem() -> Bool {
private var usesMetricSystem: Bool {
let locale = localeWithStrings(self.presentationData.strings)
if locale.identifier.hasSuffix("GB") {
return false
@ -350,7 +365,7 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
let smallValue = smallUnitValues[selectedSmallRow]
var value = largeValue * 1000 + smallValue * 10
if !self.usesMetricSystem() {
if !self.usesMetricSystem {
value = Int32(Double(value) * 1.60934)
}
let distance = stringForDistance(strings: self.presentationData.strings, distance: CLLocationDistance(value))
@ -379,7 +394,7 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
let smallValue = smallUnitValues[pickerView.selectedRow(inComponent: 1)]
var value = largeValue * 1000 + smallValue * 10
if !self.usesMetricSystem() {
if !self.usesMetricSystem {
value = Int32(Double(value) * 1.60934)
}
self.updated?(value)
@ -412,8 +427,19 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
let value = unitValues[row]
string = "\(value)"
} else {
let value = String(format: "%.2d", smallUnitValues[row])
string = ".\(value)"
if self.usesMetricSystem {
let value = String(format: "%d", smallUnitValues[row] * 10)
string = "\(value)"
} else {
let value = smallUnitValues[row]
if value == 0 {
string = ".0"
} else if value == 5 {
string = ".05"
} else {
string = ".\(value / 10)"
}
}
}
return NSAttributedString(string: string, font: font, textColor: self.presentationData.theme.actionSheet.primaryTextColor)
}
@ -442,6 +468,9 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
self.doneButton.updateTheme(SolidRoundedButtonTheme(theme: self.presentationData.theme))
self.updateDoneButtonTitle()
self.unitLabelNode.attributedText = NSAttributedString(string: self.usesMetricSystem ? self.presentationData.strings.Location_ProximityNotification_DistanceKM : self.presentationData.strings.Location_ProximityNotification_DistanceMI, font: Font.regular(15.0), textColor: self.presentationData.theme.actionSheet.primaryTextColor)
self.smallUnitLabelNode.attributedText = NSAttributedString(string: self.usesMetricSystem ? self.presentationData.strings.Location_ProximityNotification_DistanceM : "", font: Font.regular(15.0), textColor: self.presentationData.theme.actionSheet.primaryTextColor)
}
override func didLoad() {
@ -555,8 +584,15 @@ class LocationDistancePickerScreenNode: ViewControllerTracingNode, UIScrollViewD
let textSize = self.textNode.updateLayout(CGSize(width: width, height: titleHeight))
transition.updateFrame(node: self.textNode, frame: CGRect(origin: CGPoint(x: floor((width - textSize.width) / 2.0), y: floor(doneButtonFrame.center.y - textSize.height / 2.0)), size: textSize))
let pickerFrame = CGRect(origin: CGPoint(x: 0.0, y: 54.0), size: CGSize(width: contentFrame.width, height: pickerHeight))
self.pickerView?.frame = pickerFrame
self.pickerView?.frame = CGRect(origin: CGPoint(x: 0.0, y: 54.0), size: CGSize(width: contentFrame.width, height: pickerHeight))
let unitLabelSize = self.unitLabelNode.updateLayout(CGSize(width: width, height: titleHeight))
transition.updateFrame(node: self.unitLabelNode, frame: CGRect(origin: CGPoint(x: floor(pickerFrame.width / 4.0) + 50.0, y: floor(pickerFrame.center.y - unitLabelSize.height / 2.0)), size: unitLabelSize))
let smallUnitLabelSize = self.smallUnitLabelNode.updateLayout(CGSize(width: width, height: titleHeight))
transition.updateFrame(node: self.smallUnitLabelNode, frame: CGRect(origin: CGPoint(x: floor(pickerFrame.width / 4.0 * 3.0) + 50.0, y: floor(pickerFrame.center.y - smallUnitLabelSize.height / 2.0)), size: smallUnitLabelSize))
transition.updateFrame(node: self.contentContainerNode, frame: contentContainerFrame)
}

View File

@ -20,12 +20,14 @@ public class LocationViewParams {
let stopLiveLocation: (MessageId?) -> Void
let openUrl: (String) -> Void
let openPeer: (Peer) -> Void
let showAll: Bool
public init(sendLiveLocation: @escaping (TelegramMediaMap) -> Void, stopLiveLocation: @escaping (MessageId?) -> Void, openUrl: @escaping (String) -> Void, openPeer: @escaping (Peer) -> Void) {
public init(sendLiveLocation: @escaping (TelegramMediaMap) -> Void, stopLiveLocation: @escaping (MessageId?) -> Void, openUrl: @escaping (String) -> Void, openPeer: @escaping (Peer) -> Void, showAll: Bool = false) {
self.sendLiveLocation = sendLiveLocation
self.stopLiveLocation = stopLiveLocation
self.openUrl = openUrl
self.openPeer = openPeer
self.showAll = showAll
}
}
@ -73,6 +75,7 @@ public final class LocationViewController: ViewController {
public var subject: Message
private var presentationData: PresentationData
private var presentationDataDisposable: Disposable?
private var showAll: Bool
private let locationManager = LocationManager()
private var permissionDisposable: Disposable?
@ -84,6 +87,7 @@ public final class LocationViewController: ViewController {
public init(context: AccountContext, subject: Message, params: LocationViewParams) {
self.context = context
self.subject = subject
self.showAll = params.showAll
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
@ -275,7 +279,7 @@ public final class LocationViewController: ViewController {
})
} else {
let _ = (context.account.postbox.loadedPeerWithId(subject.id.peerId)
|> deliverOnMainQueue).start(next: { [weak self] peer in
|> deliverOnMainQueue).start(next: { peer in
let controller = ActionSheetController(presentationData: strongSelf.presentationData)
var title = strongSelf.presentationData.strings.Map_LiveLocationGroupDescription
if let user = peer as? TelegramUser {
@ -359,6 +363,13 @@ public final class LocationViewController: ViewController {
self.displayNode = LocationViewControllerNode(context: self.context, presentationData: self.presentationData, subject: self.subject, interaction: interaction, locationManager: self.locationManager)
self.displayNodeDidLoad()
self.controllerNode.onAnnotationsReady = { [weak self] in
guard let strongSelf = self, strongSelf.showAll else {
return
}
strongSelf.controllerNode.showAll()
}
}
private func updateRightBarButton() {

View File

@ -211,6 +211,9 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
private var listOffset: CGFloat?
private var displayedProximityAlertTooltip = false
var reportedAnnotationsReady = false
var onAnnotationsReady: (() -> Void)?
init(context: AccountContext, presentationData: PresentationData, subject: Message, interaction: LocationViewInteraction, locationManager: LocationManager) {
self.context = context
@ -475,6 +478,11 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
}
if annotations != previousAnnotations {
strongSelf.headerNode.mapNode.annotations = annotations
if !strongSelf.reportedAnnotationsReady {
strongSelf.reportedAnnotationsReady = true
strongSelf.onAnnotationsReady?()
}
}
if let _ = proximityNotification {
@ -593,14 +601,32 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
}
}
var initialized = false
private func dequeueTransition() {
guard let _ = self.validLayout, let transition = self.enqueuedTransitions.first else {
return
}
self.enqueuedTransitions.remove(at: 0)
let scrollToItem: ListViewScrollToItem?
if !self.initialized, transition.insertions.count > 0 {
var index: Int = 0
var offset: CGFloat = 0.0
if transition.insertions.count > 2 {
index = 2
offset = 40.0
} else if transition.insertions.count == 2 {
index = 1
}
scrollToItem = ListViewScrollToItem(index: index, position: .bottom(offset), animated: false, curve: .Default(duration: nil), directionHint: .Up)
self.initialized = true
} else {
scrollToItem = nil
}
let options = ListViewDeleteAndInsertOptions()
self.listNode.transaction(deleteIndices: transition.deletions, insertIndicesAndItems: transition.insertions, updateIndicesAndItems: transition.updates, options: options, updateSizeAndInsets: nil, updateOpaqueState: nil, completion: { _ in
self.listNode.transaction(deleteIndices: transition.deletions, insertIndicesAndItems: transition.insertions, updateIndicesAndItems: transition.updates, options: options, scrollToItem: scrollToItem, updateSizeAndInsets: nil, updateOpaqueState: nil, completion: { _ in
})
}
@ -623,6 +649,11 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
return state
}
var contentOffset: CGFloat = 0.0
if case let .known(offset) = self.listNode.visibleContentOffset() {
contentOffset = offset
}
let panelHeight: CGFloat = 349.0 + layout.intrinsicInsets.bottom
let inset = (layout.size.width - 260.0) / 2.0
let offset = panelHeight / 2.0 + 60.0 + inset + navigationBarHeight / 2.0
@ -630,7 +661,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
let point = CGPoint(x: layout.size.width / 2.0, y: navigationBarHeight + (layout.size.height - navigationBarHeight - panelHeight) / 2.0)
let convertedPoint = self.view.convert(point, to: self.headerNode.mapNode.view)
self.headerNode.mapNode.setMapCenter(coordinate: coordinate, radius: Double(radius), insets: UIEdgeInsets(top: navigationBarHeight, left: inset, bottom: offset, right: inset), offset: convertedPoint.y - self.headerNode.mapNode.frame.height / 2.0, animated: true)
self.headerNode.mapNode.setMapCenter(coordinate: coordinate, radius: Double(radius), insets: UIEdgeInsets(top: navigationBarHeight, left: inset, bottom: offset - contentOffset, right: inset), offset: convertedPoint.y - self.headerNode.mapNode.frame.height / 2.0, animated: true)
}
self.headerNode.mapNode.proximityIndicatorRadius = Double(radius)

View File

@ -73,7 +73,7 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool {
params.context.liveLocationManager?.cancelLiveLocation(peerId: messageId?.peerId ?? params.message.id.peerId)
}, openUrl: params.openUrl, openPeer: { peer in
params.openPeer(peer, .info)
})
}, showAll: params.modal)
let controller = LocationViewController(context: params.context, subject: params.message, params: controllerParams)
controller.navigationPresentation = .modal
params.navigationController?.pushViewController(controller)