Location directions fixes

This commit is contained in:
Ilya Laktyushin
2021-10-24 17:04:06 +04:00
parent 173c31ee5b
commit 3f2689d7d0
4 changed files with 83 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ import ItemListUI
import LocationResources import LocationResources
import AppBundle import AppBundle
import SolidRoundedButtonNode import SolidRoundedButtonNode
import ShimmerEffect
final class LocationInfoListItem: ListViewItem { final class LocationInfoListItem: ListViewItem {
let presentationData: ItemListPresentationData let presentationData: ItemListPresentationData
@@ -80,12 +81,14 @@ final class LocationInfoListItemNode: ListViewItemNode {
private let venueIconNode: TransformImageNode private let venueIconNode: TransformImageNode
private let buttonNode: HighlightableButtonNode private let buttonNode: HighlightableButtonNode
private var placeholderNode: ShimmerEffectNode?
private var drivingButtonNode: SolidRoundedButtonNode? private var drivingButtonNode: SolidRoundedButtonNode?
private var transitButtonNode: SolidRoundedButtonNode? private var transitButtonNode: SolidRoundedButtonNode?
private var walkingButtonNode: SolidRoundedButtonNode? private var walkingButtonNode: SolidRoundedButtonNode?
private var item: LocationInfoListItem? private var item: LocationInfoListItem?
private var layoutParams: ListViewItemLayoutParams? private var layoutParams: ListViewItemLayoutParams?
private var absoluteLocation: (CGRect, CGSize)?
required init() { required init() {
self.backgroundNode = ASDisplayNode() self.backgroundNode = ASDisplayNode()
@@ -305,13 +308,52 @@ final class LocationInfoListItemNode: ListViewItemNode {
let directionsWidth: CGFloat = 93.0 let directionsWidth: CGFloat = 93.0
let directionsSpacing: CGFloat = 8.0 let directionsSpacing: CGFloat = 8.0
if item.drivingTime == nil && item.transitTime == nil && item.walkingTime == nil {
let shimmerNode: ShimmerEffectNode
if let current = strongSelf.placeholderNode {
shimmerNode = current
} else {
shimmerNode = ShimmerEffectNode()
strongSelf.placeholderNode = shimmerNode
strongSelf.addSubnode(shimmerNode)
}
shimmerNode.frame = CGRect(origin: CGPoint(x: leftInset, y: subtitleFrame.maxY + 12.0), size: CGSize(width: contentSize.width - leftInset, height: 32.0))
if let (rect, size) = strongSelf.absoluteLocation {
shimmerNode.updateAbsoluteRect(rect, within: size)
}
var shapes: [ShimmerEffectNode.Shape] = []
shapes.append(.roundedRectLine(startPoint: CGPoint(x: 0.0, y: 0.0), width: directionsWidth, diameter: 32.0))
shapes.append(.roundedRectLine(startPoint: CGPoint(x: directionsWidth + directionsSpacing, y: 0.0), width: directionsWidth, diameter: 32.0))
shapes.append(.roundedRectLine(startPoint: CGPoint(x: directionsWidth + directionsSpacing + directionsWidth + directionsSpacing, y: 0.0), width: directionsWidth, diameter: 32.0))
shimmerNode.update(backgroundColor: item.presentationData.theme.list.itemBlocksBackgroundColor, foregroundColor: item.presentationData.theme.list.mediaPlaceholderColor, shimmeringColor: item.presentationData.theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), shapes: shapes, size: shimmerNode.frame.size)
} else if let shimmerNode = strongSelf.placeholderNode {
strongSelf.placeholderNode = nil
shimmerNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak shimmerNode] _ in
shimmerNode?.removeFromSupernode()
})
}
let drivingHeight = strongSelf.drivingButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0 let drivingHeight = strongSelf.drivingButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0
let transitHeight = strongSelf.transitButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0 let transitHeight = strongSelf.transitButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0
let walkingHeight = strongSelf.walkingButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0 let walkingHeight = strongSelf.walkingButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0
strongSelf.drivingButtonNode?.frame = CGRect(origin: CGPoint(x: leftInset, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: drivingHeight)) var buttonOrigin = leftInset
strongSelf.transitButtonNode?.frame = CGRect(origin: CGPoint(x: leftInset + directionsWidth + directionsSpacing, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: transitHeight)) strongSelf.drivingButtonNode?.frame = CGRect(origin: CGPoint(x: buttonOrigin, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: drivingHeight))
strongSelf.walkingButtonNode?.frame = CGRect(origin: CGPoint(x: leftInset + directionsWidth + directionsSpacing + directionsWidth + directionsSpacing, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: walkingHeight))
if item.drivingTime != nil {
buttonOrigin += directionsWidth + directionsSpacing
}
strongSelf.transitButtonNode?.frame = CGRect(origin: CGPoint(x: buttonOrigin, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: transitHeight))
if item.transitTime != nil {
buttonOrigin += directionsWidth + directionsSpacing
}
strongSelf.walkingButtonNode?.frame = CGRect(origin: CGPoint(x: buttonOrigin, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: walkingHeight))
strongSelf.buttonNode.frame = CGRect(x: 0.0, y: 0.0, width: contentSize.width, height: 72.0) strongSelf.buttonNode.frame = CGRect(x: 0.0, y: 0.0, width: contentSize.width, height: 72.0)
strongSelf.backgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: contentSize.width, height: contentSize.height)) strongSelf.backgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: contentSize.width, height: contentSize.height))
@@ -332,4 +374,13 @@ final class LocationInfoListItemNode: ListViewItemNode {
@objc private func buttonPressed() { @objc private func buttonPressed() {
self.item?.action() self.item?.action()
} }
override public func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
var rect = rect
rect.origin.y += self.insets.top
self.absoluteLocation = (rect, containerSize)
if let shimmerNode = self.placeholderNode {
shimmerNode.updateAbsoluteRect(rect, within: containerSize)
}
}
} }

