From 8ec0581ff2df261ca0b39f377a15ecf2a0e302ec Mon Sep 17 00:00:00 2001 From: nixzhu Date: Mon, 30 Nov 2015 13:57:30 +0800 Subject: [PATCH] tapLocationAction in Feeds --- Yep/Services/YepService.swift | 4 ++++ .../Feeds/FeedsViewController.swift | 9 +++++++++ .../FeedSocialWork/FeedSocialWorkCell.swift | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index fee30bbf..71887f1d 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2673,6 +2673,10 @@ struct DiscoveredFeed: Hashable { let latitude: CLLocationDegrees let longitude: CLLocationDegrees + var coordinate: CLLocationCoordinate2D { + return CLLocationCoordinate2D(latitude: latitude, longitude: longitude) + } + static func fromJSONDictionary(json: JSONDictionary) -> LocationInfo? { guard let name = json["place"] as? String, diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index c9d091f2..0996d6bb 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -9,6 +9,7 @@ import UIKit import RealmSwift import AVFoundation +import MapKit class FeedsViewController: BaseViewController { @@ -899,6 +900,14 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { } } + cell.tapLocationAction = { locationName, locationCoordinate in + + let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: locationCoordinate, addressDictionary: nil)) + mapItem.name = locationName + + mapItem.openInMapsWithLaunchOptions(nil) + } + default: guard let cell = cell as? FeedCell else { diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift index 61c1bb44..ea07d032 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift @@ -62,6 +62,7 @@ class FeedSocialWorkCell: FeedBasicCell { var tapGithubRepoLinkAction: (NSURL -> Void)? var tapDribbbleShotLinkAction: (NSURL -> Void)? var tapDribbbleShotMediaAction: ((transitionView: UIView, image: UIImage?, imageURL: NSURL, linkURL: NSURL) -> Void)? + var tapLocationAction: ((locationName: String, locationCoordinate: CLLocationCoordinate2D) -> Void)? var audioPlaying: Bool = false { willSet { @@ -134,6 +135,9 @@ class FeedSocialWorkCell: FeedBasicCell { let tapGithubLink = UITapGestureRecognizer(target: self, action: "tapGithubLink:") githubRepoContainerView.addGestureRecognizer(tapGithubLink) + + let tapLocation = UITapGestureRecognizer(target: self, action: "tapLocation:") + locationContainerView.addGestureRecognizer(tapLocation) } override func setSelected(selected: Bool, animated: Bool) { @@ -406,5 +410,18 @@ class FeedSocialWorkCell: FeedBasicCell { } } } + + func tapLocation(sender: UITapGestureRecognizer) { + + guard let feed = feed, attachment = feed.attachment else { + return + } + + if case .Location = feed.kind { + if case let .Location(locationInfo) = attachment { + tapLocationAction?(locationName: locationInfo.name, locationCoordinate: locationInfo.coordinate) + } + } + } }