mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-13 14:56:03 +10:00
tapGithubRepoAction, tapDribbbleShotAction for FeedView
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user