Add attribution for Google Places search provider and pass place id when opening Google Maps

This commit is contained in:
Ilya Laktyushin 2020-07-28 16:57:06 +03:00
parent 95b4d581cd
commit 3fbb7bf303
6 changed files with 65 additions and 17 deletions

View File

@ -8,11 +8,18 @@ import TelegramPresentationData
import ItemListUI
import AppBundle
enum LocationAttribution: Equatable {
case foursquare
case google
}
class LocationAttributionItem: ListViewItem {
let presentationData: ItemListPresentationData
let attribution: LocationAttribution
public init(presentationData: ItemListPresentationData) {
public init(presentationData: ItemListPresentationData, attribution: LocationAttribution) {
self.presentationData = presentationData
self.attribution = attribution
}
public func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
@ -93,11 +100,20 @@ private class LocationAttributionItemNode: ListViewItemNode {
strongSelf.layoutParams = params
if let _ = updatedTheme {
switch item.attribution {
case .foursquare:
strongSelf.imageNode.image = generateTintedImage(image: UIImage(bundleImageName: "Location/FoursquareAttribution"), color: item.presentationData.theme.list.itemSecondaryTextColor)
case .google:
if item.presentationData.theme.overallDarkAppearance {
strongSelf.imageNode.image = generateTintedImage(image: UIImage(bundleImageName: "Location/GoogleAttribution"), color: item.presentationData.theme.list.itemSecondaryTextColor)
} else {
strongSelf.imageNode.image = UIImage(bundleImageName: "Location/GoogleAttribution")
}
}
}
if let image = strongSelf.imageNode.image {
strongSelf.imageNode.frame = CGRect(x: floor((params.width - image.size.width) / 2.0), y: 0.0, width: image.size.width, height: image.size.height)
strongSelf.imageNode.frame = CGRect(x: floor((params.width - image.size.width) / 2.0), y: floor((contentSize.height - image.size.height) / 2.0), width: image.size.width, height: image.size.height)
}
}
})

View File

@ -40,7 +40,7 @@ private enum LocationPickerEntry: Comparable, Identifiable {
case liveLocation(PresentationTheme, String, String, CLLocationCoordinate2D?)
case header(PresentationTheme, String)
case venue(PresentationTheme, TelegramMediaMap, Int)
case attribution(PresentationTheme)
case attribution(PresentationTheme, LocationAttribution)
var stableId: LocationPickerEntryId {
switch self {
@ -83,8 +83,8 @@ private enum LocationPickerEntry: Comparable, Identifiable {
} else {
return false
}
case let .attribution(lhsTheme):
if case let .attribution(rhsTheme) = rhs, lhsTheme === rhsTheme {
case let .attribution(lhsTheme, lhsAttribution):
if case let .attribution(rhsTheme, rhsAttribution) = rhs, lhsTheme === rhsTheme, lhsAttribution == rhsAttribution {
return true
} else {
return false
@ -131,7 +131,7 @@ private enum LocationPickerEntry: Comparable, Identifiable {
func item(account: Account, presentationData: PresentationData, interaction: LocationPickerInteraction?) -> ListViewItem {
switch self {
case let .location(theme, title, subtitle, venue, coordinate):
case let .location(_, title, subtitle, venue, coordinate):
let icon: LocationActionListItemIcon
if let venue = venue {
icon = .venue(venue)
@ -147,23 +147,23 @@ private enum LocationPickerEntry: Comparable, Identifiable {
}, highlighted: { highlighted in
interaction?.updateSendActionHighlight(highlighted)
})
case let .liveLocation(theme, title, subtitle, coordinate):
case let .liveLocation(_, title, subtitle, coordinate):
return LocationActionListItem(presentationData: ItemListPresentationData(presentationData), account: account, title: title, subtitle: subtitle, icon: .liveLocation, action: {
if let coordinate = coordinate {
interaction?.sendLiveLocation(coordinate)
}
})
case let .header(theme, title):
case let .header(_, title):
return LocationSectionHeaderItem(presentationData: ItemListPresentationData(presentationData), title: title)
case let .venue(theme, venue, _):
case let .venue(_, venue, _):
let venueType = venue.venue?.type ?? ""
return ItemListVenueItem(presentationData: ItemListPresentationData(presentationData), account: account, venue: venue, style: .plain, action: {
interaction?.sendVenue(venue)
}, infoAction: ["home", "work"].contains(venueType) ? {
interaction?.openHomeWorkInfo()
} : nil)
case let .attribution(theme):
return LocationAttributionItem(presentationData: ItemListPresentationData(presentationData))
case let .attribution(_, attribution):
return LocationAttributionItem(presentationData: ItemListPresentationData(presentationData), attribution: attribution)
}
}
}
@ -496,15 +496,21 @@ final class LocationPickerControllerNode: ViewControllerTracingNode {
entries.append(.header(presentationData.theme, presentationData.strings.Map_ChooseAPlace.uppercased()))
var displayedVenues = foundVenues != nil || state.searchingVenuesAround ? foundVenues : venues
let displayedVenues = foundVenues != nil || state.searchingVenuesAround ? foundVenues : venues
if let venues = displayedVenues {
var index: Int = 0
var attribution: LocationAttribution?
for venue in venues {
if venue.venue?.provider == "foursquare" {
attribution = .foursquare
} else if venue.venue?.provider == "gplaces" {
attribution = .google
}
entries.append(.venue(presentationData.theme, venue, index))
index += 1
}
if !venues.isEmpty {
entries.append(.attribution(presentationData.theme))
if let attribution = attribution {
entries.append(.attribution(presentationData.theme, attribution))
}
}
let previousEntries = previousEntries.swap(entries)
@ -574,7 +580,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode {
if let (layout, navigationBarHeight) = strongSelf.validLayout {
var updateLayout = false
var transition: ContainedViewLayoutTransition = .animated(duration: 0.45, curve: .spring)
let transition: ContainedViewLayoutTransition = .animated(duration: 0.45, curve: .spring)
if previousState.displayingMapModeOptions != state.displayingMapModeOptions {
updateLayout = true

View File

@ -180,9 +180,13 @@ private func allOpenInOptions(context: AccountContext, item: OpenInItem) -> [Ope
let coordinates = "\(lat),\(lon)"
if withDirections {
return .openUrl(url: "comgooglemaps-x-callback://?daddr=\(coordinates)&directionsmode=driving&x-success=telegram://?resume=true&x-source=Telegram")
} else {
if let venue = location.venue, let venueId = venue.id, let provider = venue.provider, provider == "gplaces" {
return .openUrl(url: "https://www.google.com/maps/search/?api=1&query=\(venue.address ?? "")&query_place_id=\(venueId)")
} else {
return .openUrl(url: "comgooglemaps-x-callback://?center=\(coordinates)&q=\(coordinates)&x-success=telegram://?resume=true&x-source=Telegram")
}
}
}))
options.append(OpenInOption(identifier: "yandexMaps", application: .other(title: "Yandex.Maps", identifier: 313877526, scheme: "yandexmaps", store: nil), action: {

View File

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "powered_by_google_on_white@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "powered_by_google_on_white@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB