mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Use asset geo location for story location picking
This commit is contained in:
parent
8805c0b7bd
commit
8201e493f3
@ -64,6 +64,7 @@ public final class LocationPickerController: ViewController, AttachmentContainab
|
||||
private let context: AccountContext
|
||||
private let mode: LocationPickerMode
|
||||
private let source: Source
|
||||
let initialLocation: CLLocationCoordinate2D?
|
||||
private let completion: (TelegramMediaMap, Int64?, String?, String?) -> Void
|
||||
private var presentationData: PresentationData
|
||||
private var presentationDataDisposable: Disposable?
|
||||
@ -84,10 +85,11 @@ public final class LocationPickerController: ViewController, AttachmentContainab
|
||||
public var isContainerPanning: () -> Bool = { return false }
|
||||
public var isContainerExpanded: () -> Bool = { return false }
|
||||
|
||||
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, mode: LocationPickerMode, source: Source = .generic, completion: @escaping (TelegramMediaMap, Int64?, String?, String?) -> Void) {
|
||||
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, mode: LocationPickerMode, source: Source = .generic, initialLocation: CLLocationCoordinate2D? = nil, completion: @escaping (TelegramMediaMap, Int64?, String?, String?) -> Void) {
|
||||
self.context = context
|
||||
self.mode = mode
|
||||
self.source = source
|
||||
self.initialLocation = initialLocation
|
||||
self.completion = completion
|
||||
self.presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 }
|
||||
self.updatedPresentationData = updatedPresentationData
|
||||
@ -409,6 +411,7 @@ private final class LocationPickerContext: AttachmentMediaPickerContext {
|
||||
|
||||
public func storyLocationPickerController(
|
||||
context: AccountContext,
|
||||
location: CLLocationCoordinate2D?,
|
||||
completion: @escaping (TelegramMediaMap, Int64?, String?, String?) -> Void
|
||||
) -> ViewController {
|
||||
let presentationData = context.sharedContext.currentPresentationData.with({ $0 }).withUpdated(theme: defaultDarkColorPresentationTheme)
|
||||
@ -417,7 +420,7 @@ public func storyLocationPickerController(
|
||||
return nil
|
||||
})
|
||||
controller.requestController = { _, present in
|
||||
let locationPickerController = LocationPickerController(context: context, updatedPresentationData: updatedPresentationData, mode: .share(peer: nil, selfPeer: nil, hasLiveLocation: false), source: .story, completion: { location, queryId, resultId, address in
|
||||
let locationPickerController = LocationPickerController(context: context, updatedPresentationData: updatedPresentationData, mode: .share(peer: nil, selfPeer: nil, hasLiveLocation: false), source: .story, initialLocation: location, completion: { location, queryId, resultId, address in
|
||||
completion(location, queryId, resultId, address)
|
||||
})
|
||||
present(locationPickerController, locationPickerController.mediaPickerContext)
|
||||
|
@ -449,9 +449,16 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
|
||||
}
|
||||
)
|
||||
|
||||
let venuesLocation: Signal<CLLocation?, NoError>
|
||||
if let initialLocation = controller.initialLocation {
|
||||
venuesLocation = .single(CLLocation(coordinate: initialLocation, altitude: 0.0, horizontalAccuracy: 1.0, verticalAccuracy: 1.0, timestamp: Date()))
|
||||
} else {
|
||||
venuesLocation = throttledUserLocation(userLocation)
|
||||
}
|
||||
|
||||
let venues: Signal<([(TelegramMediaMap, String)], Int64)?, NoError> = .single(nil)
|
||||
|> then(
|
||||
throttledUserLocation(userLocation)
|
||||
venuesLocation
|
||||
|> mapToSignal { location -> Signal<([(TelegramMediaMap, String)], Int64)?, NoError> in
|
||||
if let location = location, location.horizontalAccuracy > 0 {
|
||||
return combineLatest(nearbyVenues(context: context, story: source == .story, latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), personalVenues)
|
||||
@ -573,7 +580,11 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
|
||||
switch strongSelf.mode {
|
||||
case .share:
|
||||
if source == .story {
|
||||
title = "Add My Current Location"
|
||||
if strongSelf.controller?.initialLocation != nil {
|
||||
title = "Add This Location"
|
||||
} else {
|
||||
title = "Add My Current Location"
|
||||
}
|
||||
} else {
|
||||
title = presentationData.strings.Map_SendMyCurrentLocation
|
||||
}
|
||||
@ -635,7 +646,9 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
|
||||
let previousUserLocation = previousUserLocation.swap(userLocation)
|
||||
switch state.selectedLocation {
|
||||
case .none:
|
||||
if let userLocation = userLocation {
|
||||
if let initialLocation = strongSelf.controller?.initialLocation {
|
||||
strongSelf.headerNode.mapNode.setMapCenter(coordinate: initialLocation, animated: false)
|
||||
} else if let userLocation = userLocation {
|
||||
strongSelf.headerNode.mapNode.setMapCenter(coordinate: userLocation.coordinate, isUserLocation: true, animated: previousUserLocation != nil)
|
||||
}
|
||||
strongSelf.headerNode.mapNode.resetAnnotationSelection()
|
||||
@ -848,7 +861,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
|
||||
|
||||
self.locationManager.manager.stopUpdatingHeading()
|
||||
}
|
||||
|
||||
|
||||
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
|
||||
self.headerNode.mapNode.userHeading = CGFloat(newHeading.magneticHeading)
|
||||
}
|
||||
|
@ -2702,7 +2702,11 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
guard let controller = self.controller else {
|
||||
return
|
||||
}
|
||||
let locationController = storyLocationPickerController(context: self.context, completion: { [weak self] location, queryId, resultId, address in
|
||||
var location: CLLocationCoordinate2D?
|
||||
if let subject = self.subject, case let .asset(asset) = subject {
|
||||
location = asset.location?.coordinate
|
||||
}
|
||||
let locationController = storyLocationPickerController(context: self.context, location: location, completion: { [weak self] location, queryId, resultId, address in
|
||||
if let self {
|
||||
let title: String
|
||||
if let venueTitle = location.venue?.title {
|
||||
|
Loading…
x
Reference in New Issue
Block a user