From b9fae1173f9cd30685f416db8a33f8140fc08ff2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 24 Nov 2015 10:37:31 +0800 Subject: [PATCH] tapGithubRepoAction, tapDribbbleShotAction for FeedView --- .../ConversationViewController.swift | 44 +++++++++++++++++++ Yep/Views/Feed/FeedView.swift | 37 ++++++++++++++-- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 1db42e48..b68a5076 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -119,6 +119,24 @@ enum ConversationFeed { return nil } + var githubRepoURL: NSURL? { + + switch self { + case .DiscoveredFeedType(let discoveredFeed): + if let attachment = discoveredFeed.attachment { + if case let .Github(githubRepo) = attachment { + return NSURL(string: githubRepo.URLString) + } + } + case .FeedType(let feed): + if let URLString = feed.socialWork?.githubRepo?.URLString { + return NSURL(string: URLString) + } + } + + return nil + } + var dribbbleShotImageURL: NSURL? { switch self { @@ -136,6 +154,24 @@ enum ConversationFeed { return nil } + + var dribbbleShotURL: NSURL? { + + switch self { + case .DiscoveredFeedType(let discoveredFeed): + if let attachment = discoveredFeed.attachment { + if case let .Dribbble(dribbbleShot) = attachment { + return NSURL(string: dribbbleShot.htmlURLString) + } + } + case .FeedType(let feed): + if let htmlURLString = feed.socialWork?.dribbbleShot?.htmlURLString { + return NSURL(string: htmlURLString) + } + } + + return nil + } var attachments: [Attachment] { switch self { @@ -1426,6 +1462,14 @@ class ConversationViewController: BaseViewController { */ } + feedView.tapGithubRepoAction = { URL in + UIApplication.sharedApplication().openURL(URL) + } + + feedView.tapDribbbleShotAction = { URL in + UIApplication.sharedApplication().openURL(URL) + } + //feedView.backgroundColor = UIColor.orangeColor() feedView.translatesAutoresizingMaskIntoConstraints = false diff --git a/Yep/Views/Feed/FeedView.swift b/Yep/Views/Feed/FeedView.swift index c3c2a942..68b80e7a 100644 --- a/Yep/Views/Feed/FeedView.swift +++ b/Yep/Views/Feed/FeedView.swift @@ -20,6 +20,8 @@ class FeedView: UIView { } var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + var tapGithubRepoAction: (NSURL -> Void)? + var tapDribbbleShotAction: (NSURL -> Void)? static let foldHeight: CGFloat = 60 @@ -159,13 +161,16 @@ class FeedView: UIView { mediaCollectionView.dataSource = self mediaCollectionView.delegate = self - let tap = UITapGestureRecognizer(target: self, action: "switchFold:") - addGestureRecognizer(tap) - tap.delegate = self + let tapSwitchFold = UITapGestureRecognizer(target: self, action: "switchFold:") + addGestureRecognizer(tapSwitchFold) + tapSwitchFold.delegate = self let tapAvatar = UITapGestureRecognizer(target: self, action: "tapAvatar:") avatarImageView.userInteractionEnabled = true avatarImageView.addGestureRecognizer(tapAvatar) + + let tapSocialWork = UITapGestureRecognizer(target: self, action: "tapSocialWork:") + socialWorkContainerView.addGestureRecognizer(tapSocialWork) } func switchFold(sender: UITapGestureRecognizer) { @@ -280,6 +285,32 @@ class FeedView: UIView { socialWorkImageView.kf_setImageWithURL(URL, placeholderImage: nil) } } + + func tapSocialWork(sender: UITapGestureRecognizer) { + + guard let kind = feed?.kind else { + return + } + + switch kind { + + case .GithubRepo: + + if let URL = feed?.githubRepoURL { + tapGithubRepoAction?(URL) + } + + case .DribbbleShot: + + if let URL = feed?.dribbbleShotURL { + tapDribbbleShotAction?(URL) + + } + + default: + break + } + } } // MARK: - UIGestureRecognizerDelegate