View File

@@ -359,9 +359,20 @@ final class LocationLiveListItemNode: ListViewItemNode {
let transitHeight = strongSelf.transitButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0 let transitHeight = strongSelf.transitButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0
let walkingHeight = strongSelf.walkingButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0 let walkingHeight = strongSelf.walkingButtonNode?.updateLayout(width: directionsWidth, transition: .immediate) ?? 0.0
strongSelf.drivingButtonNode?.frame = CGRect(origin: CGPoint(x: leftInset, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: drivingHeight)) var buttonOrigin = leftInset
strongSelf.transitButtonNode?.frame = CGRect(origin: CGPoint(x: leftInset + directionsWidth + directionsSpacing, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: transitHeight)) strongSelf.drivingButtonNode?.frame = CGRect(origin: CGPoint(x: buttonOrigin, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: drivingHeight))
strongSelf.walkingButtonNode?.frame = CGRect(origin: CGPoint(x: leftInset + directionsWidth + directionsSpacing + directionsWidth + directionsSpacing, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: walkingHeight))
if item.drivingTime != nil {
buttonOrigin += directionsWidth + directionsSpacing
}
strongSelf.transitButtonNode?.frame = CGRect(origin: CGPoint(x: buttonOrigin, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: transitHeight))
if item.transitTime != nil {
buttonOrigin += directionsWidth + directionsSpacing
}
strongSelf.walkingButtonNode?.frame = CGRect(origin: CGPoint(x: buttonOrigin, y: subtitleFrame.maxY + 12.0), size: CGSize(width: directionsWidth, height: walkingHeight))
} }
}) })
}) })

View File

@@ -80,7 +80,7 @@ func stringForEstimatedDuration(strings: PresentationStrings, time: Double, form
let string: String let string: String
if hours >= 24 { if hours >= 24 {
string = strings.Map_ETADays(days) string = strings.Map_ETADays(days)
} else if hours > 1 { } else if hours > 0 {
if hours == 1 && minutes == 0 { if hours == 1 && minutes == 0 {
string = strings.Map_ETAHours(1) string = strings.Map_ETAHours(1)
} else { } else {

View File

@@ -455,13 +455,23 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
var transitTime: Double? var transitTime: Double?
var walkingTime: Double? var walkingTime: Double?
if !isLocationView && message.author?.id != context.account.peerId { if !isLocationView && message.author?.id != context.account.peerId {
let signal = combineLatest(queue: Queue.mainQueue(), getExpectedTravelTime(coordinate: location.coordinate, transportType: .automobile), getExpectedTravelTime(coordinate: location.coordinate, transportType: .transit), getExpectedTravelTime(coordinate: location.coordinate, transportType: .walking))
|> mapToSignal { drivingTime, transitTime, walkingTime -> Signal<(Double?, Double?, Double?), NoError> in
if drivingTime != nil && transitTime != nil && walkingTime != nil {
return .single((drivingTime, transitTime, walkingTime))
} else {
return .single((drivingTime, transitTime, walkingTime))
|> delay(0.3, queue: Queue.mainQueue())
}
}
if let (previousTimestamp, maybeDrivingTime, maybeTransitTime, maybeWalkingTime) = travelTimes[message.id] { if let (previousTimestamp, maybeDrivingTime, maybeTransitTime, maybeWalkingTime) = travelTimes[message.id] {
drivingTime = maybeDrivingTime drivingTime = maybeDrivingTime
transitTime = maybeTransitTime transitTime = maybeTransitTime
walkingTime = maybeWalkingTime walkingTime = maybeWalkingTime
if timestamp > previousTimestamp + 60.0 { if timestamp > previousTimestamp + 60.0 {
strongSelf.travelDisposables.add(combineLatest(queue: Queue.mainQueue(), getExpectedTravelTime(coordinate: location.coordinate, transportType: .automobile), getExpectedTravelTime(coordinate: location.coordinate, transportType: .transit), getExpectedTravelTime(coordinate: location.coordinate, transportType: .walking)).start(next: { [weak self] drivingTime, transitTime, walkingTime in strongSelf.travelDisposables.add(signal.start(next: { [weak self] drivingTime, transitTime, walkingTime in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
@@ -472,7 +482,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
})) }))
} }
} else { } else {
strongSelf.travelDisposables.add(combineLatest(queue: Queue.mainQueue(), getExpectedTravelTime(coordinate: location.coordinate, transportType: .automobile), getExpectedTravelTime(coordinate: location.coordinate, transportType: .transit), getExpectedTravelTime(coordinate: location.coordinate, transportType: .walking)).start(next: { [weak self] drivingTime, transitTime, walkingTime in strongSelf.travelDisposables.add(signal.start(next: { [weak self] drivingTime, transitTime, walkingTime in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }