From 99281801069343cdced0b3b5e83b0bb6aab282ae Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 17:03:38 +0800 Subject: [PATCH 01/45] disable AutoLayout of Feed Cells; remove nib files --- Yep.xcodeproj/project.pbxproj | 8 - .../Feeds/FeedsViewController.swift | 9 +- Yep/Views/Cells/Feed/FeedCell.swift | 140 ++++++++------ Yep/Views/Cells/Feed/FeedCell.xib | 121 ------------ Yep/Views/Cells/FeedBasic/FeedBasicCell.swift | 160 +++++++++++----- .../FeedSocialWork/FeedSocialWorkCell.swift | 81 ++++++-- .../FeedSocialWork/FeedSocialWorkCell.xib | 178 ------------------ 7 files changed, 267 insertions(+), 430 deletions(-) delete mode 100644 Yep/Views/Cells/Feed/FeedCell.xib delete mode 100644 Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 6a1de0e0..0d34dda1 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -61,7 +61,6 @@ 501690191BFB18D20096C4F9 /* ChatLeftSocialWorkCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 501690171BFB18D20096C4F9 /* ChatLeftSocialWorkCell.xib */; }; 5016901C1BFB22180096C4F9 /* SocialWorkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016901B1BFB22180096C4F9 /* SocialWorkService.swift */; }; 5016901F1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016901D1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift */; }; - 501690201BFDCECB0096C4F9 /* FeedSocialWorkCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5016901E1BFDCECB0096C4F9 /* FeedSocialWorkCell.xib */; }; 501690231BFEA6C30096C4F9 /* FeedBasicCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 501690221BFEA6C30096C4F9 /* FeedBasicCell.swift */; }; 501813261BA07CED0025873C /* Activities.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 501813251BA07CED0025873C /* Activities.xcassets */; }; 5018132C1BA3CFEF0025873C /* WeChatActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5018132B1BA3CFEF0025873C /* WeChatActivity.swift */; }; @@ -316,7 +315,6 @@ 50F5AF861BBA676D0033C9BC /* NewFeed.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF851BBA676D0033C9BC /* NewFeed.storyboard */; }; 50F5AF881BBBB2AE0033C9BC /* HorizontalLineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF871BBBB2AE0033C9BC /* HorizontalLineView.swift */; }; 50F5AF8C1BBBB64C0033C9BC /* FeedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */; }; - 50F5AF8D1BBBB64C0033C9BC /* FeedCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF8B1BBBB64C0033C9BC /* FeedCell.xib */; }; 50F5AF951BBBCDA30033C9BC /* FeedMediaAddCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF931BBBCDA30033C9BC /* FeedMediaAddCell.swift */; }; 50F5AF961BBBCDA30033C9BC /* FeedMediaAddCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */; }; 50F5AF991BBBD02A0033C9BC /* FeedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */; }; @@ -424,7 +422,6 @@ 501690171BFB18D20096C4F9 /* ChatLeftSocialWorkCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ChatLeftSocialWorkCell.xib; path = Views/Cells/ChatLeftSocialWork/ChatLeftSocialWorkCell.xib; sourceTree = ""; }; 5016901B1BFB22180096C4F9 /* SocialWorkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocialWorkService.swift; path = Services/SocialWorkService.swift; sourceTree = ""; }; 5016901D1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedSocialWorkCell.swift; path = Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift; sourceTree = ""; }; - 5016901E1BFDCECB0096C4F9 /* FeedSocialWorkCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedSocialWorkCell.xib; path = Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib; sourceTree = ""; }; 501690221BFEA6C30096C4F9 /* FeedBasicCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBasicCell.swift; path = Views/Cells/FeedBasic/FeedBasicCell.swift; sourceTree = ""; }; 501813251BA07CED0025873C /* Activities.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Activities.xcassets; sourceTree = ""; }; 5018132B1BA3CFEF0025873C /* WeChatActivity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WeChatActivity.swift; path = Activities/WeChatActivity.swift; sourceTree = ""; }; @@ -680,7 +677,6 @@ 50F5AF851BBA676D0033C9BC /* NewFeed.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = NewFeed.storyboard; path = ViewControllers/NewFeed/NewFeed.storyboard; sourceTree = ""; }; 50F5AF871BBBB2AE0033C9BC /* HorizontalLineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HorizontalLineView.swift; path = Views/HorizontalLine/HorizontalLineView.swift; sourceTree = ""; }; 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedCell.swift; path = Views/Cells/Feed/FeedCell.swift; sourceTree = ""; }; - 50F5AF8B1BBBB64C0033C9BC /* FeedCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedCell.xib; path = Views/Cells/Feed/FeedCell.xib; sourceTree = ""; }; 50F5AF931BBBCDA30033C9BC /* FeedMediaAddCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaAddCell.swift; path = Views/Cells/FeedMediaAdd/FeedMediaAddCell.swift; sourceTree = ""; }; 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaAddCell.xib; path = Views/Cells/FeedMediaAdd/FeedMediaAddCell.xib; sourceTree = ""; }; 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaCell.swift; path = Views/Cells/FeedMedia/FeedMediaCell.swift; sourceTree = ""; }; @@ -995,7 +991,6 @@ isa = PBXGroup; children = ( 5016901D1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift */, - 5016901E1BFDCECB0096C4F9 /* FeedSocialWorkCell.xib */, ); name = FeedSocialWork; sourceTree = ""; @@ -1980,7 +1975,6 @@ isa = PBXGroup; children = ( 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */, - 50F5AF8B1BBBB64C0033C9BC /* FeedCell.xib */, ); name = Feed; sourceTree = ""; @@ -2435,7 +2429,6 @@ 50E348931B9063A700A8E699 /* AboutCell.xib in Resources */, 5039594F1B05E6E000797A3E /* ProfileSocialAccountGithubCell.xib in Resources */, 502AE5591AB932D5005BD199 /* ProfileSectionHeaderReusableView.xib in Resources */, - 50F5AF8D1BBBB64C0033C9BC /* FeedCell.xib in Resources */, 5056AD6F1B05CB92003F9359 /* ProfileSocialAccountImagesCell.xib in Resources */, 506BB7F61AE4E0A500C1A2A0 /* SkillAnnotationHeader.xib in Resources */, 50AFBF4E1BB3A594007D19DA /* bub3.caf in Resources */, @@ -2485,7 +2478,6 @@ 50CDBE431ACA9B4200459CE0 /* ChatRightImageCell.xib in Resources */, 50E1CE8B1BE0BC940025B933 /* MessageMedia.storyboard in Resources */, 50DEE0471BEA030900015741 /* PodsHelpYep.storyboard in Resources */, - 501690201BFDCECB0096C4F9 /* FeedSocialWorkCell.xib in Resources */, 508C2AA51AD661B3002B8097 /* UserStateCell.xib in Resources */, 508F8FDF1B049ACF00461B0B /* InstagramMediaCell.xib in Resources */, 848806B11B789A2D000C5424 /* EditSkillCell.xib in Resources */, diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 7beab372..e3fcf78c 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -279,8 +279,13 @@ class FeedsViewController: BaseViewController { feedsTableView.separatorColor = UIColor.yepCellSeparatorColor() feedsTableView.registerNib(UINib(nibName: feedSkillUsersCellID, bundle: nil), forCellReuseIdentifier: feedSkillUsersCellID) - feedsTableView.registerNib(UINib(nibName: feedCellID, bundle: nil), forCellReuseIdentifier: feedCellID) - feedsTableView.registerNib(UINib(nibName: feedSocialWorkCellID, bundle: nil), forCellReuseIdentifier: feedSocialWorkCellID) + +// feedsTableView.registerNib(UINib(nibName: feedCellID, bundle: nil), forCellReuseIdentifier: feedCellID) +// feedsTableView.registerNib(UINib(nibName: feedSocialWorkCellID, bundle: nil), forCellReuseIdentifier: feedSocialWorkCellID) + + feedsTableView.registerClass(FeedCell.self, forCellReuseIdentifier: feedCellID) + feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) + feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index 8c70c20f..ecf08d80 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -11,68 +11,27 @@ import UIKit let feedAttachmentImageSize = CGSize(width: 80, height: 80) let feedAttachmentBiggerImageSize = CGSize(width: 160, height: 160) +private let feedMediaCellID = "FeedMediaCell" + class FeedCell: FeedBasicCell { - @IBOutlet weak var mediaCollectionView: UICollectionView! - @IBOutlet weak var collectionViewHeight: NSLayoutConstraint! + //@IBOutlet weak var mediaCollectionView: UICollectionView! + //@IBOutlet weak var collectionViewHeight: NSLayoutConstraint! - @IBOutlet weak var leftBottomLabelTopConstraint: NSLayoutConstraint! + //@IBOutlet weak var leftBottomLabelTopConstraint: NSLayoutConstraint! - var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + lazy var mediaCollectionView: UICollectionView = { + let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout()) - var attachments = [DiscoveredAttachment]() { - didSet { + collectionView.scrollsToTop = false + collectionView.contentInset = UIEdgeInsets(top: 0, left: 15 + 40 + 10, bottom: 0, right: 15) + collectionView.showsHorizontalScrollIndicator = false + collectionView.backgroundColor = UIColor.clearColor() + collectionView.registerNib(UINib(nibName: feedMediaCellID, bundle: nil), forCellWithReuseIdentifier: feedMediaCellID) + collectionView.dataSource = self + collectionView.delegate = self - let oldHeight = collectionViewHeight.constant - let newHeight: CGFloat - if attachments.count == 1 { - newHeight = feedAttachmentBiggerImageSize.height - } else { - newHeight = feedAttachmentImageSize.height - } - if newHeight != oldHeight { - collectionViewHeight.constant = newHeight - } - - mediaCollectionView.reloadData() - } - } - - static let messageTextViewMaxWidth: CGFloat = { - let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 15) - return maxWidth - }() - - let feedMediaCellID = "FeedMediaCell" - - class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - - let rect = feed.body.boundingRectWithSize(CGSize(width: FeedCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) - - var height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 - - if let attachment = feed.attachment { - if case let .Images(attachments) = attachment { - let imageHeight: CGFloat = attachments.count == 1 ? feedAttachmentBiggerImageSize.height : feedAttachmentImageSize.height - height += (imageHeight + 15) - } - } - - return ceil(height) - } - - override func awakeFromNib() { - super.awakeFromNib() - - mediaCollectionView.scrollsToTop = false - mediaCollectionView.contentInset = UIEdgeInsets(top: 0, left: 15 + 40 + 10, bottom: 0, right: 15) - mediaCollectionView.showsHorizontalScrollIndicator = false - mediaCollectionView.backgroundColor = UIColor.clearColor() - mediaCollectionView.registerNib(UINib(nibName: feedMediaCellID, bundle: nil), forCellWithReuseIdentifier: feedMediaCellID) - mediaCollectionView.dataSource = self - mediaCollectionView.delegate = self - - let backgroundView = TouchClosuresView(frame: mediaCollectionView.bounds) + let backgroundView = TouchClosuresView(frame: collectionView.bounds) backgroundView.touchesBeganAction = { [weak self] in if let strongSelf = self { strongSelf.touchesBeganAction?(strongSelf) @@ -91,7 +50,64 @@ class FeedCell: FeedBasicCell { strongSelf.touchesCancelledAction?(strongSelf) } } - mediaCollectionView.backgroundView = backgroundView + collectionView.backgroundView = backgroundView + + return collectionView + }() + + + var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + + var attachments = [DiscoveredAttachment]() { + didSet { + + /* + let oldHeight = collectionViewHeight.constant + let newHeight: CGFloat + if attachments.count == 1 { + newHeight = feedAttachmentBiggerImageSize.height + } else { + newHeight = feedAttachmentImageSize.height + } + if newHeight != oldHeight { + collectionViewHeight.constant = newHeight + } + */ + + mediaCollectionView.reloadData() + } + } + + static let messageTextViewMaxWidth: CGFloat = { + let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 15) + return maxWidth + }() + + + class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let rect = feed.body.boundingRectWithSize(CGSize(width: FeedCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) + + var height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 + + if let attachment = feed.attachment { + if case let .Images(attachments) = attachment { + let imageHeight: CGFloat = attachments.count == 1 ? feedAttachmentBiggerImageSize.height : feedAttachmentImageSize.height + height += (imageHeight + 15) + } + } + + return ceil(height) + } + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(mediaCollectionView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") } override func prepareForReuse() { @@ -113,11 +129,11 @@ class FeedCell: FeedBasicCell { } } - if attachments.count > 1 { - leftBottomLabelTopConstraint.constant = hasMedia ? (15 + feedAttachmentImageSize.height + 15) : 15 - } else { - leftBottomLabelTopConstraint.constant = hasMedia ? (15 + feedAttachmentBiggerImageSize.height + 15) : 15 - } +// if attachments.count > 1 { +// leftBottomLabelTopConstraint.constant = hasMedia ? (15 + feedAttachmentImageSize.height + 15) : 15 +// } else { +// leftBottomLabelTopConstraint.constant = hasMedia ? (15 + feedAttachmentBiggerImageSize.height + 15) : 15 +// } mediaCollectionView.hidden = hasMedia ? false : true } diff --git a/Yep/Views/Cells/Feed/FeedCell.xib b/Yep/Views/Cells/Feed/FeedCell.xib deleted file mode 100644 index ef065e9d..00000000 --- a/Yep/Views/Cells/Feed/FeedCell.xib +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift b/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift index 294bce55..8330383d 100644 --- a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift +++ b/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift @@ -8,19 +8,115 @@ import UIKit +private let screenWidth = UIScreen.mainScreen().bounds.width + class FeedBasicCell: UITableViewCell { - @IBOutlet weak var avatarImageView: UIImageView! - @IBOutlet weak var nicknameLabel: UILabel! + //@IBOutlet weak var avatarImageView: UIImageView! + //@IBOutlet weak var nicknameLabel: UILabel! - @IBOutlet weak var skillButton: UIButton! + //@IBOutlet weak var skillButton: UIButton! + + //@IBOutlet weak var messageTextView: FeedTextView! + //@IBOutlet weak var messageTextViewHeightConstraint: NSLayoutConstraint! + + //@IBOutlet weak var leftBottomLabel: UILabel! + + //@IBOutlet weak var messageCountLabel: UILabel! + + lazy var avatarImageView: UIImageView = { + let imageView = UIImageView() + imageView.frame = CGRect(x: 15, y: 10, width: 40, height: 40) + imageView.contentMode = .ScaleAspectFit + + let tapAvatar = UITapGestureRecognizer(target: self, action: "tapAvatar:") + imageView.userInteractionEnabled = true + imageView.addGestureRecognizer(tapAvatar) + + return imageView + }() + + lazy var nicknameLabel: UILabel = { + let label = UILabel() + label.textColor = UIColor.yepTintColor() + label.font = UIFont.systemFontOfSize(15) + label.frame = CGRect(x: 65, y: 21, width: 100, height: 18) + return label + }() + + lazy var skillButton: UIButton = { + let button = UIButton() + button.setBackgroundImage(UIImage(named: "sill_bubble_empty"), forState: .Normal) + button.setTitleColor(UIColor.yepTintColor(), forState: .Normal) + button.titleLabel?.font = UIFont.feedSkillFont() + + let cellWidth = self.bounds.width + let width: CGFloat = 60 + button.frame = CGRect(x: cellWidth - width - 15, y: 19, width: width, height: 22) + + button.addTarget(self, action: "tapSkill:", forControlEvents: .TouchUpInside) + + return button + }() + + lazy var messageTextView: FeedTextView = { + let textView = FeedTextView() + textView.textColor = UIColor.yepMessageColor() + textView.font = UIFont.feedMessageFont() + textView.textContainer.lineFragmentPadding = 0 + textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + textView.dataDetectorTypes = .Link + + let cellWidth = self.bounds.width + textView.frame = CGRect(x: 65, y: 54, width: cellWidth - 65 - 15, height: 26) + + textView.touchesBeganAction = { [weak self] in + if let strongSelf = self { + strongSelf.touchesBeganAction?(strongSelf) + } + } + textView.touchesEndedAction = { [weak self] in + if let strongSelf = self { + if strongSelf.editing { + return + } + strongSelf.touchesEndedAction?(strongSelf) + } + } + textView.touchesCancelledAction = { [weak self] in + if let strongSelf = self { + strongSelf.touchesCancelledAction?(strongSelf) + } + } + + return textView + }() + + lazy var leftBottomLabel: UILabel = { + let label = UILabel() + label.textColor = UIColor.yepTintColor() + label.font = UIFont.systemFontOfSize(14) + label.textColor = UIColor.grayColor() + + return label + }() + + lazy var messageCountLabel: UILabel = { + let label = UILabel() + label.textColor = UIColor.yepTintColor() + label.font = UIFont.systemFontOfSize(14) + label.textColor = UIColor.grayColor() + return label + }() + + lazy var discussionImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "icon_discussion") + return imageView + }() - @IBOutlet weak var messageTextView: FeedTextView! - @IBOutlet weak var messageTextViewHeightConstraint: NSLayoutConstraint! - @IBOutlet weak var leftBottomLabel: UILabel! - @IBOutlet weak var messageCountLabel: UILabel! var tapAvatarAction: (UITableViewCell -> Void)? var tapSkillAction: (UITableViewCell -> Void)? @@ -36,46 +132,22 @@ class FeedBasicCell: UITableViewCell { messageTextView.attributedText = nil } - override func awakeFromNib() { - super.awakeFromNib() + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) - nicknameLabel.textColor = UIColor.yepTintColor() - messageTextView.textColor = UIColor.yepMessageColor() - leftBottomLabel.textColor = UIColor.grayColor() - messageCountLabel.textColor = UIColor.yepTintColor() - skillButton.setTitleColor(UIColor.yepTintColor(), forState: .Normal) + contentView.addSubview(avatarImageView) + contentView.addSubview(nicknameLabel) + contentView.addSubview(skillButton) - messageTextView.font = UIFont.feedMessageFont() - messageTextView.textContainer.lineFragmentPadding = 0 - messageTextView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) - messageTextView.dataDetectorTypes = .Link + contentView.addSubview(messageTextView) - skillButton.titleLabel?.font = UIFont.feedSkillFont() + contentView.addSubview(leftBottomLabel) + contentView.addSubview(messageCountLabel) + contentView.addSubview(discussionImageView) + } - let tapAvatar = UITapGestureRecognizer(target: self, action: "tapAvatar:") - avatarImageView.userInteractionEnabled = true - avatarImageView.addGestureRecognizer(tapAvatar) - - skillButton.addTarget(self, action: "tapSkill:", forControlEvents: .TouchUpInside) - - messageTextView.touchesBeganAction = { [weak self] in - if let strongSelf = self { - strongSelf.touchesBeganAction?(strongSelf) - } - } - messageTextView.touchesEndedAction = { [weak self] in - if let strongSelf = self { - if strongSelf.editing { - return - } - strongSelf.touchesEndedAction?(strongSelf) - } - } - messageTextView.touchesCancelledAction = { [weak self] in - if let strongSelf = self { - strongSelf.touchesCancelledAction?(strongSelf) - } - } + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") } override func setSelected(selected: Bool, animated: Bool) { @@ -87,7 +159,7 @@ class FeedBasicCell: UITableViewCell { private func calHeightOfMessageTextView() { let rect = messageTextView.text.boundingRectWithSize(CGSize(width: FeedCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) - messageTextViewHeightConstraint.constant = ceil(rect.height) + //messageTextViewHeightConstraint.constant = ceil(rect.height) } func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift index 574abfcb..12b39457 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift @@ -16,6 +16,7 @@ private let dribbbleShotHeight: CGFloat = Ruler.iPhoneHorizontal(160, 200, 220). class FeedSocialWorkCell: FeedBasicCell { + /* @IBOutlet weak var logoImageView: UIImageView! @IBOutlet weak var logoImageViewTrailingConstraint: NSLayoutConstraint! @@ -32,6 +33,46 @@ class FeedSocialWorkCell: FeedBasicCell { @IBOutlet weak var socialWorkBorderImageView: UIImageView! @IBOutlet weak var socialWorkContainerViewHeightConstraint: NSLayoutConstraint! + */ + + lazy var logoImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "icon_github") + return imageView + }() + + lazy var mediaContainerView: FeedMediaContainerView = { + let view = FeedMediaContainerView() + return view + }() + + lazy var githubRepoContainerView: FeedGithubRepoContainerView = { + let view = FeedGithubRepoContainerView() + return view + }() + + lazy var voiceContainerView: FeedVoiceContainerView = { + let view = FeedVoiceContainerView() + return view + }() + + lazy var locationContainerView: FeedLocationContainerView = { + let view = FeedLocationContainerView() + return view + }() + + lazy var socialWorkBorderImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "social_work_border") + return imageView + }() + + + + + + + lazy var halfMaskImageView: UIImageView = { let imageView = UIImageView(image: UIImage(named: "social_media_image_mask")) @@ -99,9 +140,19 @@ class FeedSocialWorkCell: FeedBasicCell { locationContainerView.mapImageView.image = nil } - override func awakeFromNib() { - super.awakeFromNib() + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + contentView.addSubview(logoImageView) + contentView.addSubview(mediaContainerView) + contentView.addSubview(githubRepoContainerView) + contentView.addSubview(voiceContainerView) + contentView.addSubview(locationContainerView) + contentView.addSubview(socialWorkBorderImageView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") } override func setSelected(selected: Bool, animated: Bool) { @@ -136,12 +187,12 @@ class FeedSocialWorkCell: FeedBasicCell { self.feed = feed - if needShowSkill, let skill = feed.skill { - let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) - logoImageViewTrailingConstraint.constant = 8 + (10 + rect.width + 10) + 15 - } else { - logoImageViewTrailingConstraint.constant = 15 - } +// if needShowSkill, let skill = feed.skill { +// let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) +// logoImageViewTrailingConstraint.constant = 8 + (10 + rect.width + 10) + 15 +// } else { +// logoImageViewTrailingConstraint.constant = 15 +// } if let accountName = feed.kind.accountName, @@ -185,7 +236,7 @@ class FeedSocialWorkCell: FeedBasicCell { } } - socialWorkContainerViewHeightConstraint.constant = 80 + //socialWorkContainerViewHeightConstraint.constant = 80 case .DribbbleShot: @@ -230,8 +281,8 @@ class FeedSocialWorkCell: FeedBasicCell { mediaContainerView.mediaImageView.maskView = halfMaskImageView - socialWorkContainerViewHeightConstraint.constant = dribbbleShotHeight - contentView.layoutIfNeeded() + //socialWorkContainerViewHeightConstraint.constant = dribbbleShotHeight + //contentView.layoutIfNeeded() case .Audio: @@ -252,7 +303,7 @@ class FeedSocialWorkCell: FeedBasicCell { let rect = timeLengthString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.voiceTimeLengthTextAttributes, context: nil) - voiceContainerViewWidthConstraint.constant = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 + //voiceContainerViewWidthConstraint.constant = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 if let realm = try? Realm() { @@ -316,7 +367,7 @@ class FeedSocialWorkCell: FeedBasicCell { } } - socialWorkContainerViewHeightConstraint.constant = 44 + //socialWorkContainerViewHeightConstraint.constant = 44 case .Location: @@ -357,8 +408,8 @@ class FeedSocialWorkCell: FeedBasicCell { } } - socialWorkContainerViewHeightConstraint.constant = 110 - contentView.layoutIfNeeded() + //socialWorkContainerViewHeightConstraint.constant = 110 + //contentView.layoutIfNeeded() default: break diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib deleted file mode 100644 index a1bf4aa0..00000000 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From bb8e90fbec4b837165594c32ccb67357915f23d5 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 17:33:47 +0800 Subject: [PATCH 02/45] FeedBasicCell frame layout --- Yep/Configs/YepConfig.swift | 4 ++ Yep/Extensions/UIFont+Yep.swift | 4 ++ Yep/Views/Cells/FeedBasic/FeedBasicCell.swift | 46 +++++++++++++++---- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Yep/Configs/YepConfig.swift b/Yep/Configs/YepConfig.swift index 2af6a1f2..1fc05038 100644 --- a/Yep/Configs/YepConfig.swift +++ b/Yep/Configs/YepConfig.swift @@ -226,6 +226,10 @@ class YepConfig { static let voiceTimeLengthTextAttributes:[String: NSObject] = [ NSFontAttributeName: UIFont.feedVoiceTimeLengthFont(), ] + + static let bottomLabelsTextAttributes:[String: NSObject] = [ + NSFontAttributeName: UIFont.feedBottomLabelsFont(), + ] } struct FeedView { diff --git a/Yep/Extensions/UIFont+Yep.swift b/Yep/Extensions/UIFont+Yep.swift index fdaca68c..8d3999b5 100644 --- a/Yep/Extensions/UIFont+Yep.swift +++ b/Yep/Extensions/UIFont+Yep.swift @@ -49,6 +49,10 @@ extension UIFont { return UIFont.systemFontOfSize(12) } + class func feedBottomLabelsFont() -> UIFont { + return UIFont.systemFontOfSize(14) + } + class func feedVoiceTimeLengthFont() -> UIFont { return UIFont.systemFontOfSize(15) } diff --git a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift b/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift index 8330383d..daaeb585 100644 --- a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift +++ b/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift @@ -8,7 +8,7 @@ import UIKit -private let screenWidth = UIScreen.mainScreen().bounds.width +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width class FeedBasicCell: UITableViewCell { @@ -26,7 +26,9 @@ class FeedBasicCell: UITableViewCell { lazy var avatarImageView: UIImageView = { let imageView = UIImageView() + imageView.frame = CGRect(x: 15, y: 10, width: 40, height: 40) + imageView.contentMode = .ScaleAspectFit let tapAvatar = UITapGestureRecognizer(target: self, action: "tapAvatar:") @@ -40,13 +42,15 @@ class FeedBasicCell: UITableViewCell { let label = UILabel() label.textColor = UIColor.yepTintColor() label.font = UIFont.systemFontOfSize(15) + label.frame = CGRect(x: 65, y: 21, width: 100, height: 18) + return label }() lazy var skillButton: UIButton = { let button = UIButton() - button.setBackgroundImage(UIImage(named: "sill_bubble_empty"), forState: .Normal) + button.setBackgroundImage(UIImage(named: "skill_bubble_empty"), forState: .Normal) button.setTitleColor(UIColor.yepTintColor(), forState: .Normal) button.titleLabel?.font = UIFont.feedSkillFont() @@ -67,8 +71,7 @@ class FeedBasicCell: UITableViewCell { textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) textView.dataDetectorTypes = .Link - let cellWidth = self.bounds.width - textView.frame = CGRect(x: 65, y: 54, width: cellWidth - 65 - 15, height: 26) + textView.frame = CGRect(x: 65, y: 54, width: screenWidth - 65 - 15, height: 26) textView.touchesBeganAction = { [weak self] in if let strongSelf = self { @@ -94,9 +97,10 @@ class FeedBasicCell: UITableViewCell { lazy var leftBottomLabel: UILabel = { let label = UILabel() - label.textColor = UIColor.yepTintColor() - label.font = UIFont.systemFontOfSize(14) label.textColor = UIColor.grayColor() + label.font = UIFont.feedBottomLabelsFont() + + label.frame = CGRect(x: 65, y: 0, width: 200, height: 17) return label }() @@ -104,8 +108,10 @@ class FeedBasicCell: UITableViewCell { lazy var messageCountLabel: UILabel = { let label = UILabel() label.textColor = UIColor.yepTintColor() - label.font = UIFont.systemFontOfSize(14) - label.textColor = UIColor.grayColor() + label.font = UIFont.feedBottomLabelsFont() + + label.frame = CGRect(x: 65, y: 0, width: 200, height: 17) + return label }() @@ -159,7 +165,8 @@ class FeedBasicCell: UITableViewCell { private func calHeightOfMessageTextView() { let rect = messageTextView.text.boundingRectWithSize(CGSize(width: FeedCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) - //messageTextViewHeightConstraint.constant = ceil(rect.height) + + messageTextView.frame.size.height = ceil(rect.height) } func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { @@ -172,8 +179,18 @@ class FeedBasicCell: UITableViewCell { skillButton.setTitle(skill.localName, forState: .Normal) skillButton.hidden = false + let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) + + let skillButtonWidth = rect.width + 20 + + skillButton.frame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) + + nicknameLabel.frame.size.width = screenWidth - 65 - skillButtonWidth - 15 - 16 - 18 + } else { skillButton.hidden = true + + nicknameLabel.frame.size.width = screenWidth - 65 - 15 } let plainAvatar = PlainAvatar(avatarURLString: feed.creator.avatarURLString, avatarStyle: nanoAvatarStyle) @@ -183,8 +200,17 @@ class FeedBasicCell: UITableViewCell { leftBottomLabel.text = feed.timeAndDistanceString - messageCountLabel.text = "\(feed.messagesCount)" + let messagesCountString = "\(feed.messagesCount)" + messageCountLabel.text = messagesCountString messageCountLabel.hidden = (feed.messagesCount == 0) + + leftBottomLabel.frame.origin.y = contentView.bounds.height - leftBottomLabel.frame.height - 10 + + let rect = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) + + messageCountLabel.frame = CGRect(x: screenWidth - rect.width - 45 - 8, y: leftBottomLabel.frame.origin.y, width: rect.width, height: 19) + + discussionImageView.frame = CGRect(x: screenWidth - 30 - 15, y: leftBottomLabel.frame.origin.y - 1, width: 30, height: 19) } // MARK: Actions From c2c319d90faafb2692b70ba340419adc7e8a692e Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 17:53:51 +0800 Subject: [PATCH 03/45] FeedCell frame layout --- Yep/Views/Cells/Feed/FeedCell.swift | 43 ++++++++++++----------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index ecf08d80..57a2c52a 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -12,6 +12,7 @@ let feedAttachmentImageSize = CGSize(width: 80, height: 80) let feedAttachmentBiggerImageSize = CGSize(width: 160, height: 160) private let feedMediaCellID = "FeedMediaCell" +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width class FeedCell: FeedBasicCell { @@ -21,8 +22,12 @@ class FeedCell: FeedBasicCell { //@IBOutlet weak var leftBottomLabelTopConstraint: NSLayoutConstraint! lazy var mediaCollectionView: UICollectionView = { - let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout()) + let layout = UICollectionViewFlowLayout() + layout.minimumLineSpacing = 5 + layout.scrollDirection = .Horizontal + + let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout) collectionView.scrollsToTop = false collectionView.contentInset = UIEdgeInsets(top: 0, left: 15 + 40 + 10, bottom: 0, right: 15) collectionView.showsHorizontalScrollIndicator = false @@ -61,19 +66,6 @@ class FeedCell: FeedBasicCell { var attachments = [DiscoveredAttachment]() { didSet { - /* - let oldHeight = collectionViewHeight.constant - let newHeight: CGFloat - if attachments.count == 1 { - newHeight = feedAttachmentBiggerImageSize.height - } else { - newHeight = feedAttachmentImageSize.height - } - if newHeight != oldHeight { - collectionViewHeight.constant = newHeight - } - */ - mediaCollectionView.reloadData() } } @@ -121,21 +113,22 @@ class FeedCell: FeedBasicCell { var hasMedia = false - if let attachment = feed.attachment { - if case let .Images(attachments) = attachment { - hasMedia = !attachments.isEmpty + if let attachment = feed.attachment, case let .Images(attachments) = attachment { + hasMedia = !attachments.isEmpty + + mediaCollectionView.hidden = hasMedia ? false : true + + if !mediaCollectionView.hidden { + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = attachments.count == 1 ? feedAttachmentBiggerImageSize.height : feedAttachmentImageSize.height + mediaCollectionView.frame = CGRect(x: 0, y: y, width: screenWidth, height: height) self.attachments = attachments } + + } else { + mediaCollectionView.hidden = true } - -// if attachments.count > 1 { -// leftBottomLabelTopConstraint.constant = hasMedia ? (15 + feedAttachmentImageSize.height + 15) : 15 -// } else { -// leftBottomLabelTopConstraint.constant = hasMedia ? (15 + feedAttachmentBiggerImageSize.height + 15) : 15 -// } - - mediaCollectionView.hidden = hasMedia ? false : true } } From 5f62ec1fe4ddc1e84aa5cac467a47ebeed3dcc34 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 18:08:24 +0800 Subject: [PATCH 04/45] FeedSocialWorkCell frame layout --- .../FeedSocialWork/FeedSocialWorkCell.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift index 12b39457..a4875871 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift @@ -13,6 +13,7 @@ import RealmSwift import MapKit private let dribbbleShotHeight: CGFloat = Ruler.iPhoneHorizontal(160, 200, 220).value +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width class FeedSocialWorkCell: FeedBasicCell { @@ -187,13 +188,6 @@ class FeedSocialWorkCell: FeedBasicCell { self.feed = feed -// if needShowSkill, let skill = feed.skill { -// let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) -// logoImageViewTrailingConstraint.constant = 8 + (10 + rect.width + 10) + 15 -// } else { -// logoImageViewTrailingConstraint.constant = 15 -// } - if let accountName = feed.kind.accountName, socialAccount = SocialAccount(rawValue: accountName) { @@ -237,6 +231,9 @@ class FeedSocialWorkCell: FeedBasicCell { } //socialWorkContainerViewHeightConstraint.constant = 80 + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 + githubRepoContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) case .DribbbleShot: @@ -283,6 +280,10 @@ class FeedSocialWorkCell: FeedBasicCell { //socialWorkContainerViewHeightConstraint.constant = dribbbleShotHeight //contentView.layoutIfNeeded() + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 + mediaContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) + mediaContainerView.layoutIfNeeded() case .Audio: @@ -304,6 +305,9 @@ class FeedSocialWorkCell: FeedBasicCell { let rect = timeLengthString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.voiceTimeLengthTextAttributes, context: nil) //voiceContainerViewWidthConstraint.constant = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 + let width = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + 2 + voiceContainerView.frame = CGRect(x: 65, y: y, width: width, height: 40) if let realm = try? Realm() { @@ -410,6 +414,10 @@ class FeedSocialWorkCell: FeedBasicCell { //socialWorkContainerViewHeightConstraint.constant = 110 //contentView.layoutIfNeeded() + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 + locationContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) + locationContainerView.layoutIfNeeded() default: break From f75a21957e7db5ebac0067e7df9019757e2d76e1 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 18:15:57 +0800 Subject: [PATCH 05/45] set frame for ContainerView & socialWorkBorderImageView --- .../Cells/FeedSocialWork/FeedSocialWorkCell.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift index a4875871..0e65c184 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift @@ -44,21 +44,25 @@ class FeedSocialWorkCell: FeedBasicCell { lazy var mediaContainerView: FeedMediaContainerView = { let view = FeedMediaContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) return view }() lazy var githubRepoContainerView: FeedGithubRepoContainerView = { let view = FeedGithubRepoContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) return view }() lazy var voiceContainerView: FeedVoiceContainerView = { let view = FeedVoiceContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) return view }() lazy var locationContainerView: FeedLocationContainerView = { let view = FeedLocationContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) return view }() @@ -235,6 +239,8 @@ class FeedSocialWorkCell: FeedBasicCell { let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 githubRepoContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) + socialWorkBorderImageView.frame = githubRepoContainerView.frame + case .DribbbleShot: mediaContainerView.hidden = false @@ -285,6 +291,8 @@ class FeedSocialWorkCell: FeedBasicCell { mediaContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) mediaContainerView.layoutIfNeeded() + socialWorkBorderImageView.frame = mediaContainerView.frame + case .Audio: mediaContainerView.hidden = true @@ -419,6 +427,8 @@ class FeedSocialWorkCell: FeedBasicCell { locationContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) locationContainerView.layoutIfNeeded() + socialWorkBorderImageView.frame = locationContainerView.frame + default: break } From 21af40d312aa64bee2e7885f5872270a94c1da51 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 18:20:53 +0800 Subject: [PATCH 06/45] fix messageTextView detect link --- Yep/Views/Cells/FeedBasic/FeedBasicCell.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift b/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift index daaeb585..0b0f5e1e 100644 --- a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift +++ b/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift @@ -69,6 +69,8 @@ class FeedBasicCell: UITableViewCell { textView.font = UIFont.feedMessageFont() textView.textContainer.lineFragmentPadding = 0 textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + textView.editable = false + textView.scrollEnabled = false textView.dataDetectorTypes = .Link textView.frame = CGRect(x: 65, y: 54, width: screenWidth - 65 - 15, height: 26) From 94e35dad78db2b206673273876d9dfa39e537da5 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Dec 2015 18:33:52 +0800 Subject: [PATCH 07/45] update frame for logoImageView --- Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift index 0e65c184..db59add8 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift @@ -39,6 +39,7 @@ class FeedSocialWorkCell: FeedBasicCell { lazy var logoImageView: UIImageView = { let imageView = UIImageView() imageView.image = UIImage(named: "icon_github") + imageView.frame = CGRect(x: 0, y: 0, width: 18, height: 18) return imageView }() @@ -199,6 +200,14 @@ class FeedSocialWorkCell: FeedBasicCell { logoImageView.tintColor = socialAccount.tintColor logoImageView.hidden = false + if needShowSkill, let _ = feed.skill { + logoImageView.frame.origin.x = skillButton.frame.origin.x - 8 - 18 + logoImageView.frame.origin.y = nicknameLabel.frame.origin.y + } else { + logoImageView.frame.origin.x = screenWidth - 18 - 15 + logoImageView.frame.origin.y = nicknameLabel.frame.origin.y + } + } else { logoImageView.hidden = true } From 631daf56003ee788522be344115f0fca816b491a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 09:39:40 +0800 Subject: [PATCH 08/45] file order --- Yep.xcodeproj/project.pbxproj | 32 +++++-------------- .../{FeedBasic => Feed}/FeedBasicCell.swift | 0 .../FeedSocialWorkCell.swift | 0 3 files changed, 8 insertions(+), 24 deletions(-) rename Yep/Views/Cells/{FeedBasic => Feed}/FeedBasicCell.swift (100%) rename Yep/Views/Cells/{FeedSocialWork => Feed}/FeedSocialWorkCell.swift (100%) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 0d34dda1..e58d0e92 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -60,8 +60,6 @@ 501690181BFB18D20096C4F9 /* ChatLeftSocialWorkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 501690161BFB18D20096C4F9 /* ChatLeftSocialWorkCell.swift */; }; 501690191BFB18D20096C4F9 /* ChatLeftSocialWorkCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 501690171BFB18D20096C4F9 /* ChatLeftSocialWorkCell.xib */; }; 5016901C1BFB22180096C4F9 /* SocialWorkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016901B1BFB22180096C4F9 /* SocialWorkService.swift */; }; - 5016901F1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016901D1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift */; }; - 501690231BFEA6C30096C4F9 /* FeedBasicCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 501690221BFEA6C30096C4F9 /* FeedBasicCell.swift */; }; 501813261BA07CED0025873C /* Activities.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 501813251BA07CED0025873C /* Activities.xcassets */; }; 5018132C1BA3CFEF0025873C /* WeChatActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5018132B1BA3CFEF0025873C /* WeChatActivity.swift */; }; 5019F6311B39BFE00000D993 /* ConversationMoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5019F6301B39BFE00000D993 /* ConversationMoreView.swift */; }; @@ -183,6 +181,8 @@ 507F65F71B2EBC2700A35FDC /* MediaPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507F65F61B2EBC2700A35FDC /* MediaPreviewView.swift */; }; 5080EB1C1B93F43A006F3C2D /* PodsHelpYepViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080EB1B1B93F43A006F3C2D /* PodsHelpYepViewController.swift */; }; 5080EB1F1B93F932006F3C2D /* NSBundle+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080EB1E1B93F932006F3C2D /* NSBundle+Yep.swift */; }; + 50858EBB1C22487900EDE492 /* FeedBasicCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */; }; + 50858EBD1C22488100EDE492 /* FeedSocialWorkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */; }; 50894CF11AEA4726000981AF /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF01AEA4726000981AF /* SettingsViewController.swift */; }; 50894CF51AEA4A01000981AF /* SettingsUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */; }; 50894CF61AEA4A01000981AF /* SettingsUserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50894CF41AEA4A01000981AF /* SettingsUserCell.xib */; }; @@ -421,8 +421,6 @@ 501690161BFB18D20096C4F9 /* ChatLeftSocialWorkCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftSocialWorkCell.swift; path = Views/Cells/ChatLeftSocialWork/ChatLeftSocialWorkCell.swift; sourceTree = ""; }; 501690171BFB18D20096C4F9 /* ChatLeftSocialWorkCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ChatLeftSocialWorkCell.xib; path = Views/Cells/ChatLeftSocialWork/ChatLeftSocialWorkCell.xib; sourceTree = ""; }; 5016901B1BFB22180096C4F9 /* SocialWorkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocialWorkService.swift; path = Services/SocialWorkService.swift; sourceTree = ""; }; - 5016901D1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedSocialWorkCell.swift; path = Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift; sourceTree = ""; }; - 501690221BFEA6C30096C4F9 /* FeedBasicCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBasicCell.swift; path = Views/Cells/FeedBasic/FeedBasicCell.swift; sourceTree = ""; }; 501813251BA07CED0025873C /* Activities.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Activities.xcassets; sourceTree = ""; }; 5018132B1BA3CFEF0025873C /* WeChatActivity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WeChatActivity.swift; path = Activities/WeChatActivity.swift; sourceTree = ""; }; 5019F6301B39BFE00000D993 /* ConversationMoreView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationMoreView.swift; path = Views/ConversationMore/ConversationMoreView.swift; sourceTree = ""; }; @@ -545,6 +543,8 @@ 507F65F61B2EBC2700A35FDC /* MediaPreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MediaPreviewView.swift; path = Views/Media/MediaPreviewView.swift; sourceTree = ""; }; 5080EB1B1B93F43A006F3C2D /* PodsHelpYepViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PodsHelpYepViewController.swift; path = ViewControllers/PodsHelpYep/PodsHelpYepViewController.swift; sourceTree = ""; }; 5080EB1E1B93F932006F3C2D /* NSBundle+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSBundle+Yep.swift"; path = "Extensions/NSBundle+Yep.swift"; sourceTree = ""; }; + 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBasicCell.swift; path = Views/Cells/Feed/FeedBasicCell.swift; sourceTree = ""; }; + 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedSocialWorkCell.swift; path = Views/Cells/Feed/FeedSocialWorkCell.swift; sourceTree = ""; }; 50894CF01AEA4726000981AF /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsViewController.swift; path = ViewControllers/Settings/SettingsViewController.swift; sourceTree = ""; }; 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsUserCell.swift; path = Views/Cells/SettingsUser/SettingsUserCell.swift; sourceTree = ""; }; 50894CF41AEA4A01000981AF /* SettingsUserCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = SettingsUserCell.xib; path = Views/Cells/SettingsUser/SettingsUserCell.xib; sourceTree = ""; }; @@ -987,22 +987,6 @@ name = ChatLeftSocialWork; sourceTree = ""; }; - 501690211BFDCED10096C4F9 /* FeedSocialWork */ = { - isa = PBXGroup; - children = ( - 5016901D1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift */, - ); - name = FeedSocialWork; - sourceTree = ""; - }; - 501690241BFEA6CA0096C4F9 /* FeedBasic */ = { - isa = PBXGroup; - children = ( - 501690221BFEA6C30096C4F9 /* FeedBasicCell.swift */, - ); - name = FeedBasic; - sourceTree = ""; - }; 5019F62F1B39BFCB0000D993 /* ConversationMore */ = { isa = PBXGroup; children = ( @@ -1238,9 +1222,7 @@ 5064F65B1B0B14470089FAD4 /* AddFriendMore */, 50E348941B9063AD00A8E699 /* About */, 503807251BDA180A0068345E /* FeedSkillUsers */, - 501690241BFEA6CA0096C4F9 /* FeedBasic */, 50AFBF651BB4FC37007D19DA /* Feed */, - 501690211BFDCED10096C4F9 /* FeedSocialWork */, 50F5AF921BBBCC960033C9BC /* FeedMediaAdd */, 50F5AF9B1BBBD0310033C9BC /* FeedMedia */, 6A5632901BC90A4900397B53 /* DiscoverCardUser */, @@ -1974,7 +1956,9 @@ 50AFBF651BB4FC37007D19DA /* Feed */ = { isa = PBXGroup; children = ( + 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */, 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */, + 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, ); name = Feed; sourceTree = ""; @@ -2607,6 +2591,7 @@ 500EED981BF07A3000C6BABC /* ConversationViewController+Feed.swift in Sources */, 508F8FDE1B049ACF00461B0B /* InstagramMediaCell.swift in Sources */, 502AE5211AB71C7E005BD199 /* BorderButton.swift in Sources */, + 50858EBB1C22487900EDE492 /* FeedBasicCell.swift in Sources */, 84C959891B731FD20017D3ED /* ChatBaseCell.swift in Sources */, 502AE54E1AB93175005BD199 /* ProfileHeaderCell.swift in Sources */, 50A640E01B6F38CF0050E4A3 /* NotificationsViewController.swift in Sources */, @@ -2746,7 +2731,6 @@ 504F41251ACE2D1D00FBB19A /* SampleView.swift in Sources */, 50A640EC1B6F4E420050E4A3 /* DoNotDisturbPeriodViewController.swift in Sources */, 502AE5291AB81076005BD199 /* YepService.swift in Sources */, - 5016901F1BFDCECB0096C4F9 /* FeedSocialWorkCell.swift in Sources */, 50C090A41ADE46D500CC6389 /* RegisterSelectSkillsViewController.swift in Sources */, 50CC4FA21C1AC0EE00B6A263 /* UITableView+Yep.swift in Sources */, 502AE51E1AB712D2005BD199 /* RegisterPickNameViewController.swift in Sources */, @@ -2768,6 +2752,7 @@ 502B60641BD1208E00D9C17E /* CameraCell.swift in Sources */, 505082371C21377E00643CEB /* FeedVoiceContainerView.swift in Sources */, 6AB0DF5A1BE169000052BED1 /* ShareProfileView.swift in Sources */, + 50858EBD1C22488100EDE492 /* FeedSocialWorkCell.swift in Sources */, 502AE5351AB8649F005BD199 /* LoginByMobileViewController.swift in Sources */, 506BB7F91AE5069500C1A2A0 /* RegisterPickSkillsSelectSkillsTransitionManager.swift in Sources */, 50B8E6181B41340A00C17EA1 /* MessageLoadingProgressView.swift in Sources */, @@ -2811,7 +2796,6 @@ 840CD23C1B7B59D5000D2680 /* ShowStepViewController.swift in Sources */, 508F8FD01B01D04400461B0B /* GithubRepoCell.swift in Sources */, 50F2B97B1B2EEAF800F840CC /* NavigationTitleLabel.swift in Sources */, - 501690231BFEA6C30096C4F9 /* FeedBasicCell.swift in Sources */, 50A820241B969B0F007CD30E /* NSTimeZone+Yep.swift in Sources */, 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */, 504F415A1AD5028200FBB19A /* SkillCell.swift in Sources */, diff --git a/Yep/Views/Cells/FeedBasic/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift similarity index 100% rename from Yep/Views/Cells/FeedBasic/FeedBasicCell.swift rename to Yep/Views/Cells/Feed/FeedBasicCell.swift diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift similarity index 100% rename from Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift rename to Yep/Views/Cells/Feed/FeedSocialWorkCell.swift From dc6bf85d53d2d566164c53761bb61210b79a62d7 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 09:53:25 +0800 Subject: [PATCH 09/45] use FeedBasicCell; refactor heightOfFeed --- .../Feeds/FeedsViewController.swift | 15 ++++++++++++--- Yep/Views/Cells/Feed/FeedBasicCell.swift | 16 +++++++++++++++- Yep/Views/Cells/Feed/FeedCell.swift | 12 ++---------- Yep/Views/Cells/Feed/FeedSocialWorkCell.swift | 10 ++-------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index e3fcf78c..4466d2c3 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -107,6 +107,7 @@ class FeedsViewController: BaseViewController { #endif private let feedSkillUsersCellID = "FeedSkillUsersCell" + private let feedBasicCellID = "FeedBasicCell" private let feedCellID = "FeedCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" @@ -189,6 +190,8 @@ class FeedsViewController: BaseViewController { let height: CGFloat switch feed.kind { + case .Text: + height = FeedBasicCell.heightOfFeed(feed) case .GithubRepo, .DribbbleShot, .Audio, .Location: height = FeedSocialWorkCell.heightOfFeed(feed) default: @@ -280,9 +283,7 @@ class FeedsViewController: BaseViewController { feedsTableView.registerNib(UINib(nibName: feedSkillUsersCellID, bundle: nil), forCellReuseIdentifier: feedSkillUsersCellID) -// feedsTableView.registerNib(UINib(nibName: feedCellID, bundle: nil), forCellReuseIdentifier: feedCellID) -// feedsTableView.registerNib(UINib(nibName: feedSocialWorkCellID, bundle: nil), forCellReuseIdentifier: feedSocialWorkCellID) - + feedsTableView.registerClass(FeedBasicCell.self, forCellReuseIdentifier: feedBasicCellID) feedsTableView.registerClass(FeedCell.self, forCellReuseIdentifier: feedCellID) feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) @@ -798,6 +799,10 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { switch feed.kind { + case .Text: + let cell = tableView.dequeueReusableCellWithIdentifier(feedBasicCellID) as! FeedBasicCell + return cell + case .GithubRepo, .DribbbleShot, .Audio, .Location: let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell return cell @@ -874,6 +879,10 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { switch feed.kind { + case .Text: + + cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + case .GithubRepo, .DribbbleShot, .Audio, .Location: guard let cell = cell as? FeedSocialWorkCell else { diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 0b0f5e1e..fad40320 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -158,6 +158,20 @@ class FeedBasicCell: UITableViewCell { fatalError("init(coder:) has not been implemented") } + static let messageTextViewMaxWidth: CGFloat = { + let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 15) + return maxWidth + }() + + class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let rect = feed.body.boundingRectWithSize(CGSize(width: FeedBasicCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) + + let height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 + + return ceil(height) + } + override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) @@ -166,7 +180,7 @@ class FeedBasicCell: UITableViewCell { private func calHeightOfMessageTextView() { - let rect = messageTextView.text.boundingRectWithSize(CGSize(width: FeedCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) + let rect = messageTextView.text.boundingRectWithSize(CGSize(width: FeedBasicCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) messageTextView.frame.size.height = ceil(rect.height) } diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index 57a2c52a..b4391153 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -70,17 +70,9 @@ class FeedCell: FeedBasicCell { } } - static let messageTextViewMaxWidth: CGFloat = { - let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 15) - return maxWidth - }() + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - - class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - - let rect = feed.body.boundingRectWithSize(CGSize(width: FeedCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) - - var height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 + var height = super.heightOfFeed(feed) if let attachment = feed.attachment { if case let .Images(attachments) = attachment { diff --git a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift index db59add8..e08038fd 100644 --- a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift @@ -122,11 +122,6 @@ class FeedSocialWorkCell: FeedBasicCell { } } - static let messageTextViewMaxWidth: CGFloat = { - let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 15) - return maxWidth - }() - override func layoutSubviews() { super.layoutSubviews() @@ -167,11 +162,10 @@ class FeedSocialWorkCell: FeedBasicCell { // Configure the view for the selected state } - class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - let rect = feed.body.boundingRectWithSize(CGSize(width: FeedSocialWorkCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) + var height = super.heightOfFeed(feed) - var height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 switch feed.kind { case .GithubRepo: height += (80 + 15) From 09d9742c2bac1267c52f9eb6f0be4095087a6e84 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 10:23:39 +0800 Subject: [PATCH 10/45] add FeedBiggerImageCell --- Yep.xcodeproj/project.pbxproj | 4 + Yep/Configs/YepConfig.swift | 4 + Yep/Services/YepService.swift | 7 ++ .../Feeds/FeedsViewController.swift | 119 ++++++++++-------- .../Cells/Feed/FeedBiggerImageCell.swift | 48 +++++++ Yep/Views/Cells/FeedMedia/FeedMediaCell.swift | 2 +- 6 files changed, 132 insertions(+), 52 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedBiggerImageCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index e58d0e92..e62ed984 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -183,6 +183,7 @@ 5080EB1F1B93F932006F3C2D /* NSBundle+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080EB1E1B93F932006F3C2D /* NSBundle+Yep.swift */; }; 50858EBB1C22487900EDE492 /* FeedBasicCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */; }; 50858EBD1C22488100EDE492 /* FeedSocialWorkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */; }; + 50858EBF1C224DA900EDE492 /* FeedBiggerImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */; }; 50894CF11AEA4726000981AF /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF01AEA4726000981AF /* SettingsViewController.swift */; }; 50894CF51AEA4A01000981AF /* SettingsUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */; }; 50894CF61AEA4A01000981AF /* SettingsUserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50894CF41AEA4A01000981AF /* SettingsUserCell.xib */; }; @@ -545,6 +546,7 @@ 5080EB1E1B93F932006F3C2D /* NSBundle+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSBundle+Yep.swift"; path = "Extensions/NSBundle+Yep.swift"; sourceTree = ""; }; 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBasicCell.swift; path = Views/Cells/Feed/FeedBasicCell.swift; sourceTree = ""; }; 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedSocialWorkCell.swift; path = Views/Cells/Feed/FeedSocialWorkCell.swift; sourceTree = ""; }; + 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBiggerImageCell.swift; path = Views/Cells/Feed/FeedBiggerImageCell.swift; sourceTree = ""; }; 50894CF01AEA4726000981AF /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsViewController.swift; path = ViewControllers/Settings/SettingsViewController.swift; sourceTree = ""; }; 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsUserCell.swift; path = Views/Cells/SettingsUser/SettingsUserCell.swift; sourceTree = ""; }; 50894CF41AEA4A01000981AF /* SettingsUserCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = SettingsUserCell.xib; path = Views/Cells/SettingsUser/SettingsUserCell.xib; sourceTree = ""; }; @@ -1958,6 +1960,7 @@ children = ( 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */, 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */, + 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */, 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, ); name = Feed; @@ -2702,6 +2705,7 @@ 502280F81B1C3F2800E984EE /* FriendsInContactsViewController.swift in Sources */, 50E348921B9063A700A8E699 /* AboutCell.swift in Sources */, 508A08501C16B810000A3305 /* RecordButton.swift in Sources */, + 50858EBF1C224DA900EDE492 /* FeedBiggerImageCell.swift in Sources */, 508D17401ACCD2740092D666 /* YepButton.swift in Sources */, 5019F6311B39BFE00000D993 /* ConversationMoreView.swift in Sources */, 506BB7F51AE4E0A500C1A2A0 /* SkillAnnotationHeader.swift in Sources */, diff --git a/Yep/Configs/YepConfig.swift b/Yep/Configs/YepConfig.swift index 1fc05038..d9b80b4d 100644 --- a/Yep/Configs/YepConfig.swift +++ b/Yep/Configs/YepConfig.swift @@ -232,6 +232,10 @@ class YepConfig { ] } + struct FeedBiggerImageCell { + static let imageSize: CGSize = CGSize(width: 160, height: 160) + } + struct FeedView { static let textAttributes:[String: NSObject] = [ NSFontAttributeName: UIFont.feedMessageFont(), diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index a4475989..5dd6aa12 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2743,6 +2743,13 @@ struct DiscoveredFeed: Hashable { let attachment: Attachment? + var attachmentImagesCount: Int { + if let attachment = attachment, case let .Images(attachments) = attachment { + return attachments.count + } + return 0 + } + let distance: Double? let skill: Skill? diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 4466d2c3..4dcab6b5 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -109,6 +109,7 @@ class FeedsViewController: BaseViewController { private let feedSkillUsersCellID = "FeedSkillUsersCell" private let feedBasicCellID = "FeedBasicCell" private let feedCellID = "FeedCell" + private let feedBiggerImageCellID = "FeedBiggerImageCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" @@ -285,6 +286,7 @@ class FeedsViewController: BaseViewController { feedsTableView.registerClass(FeedBasicCell.self, forCellReuseIdentifier: feedBasicCellID) feedsTableView.registerClass(FeedCell.self, forCellReuseIdentifier: feedCellID) + feedsTableView.registerClass(FeedBiggerImageCell.self, forCellReuseIdentifier: feedBiggerImageCellID) feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -803,12 +805,21 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { let cell = tableView.dequeueReusableCellWithIdentifier(feedBasicCellID) as! FeedBasicCell return cell + case .Image: + if feed.attachmentImagesCount == 1 { + let cell = tableView.dequeueReusableCellWithIdentifier(feedBiggerImageCellID) as! FeedBiggerImageCell + return cell + } else { + let cell = tableView.dequeueReusableCellWithIdentifier(feedCellID) as! FeedCell + return cell + } + case .GithubRepo, .DribbbleShot, .Audio, .Location: let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell return cell default: - let cell = tableView.dequeueReusableCellWithIdentifier(feedCellID) as! FeedCell + let cell = tableView.dequeueReusableCellWithIdentifier(feedBasicCellID) as! FeedBasicCell return cell } @@ -883,14 +894,67 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + case .Image: + + if feed.attachmentImagesCount == 1 { + guard let cell = cell as? FeedBiggerImageCell else { + break + } + cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + + } else { + guard let cell = cell as? FeedCell else { + break + } + cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + + cell.tapMediaAction = { [weak self] transitionView, image, attachments, index in + + guard image != nil else { + return + } + + let vc = UIStoryboard(name: "MediaPreview", bundle: nil).instantiateViewControllerWithIdentifier("MediaPreviewViewController") as! MediaPreviewViewController + + vc.previewMedias = attachments.map({ PreviewMedia.AttachmentType(attachment: $0) }) + vc.startIndex = index + + let transitionView = transitionView + let frame = transitionView.convertRect(transitionView.frame, toView: self?.view) + vc.previewImageViewInitalFrame = frame + vc.bottomPreviewImage = image + + vc.transitionView = transitionView + + delay(0) { + transitionView.alpha = 0 // 放到下一个 Runloop 避免太快消失产生闪烁 + } + vc.afterDismissAction = { [weak self] in + transitionView.alpha = 1 + self?.view.window?.makeKeyAndVisible() + } + + mediaPreviewWindow.rootViewController = vc + mediaPreviewWindow.windowLevel = UIWindowLevelAlert - 1 + mediaPreviewWindow.makeKeyAndVisible() + + /* + let info: [String: AnyObject] = [ + "transitionView": transitionView, + "attachments": Box(value: attachments), + "index": index, + ] + self?.performSegueWithIdentifier("showFeedMedia", sender: info) + */ + } + } + case .GithubRepo, .DribbbleShot, .Audio, .Location: guard let cell = cell as? FeedSocialWorkCell else { break } - let feed = feeds[indexPath.item] - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) cell.tapGithubRepoLinkAction = { [weak self] URL in @@ -1000,54 +1064,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { } default: - - guard let cell = cell as? FeedCell else { - break - } - - let feed = feeds[indexPath.item] - - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) - - cell.tapMediaAction = { [weak self] transitionView, image, attachments, index in - - guard image != nil else { - return - } - - let vc = UIStoryboard(name: "MediaPreview", bundle: nil).instantiateViewControllerWithIdentifier("MediaPreviewViewController") as! MediaPreviewViewController - - vc.previewMedias = attachments.map({ PreviewMedia.AttachmentType(attachment: $0) }) - vc.startIndex = index - - let transitionView = transitionView - let frame = transitionView.convertRect(transitionView.frame, toView: self?.view) - vc.previewImageViewInitalFrame = frame - vc.bottomPreviewImage = image - - vc.transitionView = transitionView - - delay(0) { - transitionView.alpha = 0 // 放到下一个 Runloop 避免太快消失产生闪烁 - } - vc.afterDismissAction = { [weak self] in - transitionView.alpha = 1 - self?.view.window?.makeKeyAndVisible() - } - - mediaPreviewWindow.rootViewController = vc - mediaPreviewWindow.windowLevel = UIWindowLevelAlert - 1 - mediaPreviewWindow.makeKeyAndVisible() - - /* - let info: [String: AnyObject] = [ - "transitionView": transitionView, - "attachments": Box(value: attachments), - "index": index, - ] - self?.performSegueWithIdentifier("showFeedMedia", sender: info) - */ - } + break } case Section.LoadMore.rawValue: diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift new file mode 100644 index 00000000..dae75d0d --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -0,0 +1,48 @@ +// +// FeedBiggerImageCell.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit + +class FeedBiggerImageCell: FeedBasicCell { + + lazy var biggerImageView: UIImageView = { + let imageView = UIImageView() + imageView.contentMode = .ScaleAspectFill + imageView.clipsToBounds = true + imageView.frame = CGRect(origin: CGPoint(x: 65, y: 0), size: YepConfig.FeedBiggerImageCell.imageSize) + return imageView + }() + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(biggerImageView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { + super.configureWithFeed(feed, needShowSkill: needShowSkill) + + if let attachment = feed.attachment, case let .Images(attachments) = attachment, let onlyAttachment = attachments.first { + biggerImageView.yep_showActivityIndicatorWhenLoading = true + biggerImageView.yep_setImageOfAttachment(onlyAttachment, withSize: YepConfig.FeedBiggerImageCell.imageSize) + + biggerImageView.frame.origin.y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + } + } +} + diff --git a/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift b/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift index cb14b846..47b54425 100644 --- a/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift +++ b/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift @@ -19,7 +19,7 @@ class FeedMediaCell: UICollectionViewCell { super.awakeFromNib() imageView.backgroundColor = YepConfig.FeedMedia.backgroundColor - imageView.layer.minificationFilter = kCAFilterLinear +// imageView.layer.minificationFilter = kCAFilterLinear contentView.backgroundColor = UIColor.clearColor() } From ef0464479f5420ccc3efc78d5a45e358fd44cf0b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 10:32:18 +0800 Subject: [PATCH 11/45] set width for iconImageView & accessoryImageView --- Yep/Views/ContainerViews/FeedGithubRepoContainerView.swift | 5 ++++- Yep/Views/ContainerViews/LinkContainerView.swift | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Yep/Views/ContainerViews/FeedGithubRepoContainerView.swift b/Yep/Views/ContainerViews/FeedGithubRepoContainerView.swift index 5013a7a6..8e0e68f8 100644 --- a/Yep/Views/ContainerViews/FeedGithubRepoContainerView.swift +++ b/Yep/Views/ContainerViews/FeedGithubRepoContainerView.swift @@ -68,11 +68,14 @@ class FeedGithubRepoContainerView: UIView { "accessoryImageView": accessoryImageView, ] - let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[iconImageView]-10-[nameLabel]-5-[accessoryImageView]-10-|", options: [], metrics: nil, views: views) + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[iconImageView(16)]-10-[nameLabel]-5-[accessoryImageView(8)]-10-|", options: [], metrics: nil, views: views) iconImageView.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal) accessoryImageView.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal) + iconImageView.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal) + accessoryImageView.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal) + let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:[nameLabel]-3-[descriptionLabel]", options: [.AlignAllLeading, .AlignAllTrailing], metrics: nil, views: views) let iconImageViewCenterY = NSLayoutConstraint(item: iconImageView, attribute: .CenterY, relatedBy: .Equal, toItem: nameLabel, attribute: .CenterY, multiplier: 1.0, constant: 0) diff --git a/Yep/Views/ContainerViews/LinkContainerView.swift b/Yep/Views/ContainerViews/LinkContainerView.swift index e84419aa..ce0cfe09 100644 --- a/Yep/Views/ContainerViews/LinkContainerView.swift +++ b/Yep/Views/ContainerViews/LinkContainerView.swift @@ -58,10 +58,7 @@ class LinkContainerView: UIView { "accessoryImageView": accessoryImageView, ] - let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[iconImageView]-10-[textLabel]-5-[accessoryImageView]-10-|", options: [.AlignAllCenterY], metrics: nil, views: views) - - iconImageView.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal) - accessoryImageView.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal) + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[iconImageView(20)]-10-[textLabel]-5-[accessoryImageView(8)]-10-|", options: [.AlignAllCenterY], metrics: nil, views: views) let iconImageViewCenterY = NSLayoutConstraint(item: iconImageView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: 0) From 66b9802a59d7b83a062e999803e02c2cb5d167a2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 10:58:54 +0800 Subject: [PATCH 12/45] tapMediaAction for FeedBiggerImageCell --- Yep/Services/YepService.swift | 11 ++- .../Feeds/FeedsViewController.swift | 81 +++++++++---------- Yep/Views/Cells/Feed/FeedBasicCell.swift | 5 +- .../Cells/Feed/FeedBiggerImageCell.swift | 21 ++++- Yep/Views/Cells/Feed/FeedSocialWorkCell.swift | 4 - 5 files changed, 70 insertions(+), 52 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 5dd6aa12..7b384083 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2743,11 +2743,16 @@ struct DiscoveredFeed: Hashable { let attachment: Attachment? - var attachmentImagesCount: Int { + var imageAttachments: [DiscoveredAttachment]? { if let attachment = attachment, case let .Images(attachments) = attachment { - return attachments.count + return attachments } - return 0 + + return nil + } + + var imageAttachmentsCount: Int { + return imageAttachments?.count ?? 0 } let distance: Double? diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 4dcab6b5..8c93bb5b 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -806,7 +806,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return cell case .Image: - if feed.attachmentImagesCount == 1 { + if feed.imageAttachmentsCount == 1 { let cell = tableView.dequeueReusableCellWithIdentifier(feedBiggerImageCellID) as! FeedBiggerImageCell return cell } else { @@ -896,57 +896,54 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { case .Image: - if feed.attachmentImagesCount == 1 { + let tapMediaAction: (transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void = { [weak self] transitionView, image, attachments, index in + + guard image != nil else { + return + } + + let vc = UIStoryboard(name: "MediaPreview", bundle: nil).instantiateViewControllerWithIdentifier("MediaPreviewViewController") as! MediaPreviewViewController + + vc.previewMedias = attachments.map({ PreviewMedia.AttachmentType(attachment: $0) }) + vc.startIndex = index + + let transitionView = transitionView + let frame = transitionView.convertRect(transitionView.bounds, toView: self?.view) + vc.previewImageViewInitalFrame = frame + vc.bottomPreviewImage = image + + vc.transitionView = transitionView + + delay(0) { + transitionView.alpha = 0 // 放到下一个 Runloop 避免太快消失产生闪烁 + } + vc.afterDismissAction = { [weak self] in + transitionView.alpha = 1 + self?.view.window?.makeKeyAndVisible() + } + + mediaPreviewWindow.rootViewController = vc + mediaPreviewWindow.windowLevel = UIWindowLevelAlert - 1 + mediaPreviewWindow.makeKeyAndVisible() + } + + if feed.imageAttachmentsCount == 1 { guard let cell = cell as? FeedBiggerImageCell else { break } + cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + cell.tapMediaAction = tapMediaAction + } else { guard let cell = cell as? FeedCell else { break } + cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) - cell.tapMediaAction = { [weak self] transitionView, image, attachments, index in - - guard image != nil else { - return - } - - let vc = UIStoryboard(name: "MediaPreview", bundle: nil).instantiateViewControllerWithIdentifier("MediaPreviewViewController") as! MediaPreviewViewController - - vc.previewMedias = attachments.map({ PreviewMedia.AttachmentType(attachment: $0) }) - vc.startIndex = index - - let transitionView = transitionView - let frame = transitionView.convertRect(transitionView.frame, toView: self?.view) - vc.previewImageViewInitalFrame = frame - vc.bottomPreviewImage = image - - vc.transitionView = transitionView - - delay(0) { - transitionView.alpha = 0 // 放到下一个 Runloop 避免太快消失产生闪烁 - } - vc.afterDismissAction = { [weak self] in - transitionView.alpha = 1 - self?.view.window?.makeKeyAndVisible() - } - - mediaPreviewWindow.rootViewController = vc - mediaPreviewWindow.windowLevel = UIWindowLevelAlert - 1 - mediaPreviewWindow.makeKeyAndVisible() - - /* - let info: [String: AnyObject] = [ - "transitionView": transitionView, - "attachments": Box(value: attachments), - "index": index, - ] - self?.performSegueWithIdentifier("showFeedMedia", sender: info) - */ - } + cell.tapMediaAction = tapMediaAction } case .GithubRepo, .DribbbleShot, .Audio, .Location: @@ -977,7 +974,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { vc.startIndex = 0 let transitionView = transitionView - let frame = transitionView.convertRect(transitionView.frame, toView: self?.view) + let frame = transitionView.convertRect(transitionView.bounds, toView: self?.view) vc.previewImageViewInitalFrame = frame vc.bottomPreviewImage = image diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index fad40320..cef8ee85 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -123,8 +123,7 @@ class FeedBasicCell: UITableViewCell { return imageView }() - - + var feed: DiscoveredFeed? var tapAvatarAction: (UITableViewCell -> Void)? var tapSkillAction: (UITableViewCell -> Void)? @@ -187,6 +186,8 @@ class FeedBasicCell: UITableViewCell { func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { + self.feed = feed + messageTextView.text = "\u{200B}\(feed.body)" // ref http://stackoverflow.com/a/25994821 calHeightOfMessageTextView() diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index dae75d0d..7980c9dd 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -10,6 +10,8 @@ import UIKit class FeedBiggerImageCell: FeedBasicCell { + var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + lazy var biggerImageView: UIImageView = { let imageView = UIImageView() imageView.contentMode = .ScaleAspectFill @@ -22,6 +24,10 @@ class FeedBiggerImageCell: FeedBasicCell { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(biggerImageView) + + biggerImageView.userInteractionEnabled = true + let tap = UITapGestureRecognizer(target: self, action: "tap:") + addGestureRecognizer(tap) } required init?(coder aDecoder: NSCoder) { @@ -34,15 +40,28 @@ class FeedBiggerImageCell: FeedBasicCell { // Configure the view for the selected state } + override func prepareForReuse() { + super.prepareForReuse() + + biggerImageView.image = nil + } + override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { super.configureWithFeed(feed, needShowSkill: needShowSkill) - if let attachment = feed.attachment, case let .Images(attachments) = attachment, let onlyAttachment = attachments.first { + if let onlyAttachment = feed.imageAttachments?.first { biggerImageView.yep_showActivityIndicatorWhenLoading = true biggerImageView.yep_setImageOfAttachment(onlyAttachment, withSize: YepConfig.FeedBiggerImageCell.imageSize) biggerImageView.frame.origin.y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 } } + + @objc private func tap(sender: UITapGestureRecognizer) { + + if let attachments = feed?.imageAttachments { + tapMediaAction?(transitionView: biggerImageView, image: biggerImageView.image, attachments: attachments, index: 0) + } + } } diff --git a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift index e08038fd..a4e88e9e 100644 --- a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift @@ -85,8 +85,6 @@ class FeedSocialWorkCell: FeedBasicCell { return imageView }() - var feed: DiscoveredFeed? - var tapGithubRepoLinkAction: (NSURL -> Void)? var tapDribbbleShotLinkAction: (NSURL -> Void)? var tapDribbbleShotMediaAction: ((transitionView: UIView, image: UIImage?, imageURL: NSURL, linkURL: NSURL) -> Void)? @@ -185,8 +183,6 @@ class FeedSocialWorkCell: FeedBasicCell { override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { super.configureWithFeed(feed, needShowSkill: needShowSkill) - self.feed = feed - if let accountName = feed.kind.accountName, socialAccount = SocialAccount(rawValue: accountName) { From 4dea8e487f6e2368259b09865d92fd7b7d8a359e Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 11:06:00 +0800 Subject: [PATCH 13/45] border --- Yep/Views/Cells/Feed/FeedBiggerImageCell.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index 7980c9dd..9c2e3b24 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -17,6 +17,8 @@ class FeedBiggerImageCell: FeedBasicCell { imageView.contentMode = .ScaleAspectFill imageView.clipsToBounds = true imageView.frame = CGRect(origin: CGPoint(x: 65, y: 0), size: YepConfig.FeedBiggerImageCell.imageSize) + imageView.layer.borderColor = UIColor.yepBorderColor().CGColor + imageView.layer.borderWidth = 1 return imageView }() From fc407e9bd2bba906ac407dc57e291548246514ad Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 11:17:52 +0800 Subject: [PATCH 14/45] floor newSize in scaleToMinSideLength --- Yep/Extensions/UIImage+Yep.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Yep/Extensions/UIImage+Yep.swift b/Yep/Extensions/UIImage+Yep.swift index 8cc2a2e8..7710498c 100644 --- a/Yep/Extensions/UIImage+Yep.swift +++ b/Yep/Extensions/UIImage+Yep.swift @@ -83,7 +83,7 @@ extension UIImage { let newHeight = pixelSideLength let newWidth = (pixelSideLength / pixelHeight) * pixelWidth - newSize = CGSize(width: newWidth, height: newHeight) + newSize = CGSize(width: floor(newWidth), height: floor(newHeight)) } else { @@ -93,16 +93,15 @@ extension UIImage { let newWidth = pixelSideLength let newHeight = (pixelSideLength / pixelWidth) * pixelHeight - newSize = CGSize(width: newWidth, height: newHeight) + newSize = CGSize(width: floor(newWidth), height: floor(newHeight)) } - if scale == UIScreen.mainScreen().scale { - let newSize = CGSize(width: newSize.width / scale, height: newSize.height / scale) - //println("newSize: \(newSize)") + let newSize = CGSize(width: floor(newSize.width / scale), height: floor(newSize.height / scale)) + //println("A scaleToMinSideLength newSize: \(newSize)") UIGraphicsBeginImageContextWithOptions(newSize, false, scale) - let rect = CGRectMake(0, 0, floor(newSize.width), floor(newSize.height)) + let rect = CGRectMake(0, 0, newSize.width, newSize.height) self.drawInRect(rect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() @@ -114,9 +113,9 @@ extension UIImage { return self } else { - //println("newSize: \(newSize)") + //println("B scaleToMinSideLength newSize: \(newSize)") UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) - let rect = CGRectMake(0, 0, floor(newSize.width), floor(newSize.height)) + let rect = CGRectMake(0, 0, newSize.width, newSize.height) self.drawInRect(rect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() From 462dcdc66cd70fe7f54d463ee9ae3470f13aa1a6 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 11:22:05 +0800 Subject: [PATCH 15/45] fix tap biggerImageView --- Yep/Views/Cells/Feed/FeedBiggerImageCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index 9c2e3b24..0fb2a7cb 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -29,7 +29,7 @@ class FeedBiggerImageCell: FeedBasicCell { biggerImageView.userInteractionEnabled = true let tap = UITapGestureRecognizer(target: self, action: "tap:") - addGestureRecognizer(tap) + biggerImageView.addGestureRecognizer(tap) } required init?(coder aDecoder: NSCoder) { From 33a5d4e0b7fb13c26ab91085d967f75e2ce9d7c0 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 13:12:27 +0800 Subject: [PATCH 16/45] add FeedNormalImagesCell --- Yep.xcodeproj/project.pbxproj | 4 + Yep/Configs/YepConfig.swift | 4 + .../Feeds/FeedsViewController.swift | 17 +++ .../Cells/Feed/FeedBiggerImageCell.swift | 9 +- .../Cells/Feed/FeedNormalImagesCell.swift | 117 ++++++++++++++++++ 5 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedNormalImagesCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index e62ed984..ba384b0c 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -302,6 +302,7 @@ 50E3488E1B905C0100A8E699 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E3488D1B905C0100A8E699 /* AboutViewController.swift */; }; 50E348921B9063A700A8E699 /* AboutCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E348901B9063A700A8E699 /* AboutCell.swift */; }; 50E348931B9063A700A8E699 /* AboutCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50E348911B9063A700A8E699 /* AboutCell.xib */; }; + 50E392BC1C22752C00C0CECB /* FeedNormalImagesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -665,6 +666,7 @@ 50E3488D1B905C0100A8E699 /* AboutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AboutViewController.swift; path = ViewControllers/About/AboutViewController.swift; sourceTree = ""; }; 50E348901B9063A700A8E699 /* AboutCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AboutCell.swift; path = Views/Cells/About/AboutCell.swift; sourceTree = ""; }; 50E348911B9063A700A8E699 /* AboutCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = AboutCell.xib; path = Views/Cells/About/AboutCell.xib; sourceTree = ""; }; + 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedNormalImagesCell.swift; path = Views/Cells/Feed/FeedNormalImagesCell.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1961,6 +1963,7 @@ 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */, 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */, 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */, + 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */, 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, ); name = Feed; @@ -2644,6 +2647,7 @@ 502C24831C1034000074A1BA /* UIImageView+Yep.swift in Sources */, 5080EB1C1B93F43A006F3C2D /* PodsHelpYepViewController.swift in Sources */, 0A1CAC731AFA526200826B45 /* SkillHomeSectionButton.swift in Sources */, + 50E392BC1C22752C00C0CECB /* FeedNormalImagesCell.swift in Sources */, 50B38FCC1B6B37F00064C132 /* FeedbackViewController.swift in Sources */, 507F65F71B2EBC2700A35FDC /* MediaPreviewView.swift in Sources */, 501690181BFB18D20096C4F9 /* ChatLeftSocialWorkCell.swift in Sources */, diff --git a/Yep/Configs/YepConfig.swift b/Yep/Configs/YepConfig.swift index d9b80b4d..34caeaff 100644 --- a/Yep/Configs/YepConfig.swift +++ b/Yep/Configs/YepConfig.swift @@ -236,6 +236,10 @@ class YepConfig { static let imageSize: CGSize = CGSize(width: 160, height: 160) } + struct FeedNormalImagesCell { + static let imageSize: CGSize = CGSize(width: 80, height: 80) + } + struct FeedView { static let textAttributes:[String: NSObject] = [ NSFontAttributeName: UIFont.feedMessageFont(), diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 8c93bb5b..17c8b6ac 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -110,6 +110,7 @@ class FeedsViewController: BaseViewController { private let feedBasicCellID = "FeedBasicCell" private let feedCellID = "FeedCell" private let feedBiggerImageCellID = "FeedBiggerImageCell" + private let feedNormalImagesCellID = "FeedNormalImagesCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" @@ -287,6 +288,7 @@ class FeedsViewController: BaseViewController { feedsTableView.registerClass(FeedBasicCell.self, forCellReuseIdentifier: feedBasicCellID) feedsTableView.registerClass(FeedCell.self, forCellReuseIdentifier: feedCellID) feedsTableView.registerClass(FeedBiggerImageCell.self, forCellReuseIdentifier: feedBiggerImageCellID) + feedsTableView.registerClass(FeedNormalImagesCell.self, forCellReuseIdentifier: feedNormalImagesCellID) feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -809,6 +811,11 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { if feed.imageAttachmentsCount == 1 { let cell = tableView.dequeueReusableCellWithIdentifier(feedBiggerImageCellID) as! FeedBiggerImageCell return cell + + } else if feed.imageAttachmentsCount <= 3 { + let cell = tableView.dequeueReusableCellWithIdentifier(feedNormalImagesCellID) as! FeedNormalImagesCell + return cell + } else { let cell = tableView.dequeueReusableCellWithIdentifier(feedCellID) as! FeedCell return cell @@ -936,6 +943,16 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.tapMediaAction = tapMediaAction + } else if feed.imageAttachmentsCount <= 3 { + + guard let cell = cell as? FeedNormalImagesCell else { + break + } + + cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + + cell.tapMediaAction = tapMediaAction + } else { guard let cell = cell as? FeedCell else { break diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index 0fb2a7cb..88940545 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -19,6 +19,11 @@ class FeedBiggerImageCell: FeedBasicCell { imageView.frame = CGRect(origin: CGPoint(x: 65, y: 0), size: YepConfig.FeedBiggerImageCell.imageSize) imageView.layer.borderColor = UIColor.yepBorderColor().CGColor imageView.layer.borderWidth = 1 + + imageView.userInteractionEnabled = true + let tap = UITapGestureRecognizer(target: self, action: "tap:") + imageView.addGestureRecognizer(tap) + return imageView }() @@ -26,10 +31,6 @@ class FeedBiggerImageCell: FeedBasicCell { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(biggerImageView) - - biggerImageView.userInteractionEnabled = true - let tap = UITapGestureRecognizer(target: self, action: "tap:") - biggerImageView.addGestureRecognizer(tap) } required init?(coder aDecoder: NSCoder) { diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift new file mode 100644 index 00000000..612c3d24 --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -0,0 +1,117 @@ +// +// FeedNormalImagesCell.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit + +class FeedNormalImagesCell: FeedBasicCell { + + var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + + private func createImageViewWithFrame(frame: CGRect) -> UIImageView { + let imageView = UIImageView() + imageView.contentMode = .ScaleAspectFill + imageView.clipsToBounds = true + imageView.frame = CGRect(origin: CGPoint(x: 65, y: 0), size: YepConfig.FeedNormalImagesCell.imageSize) + imageView.frame = frame + imageView.layer.borderColor = UIColor.yepBorderColor().CGColor + imageView.layer.borderWidth = 1 + + imageView.userInteractionEnabled = true + let tap = UITapGestureRecognizer(target: self, action: "tap:") + imageView.addGestureRecognizer(tap) + + return imageView + } + + lazy var imageView1: UIImageView = { + let x = 65 + let frame = CGRect(origin: CGPoint(x: x, y: 0), size: YepConfig.FeedNormalImagesCell.imageSize) + let imageView = self.createImageViewWithFrame(frame) + + return imageView + }() + + lazy var imageView2: UIImageView = { + let x = 65 + (YepConfig.FeedNormalImagesCell.imageSize.width + 5) + let frame = CGRect(origin: CGPoint(x: x, y: 0), size: YepConfig.FeedNormalImagesCell.imageSize) + let imageView = self.createImageViewWithFrame(frame) + + return imageView + }() + + lazy var imageView3: UIImageView = { + let x = 65 + (YepConfig.FeedNormalImagesCell.imageSize.width + 5) * 2 + let frame = CGRect(origin: CGPoint(x: 65, y: 0), size: YepConfig.FeedNormalImagesCell.imageSize) + let imageView = self.createImageViewWithFrame(frame) + + return imageView + }() + + var imageViews: [UIImageView] = [] + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(imageView1) + contentView.addSubview(imageView2) + contentView.addSubview(imageView3) + + imageViews = [imageView1, imageView2, imageView3] + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override func prepareForReuse() { + super.prepareForReuse() + + imageView1.image = nil + imageView2.image = nil + imageView3.image = nil + } + + override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { + super.configureWithFeed(feed, needShowSkill: needShowSkill) + + if let attachments = feed.imageAttachments { + + for i in 0.. Date: Thu, 17 Dec 2015 13:20:11 +0800 Subject: [PATCH 17/45] refactor FeedTapMediaAction --- .../Feeds/FeedsViewController.swift | 2 +- .../Cells/Feed/FeedBiggerImageCell.swift | 2 +- Yep/Views/Cells/Feed/FeedCell.swift | 10 +++---- .../Cells/Feed/FeedNormalImagesCell.swift | 2 +- Yep/Views/Cells/Feed/FeedSocialWorkCell.swift | 26 ------------------- 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 17c8b6ac..d1cc933c 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -903,7 +903,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { case .Image: - let tapMediaAction: (transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void = { [weak self] transitionView, image, attachments, index in + let tapMediaAction: FeedTapMediaAction = { [weak self] transitionView, image, attachments, index in guard image != nil else { return diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index 88940545..090bfb2d 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -10,7 +10,7 @@ import UIKit class FeedBiggerImageCell: FeedBasicCell { - var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + var tapMediaAction: FeedTapMediaAction? lazy var biggerImageView: UIImageView = { let imageView = UIImageView() diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index b4391153..262c2400 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -14,13 +14,10 @@ let feedAttachmentBiggerImageSize = CGSize(width: 160, height: 160) private let feedMediaCellID = "FeedMediaCell" private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width +typealias FeedTapMediaAction = (transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void + class FeedCell: FeedBasicCell { - //@IBOutlet weak var mediaCollectionView: UICollectionView! - //@IBOutlet weak var collectionViewHeight: NSLayoutConstraint! - - //@IBOutlet weak var leftBottomLabelTopConstraint: NSLayoutConstraint! - lazy var mediaCollectionView: UICollectionView = { let layout = UICollectionViewFlowLayout() @@ -60,8 +57,7 @@ class FeedCell: FeedBasicCell { return collectionView }() - - var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + var tapMediaAction: FeedTapMediaAction? var attachments = [DiscoveredAttachment]() { didSet { diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index 612c3d24..d5a62789 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -10,7 +10,7 @@ import UIKit class FeedNormalImagesCell: FeedBasicCell { - var tapMediaAction: ((transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void)? + var tapMediaAction: FeedTapMediaAction? private func createImageViewWithFrame(frame: CGRect) -> UIImageView { let imageView = UIImageView() diff --git a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift index a4e88e9e..ff03b8c1 100644 --- a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift @@ -17,25 +17,6 @@ private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width class FeedSocialWorkCell: FeedBasicCell { - /* - @IBOutlet weak var logoImageView: UIImageView! - @IBOutlet weak var logoImageViewTrailingConstraint: NSLayoutConstraint! - - @IBOutlet weak var socialWorkContainerView: UIView! - - @IBOutlet weak var mediaContainerView: FeedMediaContainerView! - - @IBOutlet weak var githubRepoContainerView: FeedGithubRepoContainerView! - - @IBOutlet weak var voiceContainerView: FeedVoiceContainerView! - @IBOutlet weak var voiceContainerViewWidthConstraint: NSLayoutConstraint! - - @IBOutlet weak var locationContainerView: FeedLocationContainerView! - - @IBOutlet weak var socialWorkBorderImageView: UIImageView! - @IBOutlet weak var socialWorkContainerViewHeightConstraint: NSLayoutConstraint! - */ - lazy var logoImageView: UIImageView = { let imageView = UIImageView() imageView.image = UIImage(named: "icon_github") @@ -73,13 +54,6 @@ class FeedSocialWorkCell: FeedBasicCell { return imageView }() - - - - - - - lazy var halfMaskImageView: UIImageView = { let imageView = UIImageView(image: UIImage(named: "social_media_image_mask")) return imageView From 0cca79402ed862d4412de06c2dcf4e4752f8b24a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 13:27:36 +0800 Subject: [PATCH 18/45] heightOfFeed for FeedBiggerImageCell & FeedNormalImagesCell --- .../Feeds/FeedsViewController.swift | 18 ++++++++++++++++-- Yep/Views/Cells/Feed/FeedBiggerImageCell.swift | 7 +++++++ .../Cells/Feed/FeedNormalImagesCell.swift | 7 +++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index d1cc933c..9fe9cb2d 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -189,15 +189,29 @@ class FeedsViewController: BaseViewController { return height } else { - let height: CGFloat + switch feed.kind { + case .Text: height = FeedBasicCell.heightOfFeed(feed) + + case .Image: + if feed.imageAttachmentsCount == 1 { + height = FeedBiggerImageCell.heightOfFeed(feed) + + } else if feed.imageAttachmentsCount <= 3 { + height = FeedNormalImagesCell.heightOfFeed(feed) + + } else { + height = FeedCell.heightOfFeed(feed) + } + case .GithubRepo, .DribbbleShot, .Audio, .Location: height = FeedSocialWorkCell.heightOfFeed(feed) + default: - height = FeedCell.heightOfFeed(feed) + height = FeedBasicCell.heightOfFeed(feed) } if !key.isEmpty { diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index 090bfb2d..ee90fd3f 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -27,6 +27,13 @@ class FeedBiggerImageCell: FeedBasicCell { return imageView }() + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let height = super.heightOfFeed(feed) + YepConfig.FeedBiggerImageCell.imageSize.height + 15 + + return ceil(height) + } + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index d5a62789..5295aa0c 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -52,6 +52,13 @@ class FeedNormalImagesCell: FeedBasicCell { return imageView }() + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let height = super.heightOfFeed(feed) + YepConfig.FeedNormalImagesCell.imageSize.height + 15 + + return ceil(height) + } + var imageViews: [UIImageView] = [] override init(style: UITableViewCellStyle, reuseIdentifier: String?) { From 9a89c64c99ac00a665e5ecd3bb58ef84bb0fb403 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 13:51:19 +0800 Subject: [PATCH 19/45] rename FeedAnyImagesCell --- Yep.xcodeproj/project.pbxproj | 8 +++--- Yep/Caches/ImageCache.swift | 2 +- .../Feeds/FeedsViewController.swift | 10 +++---- ...FeedCell.swift => FeedAnyImagesCell.swift} | 28 ++++++------------- 4 files changed, 18 insertions(+), 30 deletions(-) rename Yep/Views/Cells/Feed/{FeedCell.swift => FeedAnyImagesCell.swift} (84%) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index ba384b0c..e524ab34 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -316,7 +316,7 @@ 50F5AF831BBA67060033C9BC /* NewFeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF821BBA67060033C9BC /* NewFeedViewController.swift */; }; 50F5AF861BBA676D0033C9BC /* NewFeed.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF851BBA676D0033C9BC /* NewFeed.storyboard */; }; 50F5AF881BBBB2AE0033C9BC /* HorizontalLineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF871BBBB2AE0033C9BC /* HorizontalLineView.swift */; }; - 50F5AF8C1BBBB64C0033C9BC /* FeedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */; }; + 50F5AF8C1BBBB64C0033C9BC /* FeedAnyImagesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF8A1BBBB64C0033C9BC /* FeedAnyImagesCell.swift */; }; 50F5AF951BBBCDA30033C9BC /* FeedMediaAddCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF931BBBCDA30033C9BC /* FeedMediaAddCell.swift */; }; 50F5AF961BBBCDA30033C9BC /* FeedMediaAddCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */; }; 50F5AF991BBBD02A0033C9BC /* FeedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */; }; @@ -680,7 +680,7 @@ 50F5AF821BBA67060033C9BC /* NewFeedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NewFeedViewController.swift; path = ViewControllers/NewFeed/NewFeedViewController.swift; sourceTree = ""; }; 50F5AF851BBA676D0033C9BC /* NewFeed.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = NewFeed.storyboard; path = ViewControllers/NewFeed/NewFeed.storyboard; sourceTree = ""; }; 50F5AF871BBBB2AE0033C9BC /* HorizontalLineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HorizontalLineView.swift; path = Views/HorizontalLine/HorizontalLineView.swift; sourceTree = ""; }; - 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedCell.swift; path = Views/Cells/Feed/FeedCell.swift; sourceTree = ""; }; + 50F5AF8A1BBBB64C0033C9BC /* FeedAnyImagesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedAnyImagesCell.swift; path = Views/Cells/Feed/FeedAnyImagesCell.swift; sourceTree = ""; }; 50F5AF931BBBCDA30033C9BC /* FeedMediaAddCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaAddCell.swift; path = Views/Cells/FeedMediaAdd/FeedMediaAddCell.swift; sourceTree = ""; }; 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaAddCell.xib; path = Views/Cells/FeedMediaAdd/FeedMediaAddCell.xib; sourceTree = ""; }; 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaCell.swift; path = Views/Cells/FeedMedia/FeedMediaCell.swift; sourceTree = ""; }; @@ -1961,9 +1961,9 @@ isa = PBXGroup; children = ( 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */, - 50F5AF8A1BBBB64C0033C9BC /* FeedCell.swift */, 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */, 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */, + 50F5AF8A1BBBB64C0033C9BC /* FeedAnyImagesCell.swift */, 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, ); name = Feed; @@ -2750,7 +2750,7 @@ 505082351C212E9200643CEB /* FeedLocationContainerView.swift in Sources */, 0A3E60671ACCAECE003DC853 /* YepLocationService.swift in Sources */, 6A8215051BCBE5170011F36C /* MiniCardSkillLayout.swift in Sources */, - 50F5AF8C1BBBB64C0033C9BC /* FeedCell.swift in Sources */, + 50F5AF8C1BBBB64C0033C9BC /* FeedAnyImagesCell.swift in Sources */, 50894CF11AEA4726000981AF /* SettingsViewController.swift in Sources */, 5023DE2A1AB685BA00B3EE96 /* ContactsViewController.swift in Sources */, 50CDBE491ACBAD3200459CE0 /* ChatLeftImageCell.swift in Sources */, diff --git a/Yep/Caches/ImageCache.swift b/Yep/Caches/ImageCache.swift index 017146b1..11418896 100644 --- a/Yep/Caches/ImageCache.swift +++ b/Yep/Caches/ImageCache.swift @@ -94,7 +94,7 @@ class ImageCache { let finalImage = storeImage.decodedImage() - println("Image Decode size \(storeImage.size)") + //println("Image Decode size \(storeImage.size)") dispatch_async(dispatch_get_main_queue()) { completion(url: attachmentURL, image: finalImage, cacheType: .None) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 9fe9cb2d..166c1d34 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -108,9 +108,9 @@ class FeedsViewController: BaseViewController { private let feedSkillUsersCellID = "FeedSkillUsersCell" private let feedBasicCellID = "FeedBasicCell" - private let feedCellID = "FeedCell" private let feedBiggerImageCellID = "FeedBiggerImageCell" private let feedNormalImagesCellID = "FeedNormalImagesCell" + private let feedAnyImagesCellID = "FeedAnyImagesCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" @@ -204,7 +204,7 @@ class FeedsViewController: BaseViewController { height = FeedNormalImagesCell.heightOfFeed(feed) } else { - height = FeedCell.heightOfFeed(feed) + height = FeedAnyImagesCell.heightOfFeed(feed) } case .GithubRepo, .DribbbleShot, .Audio, .Location: @@ -300,9 +300,9 @@ class FeedsViewController: BaseViewController { feedsTableView.registerNib(UINib(nibName: feedSkillUsersCellID, bundle: nil), forCellReuseIdentifier: feedSkillUsersCellID) feedsTableView.registerClass(FeedBasicCell.self, forCellReuseIdentifier: feedBasicCellID) - feedsTableView.registerClass(FeedCell.self, forCellReuseIdentifier: feedCellID) feedsTableView.registerClass(FeedBiggerImageCell.self, forCellReuseIdentifier: feedBiggerImageCellID) feedsTableView.registerClass(FeedNormalImagesCell.self, forCellReuseIdentifier: feedNormalImagesCellID) + feedsTableView.registerClass(FeedAnyImagesCell.self, forCellReuseIdentifier: feedAnyImagesCellID) feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -831,7 +831,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return cell } else { - let cell = tableView.dequeueReusableCellWithIdentifier(feedCellID) as! FeedCell + let cell = tableView.dequeueReusableCellWithIdentifier(feedAnyImagesCellID) as! FeedAnyImagesCell return cell } @@ -968,7 +968,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.tapMediaAction = tapMediaAction } else { - guard let cell = cell as? FeedCell else { + guard let cell = cell as? FeedAnyImagesCell else { break } diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift similarity index 84% rename from Yep/Views/Cells/Feed/FeedCell.swift rename to Yep/Views/Cells/Feed/FeedAnyImagesCell.swift index 262c2400..71fd33e6 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift @@ -1,5 +1,5 @@ // -// FeedCell.swift +// FeedAnyImagesCell.swift // Yep // // Created by nixzhu on 15/9/30. @@ -8,15 +8,15 @@ import UIKit -let feedAttachmentImageSize = CGSize(width: 80, height: 80) -let feedAttachmentBiggerImageSize = CGSize(width: 160, height: 160) +let feedAttachmentImageSize = YepConfig.FeedNormalImagesCell.imageSize +let feedAttachmentBiggerImageSize = YepConfig.FeedBiggerImageCell.imageSize private let feedMediaCellID = "FeedMediaCell" private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width typealias FeedTapMediaAction = (transitionView: UIView, image: UIImage?, attachments: [DiscoveredAttachment], index: Int) -> Void -class FeedCell: FeedBasicCell { +class FeedAnyImagesCell: FeedBasicCell { lazy var mediaCollectionView: UICollectionView = { @@ -68,14 +68,7 @@ class FeedCell: FeedBasicCell { override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - var height = super.heightOfFeed(feed) - - if let attachment = feed.attachment { - if case let .Images(attachments) = attachment { - let imageHeight: CGFloat = attachments.count == 1 ? feedAttachmentBiggerImageSize.height : feedAttachmentImageSize.height - height += (imageHeight + 15) - } - } + let height = super.heightOfFeed(feed) + feedAttachmentImageSize.height + 15 return ceil(height) } @@ -108,7 +101,7 @@ class FeedCell: FeedBasicCell { if !mediaCollectionView.hidden { let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 - let height: CGFloat = attachments.count == 1 ? feedAttachmentBiggerImageSize.height : feedAttachmentImageSize.height + let height = feedAttachmentImageSize.height mediaCollectionView.frame = CGRect(x: 0, y: y, width: screenWidth, height: height) self.attachments = attachments @@ -120,7 +113,7 @@ class FeedCell: FeedBasicCell { } } -extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate { +extension FeedAnyImagesCell: UICollectionViewDataSource, UICollectionViewDelegate { func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { return 1 @@ -146,12 +139,7 @@ extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate { func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!, sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize { - if attachments.count > 1 { - return feedAttachmentImageSize - - } else { - return feedAttachmentBiggerImageSize - } + return feedAttachmentImageSize } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { From f8d497bca8a8f5a0145985b78c5ed14f22a6eae0 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 14:08:34 +0800 Subject: [PATCH 20/45] fix imageView3's frame --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 16 +++++++++------- Yep/Views/Cells/Feed/FeedNormalImagesCell.swift | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index cef8ee85..009c67a2 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -132,13 +132,6 @@ class FeedBasicCell: UITableViewCell { var touchesEndedAction: (UITableViewCell -> Void)? var touchesCancelledAction: (UITableViewCell -> Void)? - override func prepareForReuse() { - super.prepareForReuse() - - messageTextView.text = nil - messageTextView.attributedText = nil - } - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -177,6 +170,15 @@ class FeedBasicCell: UITableViewCell { // Configure the view for the selected state } + override func prepareForReuse() { + super.prepareForReuse() + + feed = nil + + messageTextView.text = nil + messageTextView.attributedText = nil + } + private func calHeightOfMessageTextView() { let rect = messageTextView.text.boundingRectWithSize(CGSize(width: FeedBasicCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index 5295aa0c..12f41f3b 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -46,7 +46,7 @@ class FeedNormalImagesCell: FeedBasicCell { lazy var imageView3: UIImageView = { let x = 65 + (YepConfig.FeedNormalImagesCell.imageSize.width + 5) * 2 - let frame = CGRect(origin: CGPoint(x: 65, y: 0), size: YepConfig.FeedNormalImagesCell.imageSize) + let frame = CGRect(origin: CGPoint(x: x, y: 0), size: YepConfig.FeedNormalImagesCell.imageSize) let imageView = self.createImageViewWithFrame(frame) return imageView From 5d7ad731a90e233db1dcfce4e63da33ffc7e3265 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 14:12:23 +0800 Subject: [PATCH 21/45] separatorInset --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 009c67a2..149d7106 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -135,6 +135,8 @@ class FeedBasicCell: UITableViewCell { override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) + separatorInset = UIEdgeInsets(top: 0, left: 65, bottom: 0, right: 0) + contentView.addSubview(avatarImageView) contentView.addSubview(nicknameLabel) contentView.addSubview(skillButton) From e491bc31d456c1733332c420272397672be0a05a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 14:15:24 +0800 Subject: [PATCH 22/45] only show FPSLabel on Feeds --- Yep/ViewControllers/Contacts/ContactsViewController.swift | 2 +- .../Conversation/ConversationViewController.swift | 2 +- .../Conversations/ConversationsViewController.swift | 2 +- Yep/ViewControllers/Discover/DiscoverViewController.swift | 2 +- Yep/ViewControllers/Profile/ProfileViewController.swift | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Yep/ViewControllers/Contacts/ContactsViewController.swift b/Yep/ViewControllers/Contacts/ContactsViewController.swift index 13e3e3bf..0f8884b9 100644 --- a/Yep/ViewControllers/Contacts/ContactsViewController.swift +++ b/Yep/ViewControllers/Contacts/ContactsViewController.swift @@ -121,7 +121,7 @@ class ContactsViewController: BaseViewController { } #if DEBUG - view.addSubview(contactsFPSLabel) +// view.addSubview(contactsFPSLabel) #endif } diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index d5ff8e4b..937d29e1 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -859,7 +859,7 @@ class ConversationViewController: BaseViewController { } #if DEBUG - view.addSubview(conversationFPSLabel) +// view.addSubview(conversationFPSLabel) #endif } diff --git a/Yep/ViewControllers/Conversations/ConversationsViewController.swift b/Yep/ViewControllers/Conversations/ConversationsViewController.swift index cde3d9e7..12476a27 100644 --- a/Yep/ViewControllers/Conversations/ConversationsViewController.swift +++ b/Yep/ViewControllers/Conversations/ConversationsViewController.swift @@ -147,7 +147,7 @@ class ConversationsViewController: UIViewController { } #if DEBUG - view.addSubview(conversationsFPSLabel) +// view.addSubview(conversationsFPSLabel) #endif } diff --git a/Yep/ViewControllers/Discover/DiscoverViewController.swift b/Yep/ViewControllers/Discover/DiscoverViewController.swift index bcbf443d..5750c2a7 100644 --- a/Yep/ViewControllers/Discover/DiscoverViewController.swift +++ b/Yep/ViewControllers/Discover/DiscoverViewController.swift @@ -114,7 +114,7 @@ class DiscoverViewController: BaseViewController { } #if DEBUG - view.addSubview(discoverFPSLabel) +// view.addSubview(discoverFPSLabel) #endif } diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 3933e8af..de5689a5 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -793,7 +793,7 @@ class ProfileViewController: UIViewController { } #if DEBUG - view.addSubview(profileFPSLabel) +// view.addSubview(profileFPSLabel) #endif } From 62131f7e8e6d2c9fc2add58688a5462df9f6e1d6 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 14:40:48 +0800 Subject: [PATCH 23/45] add FeedCellLayout --- Yep.xcodeproj/project.pbxproj | 4 ++ Yep/Views/Cells/Feed/FeedBasicCell.swift | 12 ------ Yep/Views/Cells/Feed/FeedCellLayout.swift | 46 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedCellLayout.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index e524ab34..8b978f1e 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -303,6 +303,7 @@ 50E348921B9063A700A8E699 /* AboutCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E348901B9063A700A8E699 /* AboutCell.swift */; }; 50E348931B9063A700A8E699 /* AboutCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50E348911B9063A700A8E699 /* AboutCell.xib */; }; 50E392BC1C22752C00C0CECB /* FeedNormalImagesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */; }; + 50E392BE1C228BF000C0CECB /* FeedCellLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -667,6 +668,7 @@ 50E348901B9063A700A8E699 /* AboutCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AboutCell.swift; path = Views/Cells/About/AboutCell.swift; sourceTree = ""; }; 50E348911B9063A700A8E699 /* AboutCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = AboutCell.xib; path = Views/Cells/About/AboutCell.xib; sourceTree = ""; }; 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedNormalImagesCell.swift; path = Views/Cells/Feed/FeedNormalImagesCell.swift; sourceTree = ""; }; + 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedCellLayout.swift; path = Views/Cells/Feed/FeedCellLayout.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1960,6 +1962,7 @@ 50AFBF651BB4FC37007D19DA /* Feed */ = { isa = PBXGroup; children = ( + 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */, 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */, 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */, 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */, @@ -2746,6 +2749,7 @@ 50894D101AEE3C25000981AF /* YepHUD.swift in Sources */, 50EB8CCE1AEA1B38001AC1EE /* MessageMediaViewController.swift in Sources */, 50E114F91ABC137A00F13000 /* YepServiceSync.swift in Sources */, + 50E392BE1C228BF000C0CECB /* FeedCellLayout.swift in Sources */, 506E241C1AE6254F00A33C1A /* MessageTypeButton.swift in Sources */, 505082351C212E9200643CEB /* FeedLocationContainerView.swift in Sources */, 0A3E60671ACCAECE003DC853 /* YepLocationService.swift in Sources */, diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 149d7106..e35ba801 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -12,18 +12,6 @@ private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width class FeedBasicCell: UITableViewCell { - //@IBOutlet weak var avatarImageView: UIImageView! - //@IBOutlet weak var nicknameLabel: UILabel! - - //@IBOutlet weak var skillButton: UIButton! - - //@IBOutlet weak var messageTextView: FeedTextView! - //@IBOutlet weak var messageTextViewHeightConstraint: NSLayoutConstraint! - - //@IBOutlet weak var leftBottomLabel: UILabel! - - //@IBOutlet weak var messageCountLabel: UILabel! - lazy var avatarImageView: UIImageView = { let imageView = UIImageView() diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift new file mode 100644 index 00000000..8b267b66 --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -0,0 +1,46 @@ +// +// FeedCellLayout.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import Foundation + +struct FeedCellLayout { + + struct BasicLayout { + + let avatarImageViewFrame: CGRect + let nicknameLabelFrame: CGRect + let skillButtonFrame: CGRect + + let messageTextViewFrame: CGRect + + let leftBottomLabelFrame: CGRect + let messageCountLabelFrame: CGRect + let discussionImageViewFrame: CGRect + } + let basicLayout: BasicLayout + + struct BiggerImageLayout { + let biggerImageViewFrame: CGRect + } + let biggerImageLayout: BiggerImageLayout? + + struct NormalImagesLayout { + + let imageView1Frame: CGRect + let imageView2Frame: CGRect + let imageView3Frame: CGRect + } + let normalImagesLayout: NormalImagesLayout? + + struct AnyImagesLayout { + + let mediaCollectionView: CGRect + } + let anyImagesLayout: AnyImagesLayout? +} + From cc7b940d6d0855e04089a40a37e78c43f85ecc8b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 15:46:41 +0800 Subject: [PATCH 24/45] use FeedCellLayout for FeedBasicCell & FeedBiggerImageCell --- .../Feeds/FeedsViewController.swift | 37 ++++++++++--- Yep/Views/Cells/Feed/FeedAnyImagesCell.swift | 4 +- Yep/Views/Cells/Feed/FeedBasicCell.swift | 54 +++++++++++++++---- .../Cells/Feed/FeedBiggerImageCell.swift | 25 +++++++-- Yep/Views/Cells/Feed/FeedCellLayout.swift | 35 ++++++++++-- .../Cells/Feed/FeedNormalImagesCell.swift | 4 +- Yep/Views/Cells/Feed/FeedSocialWorkCell.swift | 4 +- 7 files changed, 134 insertions(+), 29 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 166c1d34..dbec8b74 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -221,7 +221,26 @@ class FeedsViewController: BaseViewController { return height } } - + + private var feedCellLayoutHash = [String: FeedCellLayout]() + + private func feedCellLayoutOfFeed(feed: DiscoveredFeed) -> FeedCellLayout? { + let key = feed.id + + return feedCellLayoutHash[key] + } + + private func updateFeedCellLayout(layout: FeedCellLayout, forFeed feed: DiscoveredFeed) { + + let key = feed.id + + if !key.isEmpty { + feedCellLayoutHash[key] = layout + } + + println("feedCellLayoutHash.count: \(feedCellLayoutHash.count)") + } + private var feedSortStyle: FeedSortStyle = .Match { didSet { feeds = [] @@ -909,11 +928,17 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { tableView.deselectRowAtIndexPath(indexPath, animated: true) } + let layout = feedCellLayoutOfFeed(feed) + let update: FeedCellLayout.Update = { [weak self] newLayout in + self?.updateFeedCellLayout(newLayout, forFeed: feed) + } + let layoutCache = (layout: layout, update: update) + switch feed.kind { case .Text: - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) case .Image: @@ -953,7 +978,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) cell.tapMediaAction = tapMediaAction @@ -963,7 +988,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) cell.tapMediaAction = tapMediaAction @@ -972,7 +997,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) cell.tapMediaAction = tapMediaAction } @@ -983,7 +1008,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) cell.tapGithubRepoLinkAction = { [weak self] URL in self?.yep_openURL(URL) diff --git a/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift index 71fd33e6..3304027e 100644 --- a/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift @@ -89,8 +89,8 @@ class FeedAnyImagesCell: FeedBasicCell { attachments = [] } - override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { - super.configureWithFeed(feed, needShowSkill: needShowSkill) + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + super.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) var hasMedia = false diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index e35ba801..d3033331 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -176,30 +176,46 @@ class FeedBasicCell: UITableViewCell { messageTextView.frame.size.height = ceil(rect.height) } - func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { + func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { self.feed = feed + let layout = layoutCache.layout + messageTextView.text = "\u{200B}\(feed.body)" // ref http://stackoverflow.com/a/25994821 - calHeightOfMessageTextView() + if let basicLayout = layout?.basicLayout { + messageTextView.frame = basicLayout.messageTextViewFrame + } else { + calHeightOfMessageTextView() + } if needShowSkill, let skill = feed.skill { skillButton.setTitle(skill.localName, forState: .Normal) skillButton.hidden = false - let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) + if let basicLayout = layout?.basicLayout { + skillButton.frame = basicLayout.skillButtonFrame + nicknameLabel.frame = basicLayout.nicknameLabelFrame - let skillButtonWidth = rect.width + 20 + } else { + let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) - skillButton.frame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) + let skillButtonWidth = rect.width + 20 - nicknameLabel.frame.size.width = screenWidth - 65 - skillButtonWidth - 15 - 16 - 18 + skillButton.frame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) + + nicknameLabel.frame.size.width = screenWidth - 65 - skillButtonWidth - 15 - 16 - 18 + } } else { skillButton.hidden = true - nicknameLabel.frame.size.width = screenWidth - 65 - 15 + if let basicLayout = layout?.basicLayout { + nicknameLabel.frame = basicLayout.nicknameLabelFrame + } else { + nicknameLabel.frame.size.width = screenWidth - 65 - 15 + } } let plainAvatar = PlainAvatar(avatarURLString: feed.creator.avatarURLString, avatarStyle: nanoAvatarStyle) @@ -213,13 +229,29 @@ class FeedBasicCell: UITableViewCell { messageCountLabel.text = messagesCountString messageCountLabel.hidden = (feed.messagesCount == 0) - leftBottomLabel.frame.origin.y = contentView.bounds.height - leftBottomLabel.frame.height - 10 + if let basicLayout = layout?.basicLayout { + leftBottomLabel.frame = basicLayout.leftBottomLabelFrame + messageCountLabel.frame = basicLayout.messageCountLabelFrame + discussionImageView.frame = basicLayout.discussionImageViewFrame - let rect = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) + } else { + leftBottomLabel.frame.origin.y = contentView.bounds.height - leftBottomLabel.frame.height - 10 - messageCountLabel.frame = CGRect(x: screenWidth - rect.width - 45 - 8, y: leftBottomLabel.frame.origin.y, width: rect.width, height: 19) + let rect = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) - discussionImageView.frame = CGRect(x: screenWidth - 30 - 15, y: leftBottomLabel.frame.origin.y - 1, width: 30, height: 19) + messageCountLabel.frame = CGRect(x: screenWidth - rect.width - 45 - 8, y: leftBottomLabel.frame.origin.y, width: rect.width, height: 19) + + discussionImageView.frame = CGRect(x: screenWidth - 30 - 15, y: leftBottomLabel.frame.origin.y - 1, width: 30, height: 19) + } + + if layoutCache.layout == nil { + + let basicLayout = FeedCellLayout.BasicLayout(avatarImageViewFrame: avatarImageView.frame, nicknameLabelFrame: nicknameLabel.frame, skillButtonFrame: skillButton.frame, messageTextViewFrame: messageTextView.frame, leftBottomLabelFrame: leftBottomLabel.frame, messageCountLabelFrame: messageCountLabel.frame, discussionImageViewFrame: discussionImageView.frame) + + let newLayout = FeedCellLayout(basicLayout: basicLayout) + + layoutCache.update(layout: newLayout) + } } // MARK: Actions diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index ee90fd3f..f0627b24 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -56,14 +56,33 @@ class FeedBiggerImageCell: FeedBasicCell { biggerImageView.image = nil } - override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { - super.configureWithFeed(feed, needShowSkill: needShowSkill) + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) + + if let biggerImageLayout = layoutCache.layout?.biggerImageLayout { + biggerImageView.frame = biggerImageLayout.biggerImageViewFrame + + } else { + biggerImageView.frame.origin.y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + } if let onlyAttachment = feed.imageAttachments?.first { biggerImageView.yep_showActivityIndicatorWhenLoading = true biggerImageView.yep_setImageOfAttachment(onlyAttachment, withSize: YepConfig.FeedBiggerImageCell.imageSize) + } - biggerImageView.frame.origin.y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + if layoutCache.layout == nil { + + let biggerImageLayout = FeedCellLayout.BiggerImageLayout(biggerImageViewFrame: biggerImageView.frame) + _newLayout?.biggerImageLayout = biggerImageLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } } } diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index 8b267b66..974c3118 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -10,6 +10,9 @@ import Foundation struct FeedCellLayout { + typealias Update = (layout: FeedCellLayout) -> Void + typealias Cache = (layout: FeedCellLayout?, update: Update) + struct BasicLayout { let avatarImageViewFrame: CGRect @@ -21,13 +24,35 @@ struct FeedCellLayout { let leftBottomLabelFrame: CGRect let messageCountLabelFrame: CGRect let discussionImageViewFrame: CGRect + + init(avatarImageViewFrame: CGRect, + nicknameLabelFrame: CGRect, + skillButtonFrame: CGRect, + messageTextViewFrame: CGRect, + leftBottomLabelFrame: CGRect, + messageCountLabelFrame: CGRect, + discussionImageViewFrame: CGRect) { + self.avatarImageViewFrame = avatarImageViewFrame + self.nicknameLabelFrame = nicknameLabelFrame + self.skillButtonFrame = skillButtonFrame + + self.messageTextViewFrame = messageTextViewFrame + + self.leftBottomLabelFrame = leftBottomLabelFrame + self.messageCountLabelFrame = messageCountLabelFrame + self.discussionImageViewFrame = discussionImageViewFrame + } } let basicLayout: BasicLayout struct BiggerImageLayout { let biggerImageViewFrame: CGRect + + init(biggerImageViewFrame: CGRect) { + self.biggerImageViewFrame = biggerImageViewFrame + } } - let biggerImageLayout: BiggerImageLayout? + var biggerImageLayout: BiggerImageLayout? struct NormalImagesLayout { @@ -35,12 +60,16 @@ struct FeedCellLayout { let imageView2Frame: CGRect let imageView3Frame: CGRect } - let normalImagesLayout: NormalImagesLayout? + var normalImagesLayout: NormalImagesLayout? struct AnyImagesLayout { let mediaCollectionView: CGRect } - let anyImagesLayout: AnyImagesLayout? + var anyImagesLayout: AnyImagesLayout? + + init(basicLayout: BasicLayout) { + self.basicLayout = basicLayout + } } diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index 12f41f3b..44b88ff5 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -89,8 +89,8 @@ class FeedNormalImagesCell: FeedBasicCell { imageView3.image = nil } - override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { - super.configureWithFeed(feed, needShowSkill: needShowSkill) + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + super.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) if let attachments = feed.imageAttachments { diff --git a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift index ff03b8c1..91ab639b 100644 --- a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift @@ -154,8 +154,8 @@ class FeedSocialWorkCell: FeedBasicCell { return ceil(height) } - override func configureWithFeed(feed: DiscoveredFeed, needShowSkill: Bool) { - super.configureWithFeed(feed, needShowSkill: needShowSkill) + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + super.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) if let accountName = feed.kind.accountName, From 380f1af08e09b036368377d54308805edb544296 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 15:57:58 +0800 Subject: [PATCH 25/45] use FeedCellLayout for FeedNormalImagesCell --- Yep/Views/Cells/Feed/FeedCellLayout.swift | 6 ++++ .../Cells/Feed/FeedNormalImagesCell.swift | 29 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index 974c3118..db96a2af 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -59,6 +59,12 @@ struct FeedCellLayout { let imageView1Frame: CGRect let imageView2Frame: CGRect let imageView3Frame: CGRect + + init(imageView1Frame: CGRect, imageView2Frame: CGRect, imageView3Frame: CGRect) { + self.imageView1Frame = imageView1Frame + self.imageView2Frame = imageView2Frame + self.imageView3Frame = imageView3Frame + } } var normalImagesLayout: NormalImagesLayout? diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index 44b88ff5..29eec605 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -90,7 +90,22 @@ class FeedNormalImagesCell: FeedBasicCell { } override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { - super.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) + + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) + + if let normalImagesLayout = layoutCache.layout?.normalImagesLayout { + imageView1.frame = normalImagesLayout.imageView1Frame + imageView2.frame = normalImagesLayout.imageView2Frame + imageView3.frame = normalImagesLayout.imageView3Frame + + } else { + imageViews.forEach({ + $0.frame.origin.y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + }) + } if let attachments = feed.imageAttachments { @@ -100,8 +115,6 @@ class FeedNormalImagesCell: FeedBasicCell { imageViews[i].yep_showActivityIndicatorWhenLoading = true imageViews[i].yep_setImageOfAttachment(attachment, withSize: YepConfig.FeedNormalImagesCell.imageSize) - imageViews[i].frame.origin.y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 - imageViews[i].hidden = false } else { @@ -109,6 +122,16 @@ class FeedNormalImagesCell: FeedBasicCell { } } } + + if layoutCache.layout == nil { + + let normalImagesLayout = FeedCellLayout.NormalImagesLayout(imageView1Frame: imageView1.frame, imageView2Frame: imageView2.frame, imageView3Frame: imageView3.frame) + _newLayout?.normalImagesLayout = normalImagesLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } + } } @objc private func tap(sender: UITapGestureRecognizer) { From a68464826b48603ef36d77d9ae0caeec5cb767c2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 16:06:15 +0800 Subject: [PATCH 26/45] use FeedCellLayout for FeedAnyImagesCell --- Yep/Views/Cells/Feed/FeedAnyImagesCell.swift | 38 ++++++++++++-------- Yep/Views/Cells/Feed/FeedCellLayout.swift | 6 +++- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift index 3304027e..5f569858 100644 --- a/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift @@ -90,25 +90,33 @@ class FeedAnyImagesCell: FeedBasicCell { } override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { - super.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) - var hasMedia = false + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) - if let attachment = feed.attachment, case let .Images(attachments) = attachment { - hasMedia = !attachments.isEmpty - - mediaCollectionView.hidden = hasMedia ? false : true - - if !mediaCollectionView.hidden { - let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 - let height = feedAttachmentImageSize.height - mediaCollectionView.frame = CGRect(x: 0, y: y, width: screenWidth, height: height) - - self.attachments = attachments - } + if let anyImagesLayout = layoutCache.layout?.anyImagesLayout { + mediaCollectionView.frame = anyImagesLayout.mediaCollectionViewFrame } else { - mediaCollectionView.hidden = true + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height = feedAttachmentImageSize.height + mediaCollectionView.frame = CGRect(x: 0, y: y, width: screenWidth, height: height) + } + + if let attachment = feed.attachment, case let .Images(attachments) = attachment { + self.attachments = attachments + } + + if layoutCache.layout == nil { + + let anyImagesLayout = FeedCellLayout.AnyImagesLayout(mediaCollectionViewFrame: mediaCollectionView.frame) + _newLayout?.anyImagesLayout = anyImagesLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } } } } diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index db96a2af..1eff5a64 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -70,7 +70,11 @@ struct FeedCellLayout { struct AnyImagesLayout { - let mediaCollectionView: CGRect + let mediaCollectionViewFrame: CGRect + + init(mediaCollectionViewFrame: CGRect) { + self.mediaCollectionViewFrame = mediaCollectionViewFrame + } } var anyImagesLayout: AnyImagesLayout? From 2211c2f934a840bd24469edd6a5d3973c946a958 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 17:06:35 +0800 Subject: [PATCH 27/45] prepare cal FeedCellLayout from DiscoveredFeed --- .../Feeds/FeedsViewController.swift | 20 ++- Yep/Views/Cells/Feed/FeedBasicCell.swift | 2 +- Yep/Views/Cells/Feed/FeedCellLayout.swift | 137 +++++++++++++++++- 3 files changed, 150 insertions(+), 9 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index dbec8b74..2821f5d9 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -483,7 +483,13 @@ class FeedsViewController: BaseViewController { defaultFailureHandler(reason, errorMessage: errorMessage) } - let completion: [DiscoveredFeed] -> Void = { feeds in + let completion: [DiscoveredFeed] -> Void = { [weak self] feeds in + + let needShowSkill: Bool = (self?.skill == nil) ? true : false + feeds.forEach({ feed in + let newLayout = FeedCellLayout(feed: feed, needShowSkill: needShowSkill) + self?.updateFeedCellLayout(newLayout, forFeed: feed) + }) dispatch_async(dispatch_get_main_queue()) { [weak self] in @@ -928,6 +934,8 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { tableView.deselectRowAtIndexPath(indexPath, animated: true) } + let needShowSkill: Bool = (skill == nil) ? true : false + let layout = feedCellLayoutOfFeed(feed) let update: FeedCellLayout.Update = { [weak self] newLayout in self?.updateFeedCellLayout(newLayout, forFeed: feed) @@ -938,7 +946,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { case .Text: - cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) case .Image: @@ -978,7 +986,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) cell.tapMediaAction = tapMediaAction @@ -988,7 +996,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) cell.tapMediaAction = tapMediaAction @@ -997,7 +1005,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) cell.tapMediaAction = tapMediaAction } @@ -1008,7 +1016,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: (skill == nil) ? true : false) + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) cell.tapGithubRepoLinkAction = { [weak self] URL in self?.yep_openURL(URL) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index d3033331..273e68cb 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -248,7 +248,7 @@ class FeedBasicCell: UITableViewCell { let basicLayout = FeedCellLayout.BasicLayout(avatarImageViewFrame: avatarImageView.frame, nicknameLabelFrame: nicknameLabel.frame, skillButtonFrame: skillButton.frame, messageTextViewFrame: messageTextView.frame, leftBottomLabelFrame: leftBottomLabel.frame, messageCountLabelFrame: messageCountLabel.frame, discussionImageViewFrame: discussionImageView.frame) - let newLayout = FeedCellLayout(basicLayout: basicLayout) + let newLayout = FeedCellLayout(height: contentView.bounds.height, basicLayout: basicLayout) layoutCache.update(layout: newLayout) } diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index 1eff5a64..a1dbcfec 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -6,13 +6,17 @@ // Copyright © 2015年 Catch Inc. All rights reserved. // -import Foundation +import UIKit + +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width struct FeedCellLayout { typealias Update = (layout: FeedCellLayout) -> Void typealias Cache = (layout: FeedCellLayout?, update: Update) + let height: CGFloat + struct BasicLayout { let avatarImageViewFrame: CGRect @@ -78,8 +82,137 @@ struct FeedCellLayout { } var anyImagesLayout: AnyImagesLayout? - init(basicLayout: BasicLayout) { + init(height: CGFloat, basicLayout: BasicLayout) { + self.height = height self.basicLayout = basicLayout } + + init(feed: DiscoveredFeed, needShowSkill: Bool) { + + let height: CGFloat + + switch feed.kind { + + case .Text: + height = FeedBasicCell.heightOfFeed(feed) + + case .Image: + if feed.imageAttachmentsCount == 1 { + height = FeedBiggerImageCell.heightOfFeed(feed) + + } else if feed.imageAttachmentsCount <= 3 { + height = FeedNormalImagesCell.heightOfFeed(feed) + + } else { + height = FeedAnyImagesCell.heightOfFeed(feed) + } + + case .GithubRepo, .DribbbleShot, .Audio, .Location: + height = FeedSocialWorkCell.heightOfFeed(feed) + + default: + height = FeedBasicCell.heightOfFeed(feed) + } + + self.height = height + + let avatarImageViewFrame = CGRect(x: 15, y: 10, width: 40, height: 40) + + let nicknameLabelFrame: CGRect + let skillButtonFrame: CGRect + + if needShowSkill, let skill = feed.skill { + + let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) + + let skillButtonWidth = rect.width + 20 + + skillButtonFrame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) + + let nicknameLabelWidth = screenWidth - 65 - skillButtonWidth - 15 - 16 - 18 + nicknameLabelFrame = CGRect(x: 65, y: 21, width: nicknameLabelWidth, height: 18) + + } else { + let nicknameLabelWidth = screenWidth - 65 - 15 + nicknameLabelFrame = CGRect(x: 65, y: 21, width: nicknameLabelWidth, height: 18) + skillButtonFrame = CGRectZero + } + + let _rect1 = feed.body.boundingRectWithSize(CGSize(width: FeedBasicCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) + + let messageTextViewHeight = ceil(_rect1.height) + let messageTextViewFrame = CGRect(x: 65, y: 54, width: screenWidth - 65 - 15, height: messageTextViewHeight) + + let leftBottomLabelOriginY = height - 17 - 10 + let leftBottomLabelFrame = CGRect(x: 65, y: leftBottomLabelOriginY, width: 200, height: 17) + + let messagesCountString = "\(feed.messagesCount)" + + let _rect2 = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) + + let messageCountLabelFrame = CGRect(x: screenWidth - _rect2.width - 45 - 8, y: leftBottomLabelOriginY, width: _rect2.width, height: 19) + + let discussionImageViewFrame = CGRect(x: screenWidth - 30 - 15, y: leftBottomLabelOriginY - 1, width: 30, height: 19) + + let basicLayout = FeedCellLayout.BasicLayout( + avatarImageViewFrame: avatarImageViewFrame, + nicknameLabelFrame: nicknameLabelFrame, + skillButtonFrame: skillButtonFrame, + messageTextViewFrame: messageTextViewFrame, + leftBottomLabelFrame: leftBottomLabelFrame, + messageCountLabelFrame: messageCountLabelFrame, + discussionImageViewFrame: discussionImageViewFrame + ) + + self.basicLayout = basicLayout + + switch feed.kind { + + case .Text: + break + + case .Image: + + let beginY = messageTextViewFrame.origin.y + messageTextViewFrame.height + 15 + + if feed.imageAttachmentsCount == 1 { + + let biggerImageViewFrame = CGRect(origin: CGPoint(x: 65, y: beginY), size: YepConfig.FeedBiggerImageCell.imageSize) + + let biggerImageLayout = FeedCellLayout.BiggerImageLayout(biggerImageViewFrame: biggerImageViewFrame) + + self.biggerImageLayout = biggerImageLayout + + } else if feed.imageAttachmentsCount <= 3 { + + let x1 = 65 + (YepConfig.FeedNormalImagesCell.imageSize.width + 5) * 0 + let imageView1Frame = CGRect(origin: CGPoint(x: x1, y: beginY), size: YepConfig.FeedNormalImagesCell.imageSize) + + let x2 = 65 + (YepConfig.FeedNormalImagesCell.imageSize.width + 5) * 1 + let imageView2Frame = CGRect(origin: CGPoint(x: x2, y: beginY), size: YepConfig.FeedNormalImagesCell.imageSize) + + let x3 = 65 + (YepConfig.FeedNormalImagesCell.imageSize.width + 5) * 2 + let imageView3Frame = CGRect(origin: CGPoint(x: x3, y: beginY), size: YepConfig.FeedNormalImagesCell.imageSize) + + let normalImagesLayout = FeedCellLayout.NormalImagesLayout(imageView1Frame: imageView1Frame, imageView2Frame: imageView2Frame, imageView3Frame: imageView3Frame) + + self.normalImagesLayout = normalImagesLayout + + } else { + let height = feedAttachmentImageSize.height + let mediaCollectionViewFrame = CGRect(x: 0, y: beginY, width: screenWidth, height: height) + + let anyImagesLayout = FeedCellLayout.AnyImagesLayout(mediaCollectionViewFrame: mediaCollectionViewFrame) + + self.anyImagesLayout = anyImagesLayout + } + + case .GithubRepo, .DribbbleShot, .Audio, .Location: + break + + default: + break + } + } } From 524bfe23f56dfef1c406249ed8206fcf4449354a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 17:36:55 +0800 Subject: [PATCH 28/45] add FeedGithubRepoCell --- Yep.xcodeproj/project.pbxproj | 4 + .../Feeds/FeedsViewController.swift | 25 +++- Yep/Views/Cells/Feed/FeedCellLayout.swift | 19 ++- Yep/Views/Cells/Feed/FeedGithubRepoCell.swift | 120 ++++++++++++++++++ 4 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedGithubRepoCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 8b978f1e..7611f683 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -304,6 +304,7 @@ 50E348931B9063A700A8E699 /* AboutCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50E348911B9063A700A8E699 /* AboutCell.xib */; }; 50E392BC1C22752C00C0CECB /* FeedNormalImagesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */; }; 50E392BE1C228BF000C0CECB /* FeedCellLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */; }; + 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -669,6 +670,7 @@ 50E348911B9063A700A8E699 /* AboutCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = AboutCell.xib; path = Views/Cells/About/AboutCell.xib; sourceTree = ""; }; 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedNormalImagesCell.swift; path = Views/Cells/Feed/FeedNormalImagesCell.swift; sourceTree = ""; }; 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedCellLayout.swift; path = Views/Cells/Feed/FeedCellLayout.swift; sourceTree = ""; }; + 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedGithubRepoCell.swift; path = Views/Cells/Feed/FeedGithubRepoCell.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1968,6 +1970,7 @@ 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */, 50F5AF8A1BBBB64C0033C9BC /* FeedAnyImagesCell.swift */, 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, + 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */, ); name = Feed; sourceTree = ""; @@ -2740,6 +2743,7 @@ 50DEE0311BE339B000015741 /* LoadMoreTableViewCell.swift in Sources */, 50DEE0361BE3720F00015741 /* LoadMoreCollectionViewCell.swift in Sources */, 504F41251ACE2D1D00FBB19A /* SampleView.swift in Sources */, + 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */, 50A640EC1B6F4E420050E4A3 /* DoNotDisturbPeriodViewController.swift in Sources */, 502AE5291AB81076005BD199 /* YepService.swift in Sources */, 50C090A41ADE46D500CC6389 /* RegisterSelectSkillsViewController.swift in Sources */, diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 2821f5d9..f9e61036 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -112,6 +112,7 @@ class FeedsViewController: BaseViewController { private let feedNormalImagesCellID = "FeedNormalImagesCell" private let feedAnyImagesCellID = "FeedAnyImagesCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" + private let feedGithubRepoCellID = "FeedGithubRepoCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" private lazy var noFeedsFooterView: InfoView = InfoView(NSLocalizedString("No Feeds.", comment: "")) @@ -207,7 +208,10 @@ class FeedsViewController: BaseViewController { height = FeedAnyImagesCell.heightOfFeed(feed) } - case .GithubRepo, .DribbbleShot, .Audio, .Location: + case .GithubRepo: + height = FeedGithubRepoCell.heightOfFeed(feed) + + case .DribbbleShot, .Audio, .Location: height = FeedSocialWorkCell.heightOfFeed(feed) default: @@ -323,6 +327,7 @@ class FeedsViewController: BaseViewController { feedsTableView.registerClass(FeedNormalImagesCell.self, forCellReuseIdentifier: feedNormalImagesCellID) feedsTableView.registerClass(FeedAnyImagesCell.self, forCellReuseIdentifier: feedAnyImagesCellID) feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) + feedsTableView.registerClass(FeedGithubRepoCell.self, forCellReuseIdentifier: feedGithubRepoCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -860,7 +865,11 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return cell } - case .GithubRepo, .DribbbleShot, .Audio, .Location: + case .GithubRepo: + let cell = tableView.dequeueReusableCellWithIdentifier(feedGithubRepoCellID) as! FeedGithubRepoCell + return cell + + case .DribbbleShot, .Audio, .Location: let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell return cell @@ -1010,9 +1019,9 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.tapMediaAction = tapMediaAction } - case .GithubRepo, .DribbbleShot, .Audio, .Location: + case .GithubRepo: - guard let cell = cell as? FeedSocialWorkCell else { + guard let cell = cell as? FeedGithubRepoCell else { break } @@ -1022,6 +1031,14 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { self?.yep_openURL(URL) } + case .DribbbleShot, .Audio, .Location: + + guard let cell = cell as? FeedSocialWorkCell else { + break + } + + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) + cell.tapDribbbleShotLinkAction = { [weak self] URL in self?.yep_openURL(URL) } diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index a1dbcfec..a609dcf9 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -82,6 +82,11 @@ struct FeedCellLayout { } var anyImagesLayout: AnyImagesLayout? + struct GithubRepoLayout { + let githubRepoContainerViewFrame: CGRect + } + var githubRepoLayout: GithubRepoLayout? + init(height: CGFloat, basicLayout: BasicLayout) { self.height = height self.basicLayout = basicLayout @@ -166,6 +171,8 @@ struct FeedCellLayout { self.basicLayout = basicLayout + let beginY = messageTextViewFrame.origin.y + messageTextViewFrame.height + 15 + switch feed.kind { case .Text: @@ -173,7 +180,6 @@ struct FeedCellLayout { case .Image: - let beginY = messageTextViewFrame.origin.y + messageTextViewFrame.height + 15 if feed.imageAttachmentsCount == 1 { @@ -207,7 +213,16 @@ struct FeedCellLayout { self.anyImagesLayout = anyImagesLayout } - case .GithubRepo, .DribbbleShot, .Audio, .Location: + case .GithubRepo: + + let height: CGFloat = leftBottomLabelFrame.origin.y - beginY - 15 + let githubRepoContainerViewFrame = CGRect(x: 65, y: beginY, width: screenWidth - 65 - 60, height: height) + + let githubRepoLayout = FeedCellLayout.GithubRepoLayout(githubRepoContainerViewFrame: githubRepoContainerViewFrame) + + self.githubRepoLayout = githubRepoLayout + + case .DribbbleShot, .Audio, .Location: break default: diff --git a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift new file mode 100644 index 00000000..372bf2eb --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift @@ -0,0 +1,120 @@ +// +// FeedGithubRepoCell.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit + +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width + +class FeedGithubRepoCell: FeedBasicCell { + + var tapGithubRepoLinkAction: (NSURL -> Void)? + + lazy var logoImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "icon_github") + imageView.frame = CGRect(x: 0, y: 0, width: 18, height: 18) + imageView.tintColor = SocialAccount.Github.tintColor + return imageView + }() + + lazy var githubRepoContainerView: FeedGithubRepoContainerView = { + let view = FeedGithubRepoContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) + return view + }() + + lazy var socialWorkBorderImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "social_work_border") + return imageView + }() + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(logoImageView) + contentView.addSubview(githubRepoContainerView) + contentView.addSubview(socialWorkBorderImageView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let height = super.heightOfFeed(feed) + (80 + 15) + + return ceil(height) + } + + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) + + if needShowSkill, let _ = feed.skill { + logoImageView.frame.origin.x = skillButton.frame.origin.x - 8 - 18 + logoImageView.frame.origin.y = nicknameLabel.frame.origin.y + + } else { + logoImageView.frame.origin.x = screenWidth - 18 - 15 + logoImageView.frame.origin.y = nicknameLabel.frame.origin.y + } + + if let attachment = feed.attachment { + if case let .Github(githubRepo) = attachment { + githubRepoContainerView.nameLabel.text = githubRepo.name + githubRepoContainerView.descriptionLabel.text = githubRepo.description + } + } + + githubRepoContainerView.tapAction = { [weak self] in + guard let attachment = feed.attachment else { + return + } + + if case .GithubRepo = feed.kind { + if case let .Github(repo) = attachment, let URL = NSURL(string: repo.URLString) { + self?.tapGithubRepoLinkAction?(URL) + } + } + } + + if let githubRepoLayout = layoutCache.layout?.githubRepoLayout { + githubRepoContainerView.frame = githubRepoLayout.githubRepoContainerViewFrame + socialWorkBorderImageView.frame = githubRepoContainerView.frame + + } else { + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 + githubRepoContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) + + socialWorkBorderImageView.frame = githubRepoContainerView.frame + } + + if layoutCache.layout == nil { + + let githubRepoLayout = FeedCellLayout.GithubRepoLayout(githubRepoContainerViewFrame: githubRepoContainerView.frame) + _newLayout?.githubRepoLayout = githubRepoLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } + } + } +} + From 165e6e1339dba2094faf8a71724ce6eeb9b62b78 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 18:06:27 +0800 Subject: [PATCH 29/45] add FeedDribbbleShotCell --- Yep.xcodeproj/project.pbxproj | 4 + .../Feeds/FeedsViewController.swift | 25 ++- Yep/Views/Cells/Feed/FeedCellLayout.swift | 17 +- .../Cells/Feed/FeedDribbbleShotCell.swift | 149 ++++++++++++++++++ Yep/Views/Cells/Feed/FeedGithubRepoCell.swift | 2 +- 5 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 7611f683..5c04b591 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -305,6 +305,7 @@ 50E392BC1C22752C00C0CECB /* FeedNormalImagesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */; }; 50E392BE1C228BF000C0CECB /* FeedCellLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */; }; 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */; }; + 50E392C21C22B9E400C0CECB /* FeedDribbbleShotCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -671,6 +672,7 @@ 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedNormalImagesCell.swift; path = Views/Cells/Feed/FeedNormalImagesCell.swift; sourceTree = ""; }; 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedCellLayout.swift; path = Views/Cells/Feed/FeedCellLayout.swift; sourceTree = ""; }; 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedGithubRepoCell.swift; path = Views/Cells/Feed/FeedGithubRepoCell.swift; sourceTree = ""; }; + 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedDribbbleShotCell.swift; path = Views/Cells/Feed/FeedDribbbleShotCell.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1971,6 +1973,7 @@ 50F5AF8A1BBBB64C0033C9BC /* FeedAnyImagesCell.swift */, 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */, + 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */, ); name = Feed; sourceTree = ""; @@ -2814,6 +2817,7 @@ 50F2B97B1B2EEAF800F840CC /* NavigationTitleLabel.swift in Sources */, 50A820241B969B0F007CD30E /* NSTimeZone+Yep.swift in Sources */, 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */, + 50E392C21C22B9E400C0CECB /* FeedDribbbleShotCell.swift in Sources */, 504F415A1AD5028200FBB19A /* SkillCell.swift in Sources */, 84385C481B85AC890071130D /* ShowStepMatchViewController.swift in Sources */, 0A0027D61B19CEC000AD4BE0 /* ConversationOperationQueue.swift in Sources */, diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index f9e61036..816bc0b7 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -113,6 +113,7 @@ class FeedsViewController: BaseViewController { private let feedAnyImagesCellID = "FeedAnyImagesCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" private let feedGithubRepoCellID = "FeedGithubRepoCell" + private let feedDribbbleShotCellID = "FeedDribbbleShotCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" private lazy var noFeedsFooterView: InfoView = InfoView(NSLocalizedString("No Feeds.", comment: "")) @@ -211,7 +212,10 @@ class FeedsViewController: BaseViewController { case .GithubRepo: height = FeedGithubRepoCell.heightOfFeed(feed) - case .DribbbleShot, .Audio, .Location: + case .DribbbleShot: + height = FeedDribbbleShotCell.heightOfFeed(feed) + + case .Audio, .Location: height = FeedSocialWorkCell.heightOfFeed(feed) default: @@ -328,6 +332,7 @@ class FeedsViewController: BaseViewController { feedsTableView.registerClass(FeedAnyImagesCell.self, forCellReuseIdentifier: feedAnyImagesCellID) feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) feedsTableView.registerClass(FeedGithubRepoCell.self, forCellReuseIdentifier: feedGithubRepoCellID) + feedsTableView.registerClass(FeedDribbbleShotCell.self, forCellReuseIdentifier: feedDribbbleShotCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -869,7 +874,11 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { let cell = tableView.dequeueReusableCellWithIdentifier(feedGithubRepoCellID) as! FeedGithubRepoCell return cell - case .DribbbleShot, .Audio, .Location: + case .DribbbleShot: + let cell = tableView.dequeueReusableCellWithIdentifier(feedDribbbleShotCellID) as! FeedDribbbleShotCell + return cell + + case .Audio, .Location: let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell return cell @@ -1031,9 +1040,9 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { self?.yep_openURL(URL) } - case .DribbbleShot, .Audio, .Location: + case .DribbbleShot: - guard let cell = cell as? FeedSocialWorkCell else { + guard let cell = cell as? FeedDribbbleShotCell else { break } @@ -1072,6 +1081,14 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { mediaPreviewWindow.makeKeyAndVisible() } + case .Audio, .Location: + + guard let cell = cell as? FeedSocialWorkCell else { + break + } + + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) + cell.playOrPauseAudioAction = { [weak self] cell in guard let realm = try? Realm(), feedAudio = FeedAudio.feedAudioWithFeedID(feed.id, inRealm: realm) else { diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index a609dcf9..95032f9b 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -87,6 +87,13 @@ struct FeedCellLayout { } var githubRepoLayout: GithubRepoLayout? + struct DribbbleShotLayout { + let dribbbleShotContainerViewFrame: CGRect + } + var dribbbleShotLayout: DribbbleShotLayout? + + // MARK: - Init + init(height: CGFloat, basicLayout: BasicLayout) { self.height = height self.basicLayout = basicLayout @@ -222,7 +229,15 @@ struct FeedCellLayout { self.githubRepoLayout = githubRepoLayout - case .DribbbleShot, .Audio, .Location: + case .DribbbleShot: + let height: CGFloat = leftBottomLabelFrame.origin.y - beginY - 15 + let dribbbleShotContainerViewFrame = CGRect(x: 65, y: beginY, width: screenWidth - 65 - 60, height: height) + + let dribbbleShotLayout = FeedCellLayout.DribbbleShotLayout(dribbbleShotContainerViewFrame: dribbbleShotContainerViewFrame) + + self.dribbbleShotLayout = dribbbleShotLayout + + case .Audio, .Location: break default: diff --git a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift new file mode 100644 index 00000000..19484ad2 --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift @@ -0,0 +1,149 @@ +// +// FeedDribbbleShotCell.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit +import Ruler + +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width +private let dribbbleShotHeight: CGFloat = Ruler.iPhoneHorizontal(160, 200, 220).value + +class FeedDribbbleShotCell: FeedBasicCell { + + var tapDribbbleShotLinkAction: (NSURL -> Void)? + var tapDribbbleShotMediaAction: ((transitionView: UIView, image: UIImage?, imageURL: NSURL, linkURL: NSURL) -> Void)? + + lazy var logoImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: SocialAccount.Dribbble.iconName) + imageView.frame = CGRect(x: 0, y: 0, width: 18, height: 18) + imageView.tintColor = SocialAccount.Dribbble.tintColor + return imageView + }() + + lazy var mediaContainerView: FeedMediaContainerView = { + let view = FeedMediaContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) + return view + }() + + lazy var socialWorkBorderImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "social_work_border") + return imageView + }() + + lazy var halfMaskImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "social_media_image_mask")) + return imageView + }() + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(logoImageView) + contentView.addSubview(mediaContainerView) + contentView.addSubview(socialWorkBorderImageView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let height = super.heightOfFeed(feed) + (dribbbleShotHeight + 15) + + return ceil(height) + } + + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) + + if needShowSkill, let _ = feed.skill { + logoImageView.frame.origin.x = skillButton.frame.origin.x - 8 - 18 + logoImageView.frame.origin.y = nicknameLabel.frame.origin.y + + } else { + logoImageView.frame.origin.x = screenWidth - 18 - 15 + logoImageView.frame.origin.y = nicknameLabel.frame.origin.y + } + + if let attachment = feed.attachment { + if case let .Dribbble(dribbbleShot) = attachment { + if let URL = NSURL(string: dribbbleShot.imageURLString) { + mediaContainerView.mediaImageView.kf_showIndicatorWhenLoading = true + mediaContainerView.mediaImageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: MediaOptionsInfos) + } + + mediaContainerView.linkContainerView.textLabel.text = dribbbleShot.title + } + } + + mediaContainerView.tapMediaAction = { [weak self] mediaImageView in + + guard let attachment = feed.attachment else { + return + } + + if case .DribbbleShot = feed.kind { + if case let .Dribbble(shot) = attachment, let imageURL = NSURL(string: shot.imageURLString), let linkURL = NSURL(string: shot.htmlURLString) { + self?.tapDribbbleShotMediaAction?(transitionView: mediaImageView, image: mediaImageView.image, imageURL: imageURL, linkURL: linkURL) + } + } + } + + mediaContainerView.linkContainerView.tapAction = { [weak self] in + + guard let attachment = feed.attachment else { + return + } + + if case .DribbbleShot = feed.kind { + if case let .Dribbble(shot) = attachment, let URL = NSURL(string: shot.htmlURLString) { + self?.tapDribbbleShotLinkAction?(URL) + } + } + } + + if let dribbbleShotLayout = layoutCache.layout?.dribbbleShotLayout { + mediaContainerView.frame = dribbbleShotLayout.dribbbleShotContainerViewFrame + socialWorkBorderImageView.frame = mediaContainerView.frame + + } else { + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 + mediaContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) + socialWorkBorderImageView.frame = mediaContainerView.frame + } + mediaContainerView.layoutIfNeeded() + + halfMaskImageView.frame = mediaContainerView.mediaImageView.bounds + mediaContainerView.mediaImageView.maskView = halfMaskImageView + + if layoutCache.layout == nil { + + let dribbbleShotLayout = FeedCellLayout.DribbbleShotLayout(dribbbleShotContainerViewFrame: mediaContainerView.frame) + _newLayout?.dribbbleShotLayout = dribbbleShotLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } + } + } +} + diff --git a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift index 372bf2eb..6171b54d 100644 --- a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift +++ b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift @@ -16,7 +16,7 @@ class FeedGithubRepoCell: FeedBasicCell { lazy var logoImageView: UIImageView = { let imageView = UIImageView() - imageView.image = UIImage(named: "icon_github") + imageView.image = UIImage(named: SocialAccount.Github.iconName) imageView.frame = CGRect(x: 0, y: 0, width: 18, height: 18) imageView.tintColor = SocialAccount.Github.tintColor return imageView From 578b1f070bc8f5d15edd007b977a7bcc99184e54 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 18:37:52 +0800 Subject: [PATCH 30/45] add FeedVoiceCell --- Yep.xcodeproj/project.pbxproj | 4 + .../Feeds/FeedsViewController.swift | 35 +++- Yep/Views/Cells/Feed/FeedCellLayout.swift | 26 ++- .../Cells/Feed/FeedDribbbleShotCell.swift | 6 + Yep/Views/Cells/Feed/FeedVoiceCell.swift | 173 ++++++++++++++++++ 5 files changed, 234 insertions(+), 10 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedVoiceCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 5c04b591..7eb498a6 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -306,6 +306,7 @@ 50E392BE1C228BF000C0CECB /* FeedCellLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */; }; 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */; }; 50E392C21C22B9E400C0CECB /* FeedDribbbleShotCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */; }; + 50E392C41C22C0F600C0CECB /* FeedVoiceCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -673,6 +674,7 @@ 50E392BD1C228BF000C0CECB /* FeedCellLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedCellLayout.swift; path = Views/Cells/Feed/FeedCellLayout.swift; sourceTree = ""; }; 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedGithubRepoCell.swift; path = Views/Cells/Feed/FeedGithubRepoCell.swift; sourceTree = ""; }; 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedDribbbleShotCell.swift; path = Views/Cells/Feed/FeedDribbbleShotCell.swift; sourceTree = ""; }; + 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedVoiceCell.swift; path = Views/Cells/Feed/FeedVoiceCell.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1974,6 +1976,7 @@ 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */, 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */, + 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */, ); name = Feed; sourceTree = ""; @@ -2696,6 +2699,7 @@ 50DEE0411BE7626100015741 /* YepHelpers.swift in Sources */, 501138311BCB62A20055A014 /* FeedConversationCell.swift in Sources */, 502AE5401AB88862005BD199 /* SkillRankCell.swift in Sources */, + 50E392C41C22C0F600C0CECB /* FeedVoiceCell.swift in Sources */, 50C090A01ADE391600CC6389 /* AddSkillsReusableView.swift in Sources */, 84385C4A1B85BE200071130D /* ShowStepMeetViewController.swift in Sources */, 5023DE2D1AB685ED00B3EE96 /* DiscoverViewController.swift in Sources */, diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 816bc0b7..cd443370 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -112,8 +112,9 @@ class FeedsViewController: BaseViewController { private let feedNormalImagesCellID = "FeedNormalImagesCell" private let feedAnyImagesCellID = "FeedAnyImagesCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" - private let feedGithubRepoCellID = "FeedGithubRepoCell" - private let feedDribbbleShotCellID = "FeedDribbbleShotCell" + private let feedGithubRepoCellID = "FeedGithubRepoCell" + private let feedDribbbleShotCellID = "FeedDribbbleShotCell" + private let feedVoiceCellID = "FeedVoiceCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" private lazy var noFeedsFooterView: InfoView = InfoView(NSLocalizedString("No Feeds.", comment: "")) @@ -150,7 +151,7 @@ class FeedsViewController: BaseViewController { let indexPath = NSIndexPath(forRow: index, inSection: Section.Feed.rawValue) - if let cell = feedsTableView.cellForRowAtIndexPath(indexPath) as? FeedSocialWorkCell { + if let cell = feedsTableView.cellForRowAtIndexPath(indexPath) as? FeedVoiceCell { cell.audioPlayedDuration = 0 } @@ -215,7 +216,10 @@ class FeedsViewController: BaseViewController { case .DribbbleShot: height = FeedDribbbleShotCell.heightOfFeed(feed) - case .Audio, .Location: + case .Audio: + height = FeedVoiceCell.heightOfFeed(feed) + + case .Location: height = FeedSocialWorkCell.heightOfFeed(feed) default: @@ -333,6 +337,7 @@ class FeedsViewController: BaseViewController { feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) feedsTableView.registerClass(FeedGithubRepoCell.self, forCellReuseIdentifier: feedGithubRepoCellID) feedsTableView.registerClass(FeedDribbbleShotCell.self, forCellReuseIdentifier: feedDribbbleShotCellID) + feedsTableView.registerClass(FeedVoiceCell.self, forCellReuseIdentifier: feedVoiceCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -601,7 +606,7 @@ class FeedsViewController: BaseViewController { let indexPath = NSIndexPath(forRow: index, inSection: Section.Feed.rawValue) - if let cell = feedsTableView.cellForRowAtIndexPath(indexPath) as? FeedSocialWorkCell { + if let cell = feedsTableView.cellForRowAtIndexPath(indexPath) as? FeedVoiceCell { cell.audioPlayedDuration = currentTime } @@ -878,7 +883,11 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { let cell = tableView.dequeueReusableCellWithIdentifier(feedDribbbleShotCellID) as! FeedDribbbleShotCell return cell - case .Audio, .Location: + case .Audio: + let cell = tableView.dequeueReusableCellWithIdentifier(feedVoiceCellID) as! FeedVoiceCell + return cell + + case .Location: let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell return cell @@ -1081,9 +1090,9 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { mediaPreviewWindow.makeKeyAndVisible() } - case .Audio, .Location: + case .Audio: - guard let cell = cell as? FeedSocialWorkCell else { + guard let cell = cell as? FeedVoiceCell else { break } @@ -1129,7 +1138,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { let indexPath = NSIndexPath(forRow: index, inSection: Section.Feed.rawValue) - if let cell = strongSelf.feedsTableView.cellForRowAtIndexPath(indexPath) as? FeedSocialWorkCell { + if let cell = strongSelf.feedsTableView.cellForRowAtIndexPath(indexPath) as? FeedVoiceCell { cell.audioPlaying = false } @@ -1150,6 +1159,14 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { } } + case .Location: + + guard let cell = cell as? FeedSocialWorkCell else { + break + } + + cell.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) + cell.tapLocationAction = { locationName, locationCoordinate in let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: locationCoordinate, addressDictionary: nil)) diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index 95032f9b..b6df41f2 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -92,6 +92,11 @@ struct FeedCellLayout { } var dribbbleShotLayout: DribbbleShotLayout? + struct AudioLayout { + let voiceContainerViewFrame: CGRect + } + var audioLayout: AudioLayout? + // MARK: - Init init(height: CGFloat, basicLayout: BasicLayout) { @@ -230,6 +235,7 @@ struct FeedCellLayout { self.githubRepoLayout = githubRepoLayout case .DribbbleShot: + let height: CGFloat = leftBottomLabelFrame.origin.y - beginY - 15 let dribbbleShotContainerViewFrame = CGRect(x: 65, y: beginY, width: screenWidth - 65 - 60, height: height) @@ -237,7 +243,25 @@ struct FeedCellLayout { self.dribbbleShotLayout = dribbbleShotLayout - case .Audio, .Location: + case .Audio: + + if let attachment = feed.attachment { + if case let .Audio(audioInfo) = attachment { + let timeLengthString = String(format: "%.1f\"", audioInfo.duration) + let rect = timeLengthString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.voiceTimeLengthTextAttributes, context: nil) + + let width = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 + let y = beginY + 2 + + let voiceContainerViewFrame = CGRect(x: 65, y: y, width: width, height: 40) + + let audioLayout = FeedCellLayout.AudioLayout(voiceContainerViewFrame: voiceContainerViewFrame) + + self.audioLayout = audioLayout + } + } + + case .Location: break default: diff --git a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift index 19484ad2..a859ce58 100644 --- a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift +++ b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift @@ -67,6 +67,12 @@ class FeedDribbbleShotCell: FeedBasicCell { return ceil(height) } + override func prepareForReuse() { + super.prepareForReuse() + + mediaContainerView.mediaImageView.image = nil + } + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { var _newLayout: FeedCellLayout? diff --git a/Yep/Views/Cells/Feed/FeedVoiceCell.swift b/Yep/Views/Cells/Feed/FeedVoiceCell.swift new file mode 100644 index 00000000..2f7320e6 --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedVoiceCell.swift @@ -0,0 +1,173 @@ +// +// FeedVoiceCell.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit +import RealmSwift + +class FeedVoiceCell: FeedBasicCell { + + lazy var voiceContainerView: FeedVoiceContainerView = { + let view = FeedVoiceContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) + return view + }() + + var audioPlaying: Bool = false { + willSet { + voiceContainerView.audioPlaying = newValue + } + } + var playOrPauseAudioAction: (FeedVoiceCell -> Void)? + var audioPlayedDuration: NSTimeInterval = 0 { + willSet { + updateVoiceContainerView() + } + } + private func updateVoiceContainerView() { + + guard let feed = feed, realm = try? Realm(), feedAudio = FeedAudio.feedAudioWithFeedID(feed.id, inRealm: realm) else { + return + } + + if let (audioDuration, audioSamples) = feedAudio.audioMetaInfo { + + voiceContainerView.voiceSampleView.samples = audioSamples + voiceContainerView.voiceSampleView.progress = CGFloat(audioPlayedDuration / audioDuration) + } + + if let playingFeedAudio = YepAudioService.sharedManager.playingFeedAudio where playingFeedAudio.feedID == feedAudio.feedID, let audioPlayer = YepAudioService.sharedManager.audioPlayer where audioPlayer.playing { + audioPlaying = true + } else { + audioPlaying = false + } + } + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(voiceContainerView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let height = super.heightOfFeed(feed) + (44 + 15) + + return ceil(height) + } + + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) + + if let attachment = feed.attachment { + if case let .Audio(audioInfo) = attachment { + + voiceContainerView.voiceSampleView.sampleColor = UIColor.leftWaveColor() + voiceContainerView.voiceSampleView.samples = audioInfo.sampleValues + + let timeLengthString = String(format: "%.1f\"", audioInfo.duration) + voiceContainerView.timeLengthLabel.text = timeLengthString + + if let audioLayout = layoutCache.layout?.audioLayout { + voiceContainerView.frame = audioLayout.voiceContainerViewFrame + + } else { + let rect = timeLengthString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.voiceTimeLengthTextAttributes, context: nil) + + let width = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + 2 + voiceContainerView.frame = CGRect(x: 65, y: y, width: width, height: 40) + } + + if let realm = try? Realm() { + + let feedAudio = FeedAudio.feedAudioWithFeedID(audioInfo.feedID, inRealm: realm) + + if let feedAudio = feedAudio, playingFeedAudio = YepAudioService.sharedManager.playingFeedAudio, audioPlayer = YepAudioService.sharedManager.audioPlayer { + audioPlaying = (feedAudio.feedID == playingFeedAudio.feedID) && audioPlayer.playing + } else { + audioPlaying = false + } + + let needDownload = (feedAudio == nil) || (feedAudio?.fileName ?? "").isEmpty + + if needDownload { + if let URL = NSURL(string: audioInfo.URLString) { + YepDownloader.downloadDataFromURL(URL, reportProgress: { progress in + println("audio progress: \(progress)") + + }, finishedAction: { data in + println("audio finish: \(data.length)") + + dispatch_async(dispatch_get_main_queue()) { + if let realm = try? Realm() { + + var feedAudio = FeedAudio.feedAudioWithFeedID(audioInfo.feedID, inRealm: realm) + + if feedAudio == nil { + let newFeedAudio = FeedAudio() + newFeedAudio.feedID = audioInfo.feedID + newFeedAudio.URLString = audioInfo.URLString + newFeedAudio.metadata = audioInfo.metaData + + let _ = try? realm.write { + realm.add(newFeedAudio) + } + + feedAudio = newFeedAudio + } + + if let feedAudio = feedAudio where feedAudio.fileName.isEmpty { + + let fileName = NSUUID().UUIDString + if let _ = NSFileManager.saveMessageAudioData(data, withName: fileName) { + let _ = try? realm.write { + feedAudio.fileName = fileName + } + } + } + } + } + }) + } + } + + voiceContainerView.playOrPauseAudioAction = { [weak self] in + if let strongSelf = self { + strongSelf.playOrPauseAudioAction?(strongSelf) + } + } + } + } + } + + if layoutCache.layout == nil { + + let audioLayout = FeedCellLayout.AudioLayout(voiceContainerViewFrame: voiceContainerView.frame) + _newLayout?.audioLayout = audioLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } + } + } +} + From 5a413b11c116d04c39335a1f168d2275ced96184 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 18:58:36 +0800 Subject: [PATCH 31/45] add FeedLocationCell --- Yep.xcodeproj/project.pbxproj | 4 + .../Feeds/FeedsViewController.swift | 10 +- Yep/Views/Cells/Feed/FeedCellLayout.swift | 13 +- Yep/Views/Cells/Feed/FeedLocationCell.swift | 129 ++++++++++++++++++ 4 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 Yep/Views/Cells/Feed/FeedLocationCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 7eb498a6..8c8ddfdc 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -307,6 +307,7 @@ 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */; }; 50E392C21C22B9E400C0CECB /* FeedDribbbleShotCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */; }; 50E392C41C22C0F600C0CECB /* FeedVoiceCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */; }; + 50E392C61C22C82800C0CECB /* FeedLocationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E392C51C22C82800C0CECB /* FeedLocationCell.swift */; }; 50E61CEB1AF1F69D00908A9D /* ConversationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */; }; 50EB8C5E1AE78AB9001AC1EE /* YepAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */; }; 50EB8CBF1AE89ED8001AC1EE /* ChatLeftVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */; }; @@ -675,6 +676,7 @@ 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedGithubRepoCell.swift; path = Views/Cells/Feed/FeedGithubRepoCell.swift; sourceTree = ""; }; 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedDribbbleShotCell.swift; path = Views/Cells/Feed/FeedDribbbleShotCell.swift; sourceTree = ""; }; 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedVoiceCell.swift; path = Views/Cells/Feed/FeedVoiceCell.swift; sourceTree = ""; }; + 50E392C51C22C82800C0CECB /* FeedLocationCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedLocationCell.swift; path = Views/Cells/Feed/FeedLocationCell.swift; sourceTree = ""; }; 50E61CEA1AF1F69D00908A9D /* ConversationTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationTitleView.swift; path = Views/ConversationTitle/ConversationTitleView.swift; sourceTree = ""; }; 50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAsset.swift; path = Helpers/YepAsset.swift; sourceTree = ""; }; 50EB8CBD1AE89ED8001AC1EE /* ChatLeftVideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftVideoCell.swift; path = Views/Cells/ChatLeftVideo/ChatLeftVideoCell.swift; sourceTree = ""; }; @@ -1977,6 +1979,7 @@ 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */, 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */, 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */, + 50E392C51C22C82800C0CECB /* FeedLocationCell.swift */, ); name = Feed; sourceTree = ""; @@ -2755,6 +2758,7 @@ 502AE5291AB81076005BD199 /* YepService.swift in Sources */, 50C090A41ADE46D500CC6389 /* RegisterSelectSkillsViewController.swift in Sources */, 50CC4FA21C1AC0EE00B6A263 /* UITableView+Yep.swift in Sources */, + 50E392C61C22C82800C0CECB /* FeedLocationCell.swift in Sources */, 502AE51E1AB712D2005BD199 /* RegisterPickNameViewController.swift in Sources */, 50B8E6161B40F9E700C17EA1 /* YepDownloader.swift in Sources */, 50894D101AEE3C25000981AF /* YepHUD.swift in Sources */, diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index cd443370..74388f22 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -111,10 +111,10 @@ class FeedsViewController: BaseViewController { private let feedBiggerImageCellID = "FeedBiggerImageCell" private let feedNormalImagesCellID = "FeedNormalImagesCell" private let feedAnyImagesCellID = "FeedAnyImagesCell" - private let feedSocialWorkCellID = "FeedSocialWorkCell" private let feedGithubRepoCellID = "FeedGithubRepoCell" private let feedDribbbleShotCellID = "FeedDribbbleShotCell" private let feedVoiceCellID = "FeedVoiceCell" + private let feedLocationCellID = "FeedLocationCell" private let loadMoreTableViewCellID = "LoadMoreTableViewCell" private lazy var noFeedsFooterView: InfoView = InfoView(NSLocalizedString("No Feeds.", comment: "")) @@ -220,7 +220,7 @@ class FeedsViewController: BaseViewController { height = FeedVoiceCell.heightOfFeed(feed) case .Location: - height = FeedSocialWorkCell.heightOfFeed(feed) + height = FeedLocationCell.heightOfFeed(feed) default: height = FeedBasicCell.heightOfFeed(feed) @@ -334,10 +334,10 @@ class FeedsViewController: BaseViewController { feedsTableView.registerClass(FeedBiggerImageCell.self, forCellReuseIdentifier: feedBiggerImageCellID) feedsTableView.registerClass(FeedNormalImagesCell.self, forCellReuseIdentifier: feedNormalImagesCellID) feedsTableView.registerClass(FeedAnyImagesCell.self, forCellReuseIdentifier: feedAnyImagesCellID) - feedsTableView.registerClass(FeedSocialWorkCell.self, forCellReuseIdentifier: feedSocialWorkCellID) feedsTableView.registerClass(FeedGithubRepoCell.self, forCellReuseIdentifier: feedGithubRepoCellID) feedsTableView.registerClass(FeedDribbbleShotCell.self, forCellReuseIdentifier: feedDribbbleShotCellID) feedsTableView.registerClass(FeedVoiceCell.self, forCellReuseIdentifier: feedVoiceCellID) + feedsTableView.registerClass(FeedLocationCell.self, forCellReuseIdentifier: feedLocationCellID) feedsTableView.registerNib(UINib(nibName: loadMoreTableViewCellID, bundle: nil), forCellReuseIdentifier: loadMoreTableViewCellID) @@ -888,7 +888,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return cell case .Location: - let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell + let cell = tableView.dequeueReusableCellWithIdentifier(feedLocationCellID) as! FeedLocationCell return cell default: @@ -1161,7 +1161,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { case .Location: - guard let cell = cell as? FeedSocialWorkCell else { + guard let cell = cell as? FeedLocationCell else { break } diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index b6df41f2..b4f0213b 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -97,6 +97,11 @@ struct FeedCellLayout { } var audioLayout: AudioLayout? + struct LocationLayout { + let locationContainerViewFrame: CGRect + } + var locationLayout: LocationLayout? + // MARK: - Init init(height: CGFloat, basicLayout: BasicLayout) { @@ -262,7 +267,13 @@ struct FeedCellLayout { } case .Location: - break + + let height: CGFloat = leftBottomLabelFrame.origin.y - beginY - 15 + let locationContainerViewFrame = CGRect(x: 65, y: beginY, width: screenWidth - 65 - 60, height: height) + + let locationLayout = FeedCellLayout.LocationLayout(locationContainerViewFrame: locationContainerViewFrame) + + self.locationLayout = locationLayout default: break diff --git a/Yep/Views/Cells/Feed/FeedLocationCell.swift b/Yep/Views/Cells/Feed/FeedLocationCell.swift new file mode 100644 index 00000000..af71b36f --- /dev/null +++ b/Yep/Views/Cells/Feed/FeedLocationCell.swift @@ -0,0 +1,129 @@ +// +// FeedLocationCell.swift +// Yep +// +// Created by nixzhu on 15/12/17. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit +import MapKit + +private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width + +class FeedLocationCell: FeedBasicCell { + + var tapLocationAction: ((locationName: String, locationCoordinate: CLLocationCoordinate2D) -> Void)? + + lazy var locationContainerView: FeedLocationContainerView = { + let view = FeedLocationContainerView() + view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) + return view + }() + + lazy var socialWorkBorderImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "social_work_border") + return imageView + }() + + lazy var halfMaskImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "social_media_image_mask")) + return imageView + }() + + override func prepareForReuse() { + super.prepareForReuse() + + locationContainerView.mapImageView.image = nil + } + + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(locationContainerView) + contentView.addSubview(socialWorkBorderImageView) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func setSelected(selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let height = super.heightOfFeed(feed) + (110 + 15) + + return ceil(height) + } + + override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { + + var _newLayout: FeedCellLayout? + super.configureWithFeed(feed, layoutCache: (layout: layoutCache.layout, update: { newLayout in + _newLayout = newLayout + }), needShowSkill: needShowSkill) + + + if let attachment = feed.attachment { + if case let .Location(locationInfo) = attachment { + + let location = CLLocation(latitude: locationInfo.latitude, longitude: locationInfo.longitude) + let size = CGSize(width: UIScreen.mainScreen().bounds.width - 65 - 60, height: 110 - locationContainerView.nameLabel.bounds.height) + locationContainerView.mapImageView.yep_showActivityIndicatorWhenLoading = true + locationContainerView.mapImageView.yep_setImageOfLocation(location, withSize: size) + + if locationInfo.name.isEmpty { + locationContainerView.nameLabel.text = NSLocalizedString("Unknown location", comment: "") + + } else { + locationContainerView.nameLabel.text = locationInfo.name + } + } + } + + locationContainerView.mapImageView.maskView = halfMaskImageView + + locationContainerView.tapAction = { [weak self] in + guard let attachment = feed.attachment else { + return + } + + if case .Location = feed.kind { + if case let .Location(locationInfo) = attachment { + self?.tapLocationAction?(locationName: locationInfo.name, locationCoordinate: locationInfo.coordinate) + } + } + } + + if let locationLayout = layoutCache.layout?.locationLayout { + locationContainerView.frame = locationLayout.locationContainerViewFrame + socialWorkBorderImageView.frame = locationContainerView.frame + + } else { + let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 + locationContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) + socialWorkBorderImageView.frame = locationContainerView.frame + } + locationContainerView.layoutIfNeeded() + + halfMaskImageView.frame = locationContainerView.mapImageView.bounds + locationContainerView.mapImageView.maskView = halfMaskImageView + + if layoutCache.layout == nil { + + let locationLayout = FeedCellLayout.LocationLayout(locationContainerViewFrame: locationContainerView.frame) + _newLayout?.locationLayout = locationLayout + + if let newLayout = _newLayout { + layoutCache.update(layout: newLayout) + } + } + } +} From 8dc82a7c3914b0246e8e807a698c51352ebc1f0d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 19:00:01 +0800 Subject: [PATCH 32/45] delete FeedSocialWorkCell --- Yep.xcodeproj/project.pbxproj | 4 - Yep/Views/Cells/Feed/FeedSocialWorkCell.swift | 416 ------------------ 2 files changed, 420 deletions(-) delete mode 100644 Yep/Views/Cells/Feed/FeedSocialWorkCell.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 8c8ddfdc..40c48c75 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -182,7 +182,6 @@ 5080EB1C1B93F43A006F3C2D /* PodsHelpYepViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080EB1B1B93F43A006F3C2D /* PodsHelpYepViewController.swift */; }; 5080EB1F1B93F932006F3C2D /* NSBundle+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080EB1E1B93F932006F3C2D /* NSBundle+Yep.swift */; }; 50858EBB1C22487900EDE492 /* FeedBasicCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */; }; - 50858EBD1C22488100EDE492 /* FeedSocialWorkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */; }; 50858EBF1C224DA900EDE492 /* FeedBiggerImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */; }; 50894CF11AEA4726000981AF /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF01AEA4726000981AF /* SettingsViewController.swift */; }; 50894CF51AEA4A01000981AF /* SettingsUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */; }; @@ -551,7 +550,6 @@ 5080EB1B1B93F43A006F3C2D /* PodsHelpYepViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PodsHelpYepViewController.swift; path = ViewControllers/PodsHelpYep/PodsHelpYepViewController.swift; sourceTree = ""; }; 5080EB1E1B93F932006F3C2D /* NSBundle+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSBundle+Yep.swift"; path = "Extensions/NSBundle+Yep.swift"; sourceTree = ""; }; 50858EBA1C22487900EDE492 /* FeedBasicCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBasicCell.swift; path = Views/Cells/Feed/FeedBasicCell.swift; sourceTree = ""; }; - 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedSocialWorkCell.swift; path = Views/Cells/Feed/FeedSocialWorkCell.swift; sourceTree = ""; }; 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedBiggerImageCell.swift; path = Views/Cells/Feed/FeedBiggerImageCell.swift; sourceTree = ""; }; 50894CF01AEA4726000981AF /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsViewController.swift; path = ViewControllers/Settings/SettingsViewController.swift; sourceTree = ""; }; 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsUserCell.swift; path = Views/Cells/SettingsUser/SettingsUserCell.swift; sourceTree = ""; }; @@ -1975,7 +1973,6 @@ 50858EBE1C224DA900EDE492 /* FeedBiggerImageCell.swift */, 50E392BB1C22752C00C0CECB /* FeedNormalImagesCell.swift */, 50F5AF8A1BBBB64C0033C9BC /* FeedAnyImagesCell.swift */, - 50858EBC1C22488100EDE492 /* FeedSocialWorkCell.swift */, 50E392BF1C22B30300C0CECB /* FeedGithubRepoCell.swift */, 50E392C11C22B9E400C0CECB /* FeedDribbbleShotCell.swift */, 50E392C31C22C0F600C0CECB /* FeedVoiceCell.swift */, @@ -2779,7 +2776,6 @@ 502B60641BD1208E00D9C17E /* CameraCell.swift in Sources */, 505082371C21377E00643CEB /* FeedVoiceContainerView.swift in Sources */, 6AB0DF5A1BE169000052BED1 /* ShareProfileView.swift in Sources */, - 50858EBD1C22488100EDE492 /* FeedSocialWorkCell.swift in Sources */, 502AE5351AB8649F005BD199 /* LoginByMobileViewController.swift in Sources */, 506BB7F91AE5069500C1A2A0 /* RegisterPickSkillsSelectSkillsTransitionManager.swift in Sources */, 50B8E6181B41340A00C17EA1 /* MessageLoadingProgressView.swift in Sources */, diff --git a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift b/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift deleted file mode 100644 index 91ab639b..00000000 --- a/Yep/Views/Cells/Feed/FeedSocialWorkCell.swift +++ /dev/null @@ -1,416 +0,0 @@ -// -// FeedSocialWorkCell.swift -// Yep -// -// Created by nixzhu on 15/11/19. -// Copyright © 2015年 Catch Inc. All rights reserved. -// - -import UIKit -import Kingfisher -import Ruler -import RealmSwift -import MapKit - -private let dribbbleShotHeight: CGFloat = Ruler.iPhoneHorizontal(160, 200, 220).value -private let screenWidth: CGFloat = UIScreen.mainScreen().bounds.width - -class FeedSocialWorkCell: FeedBasicCell { - - lazy var logoImageView: UIImageView = { - let imageView = UIImageView() - imageView.image = UIImage(named: "icon_github") - imageView.frame = CGRect(x: 0, y: 0, width: 18, height: 18) - return imageView - }() - - lazy var mediaContainerView: FeedMediaContainerView = { - let view = FeedMediaContainerView() - view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) - return view - }() - - lazy var githubRepoContainerView: FeedGithubRepoContainerView = { - let view = FeedGithubRepoContainerView() - view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) - return view - }() - - lazy var voiceContainerView: FeedVoiceContainerView = { - let view = FeedVoiceContainerView() - view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) - return view - }() - - lazy var locationContainerView: FeedLocationContainerView = { - let view = FeedLocationContainerView() - view.frame = CGRect(x: 0, y: 0, width: 200, height: 200) - return view - }() - - lazy var socialWorkBorderImageView: UIImageView = { - let imageView = UIImageView() - imageView.image = UIImage(named: "social_work_border") - return imageView - }() - - lazy var halfMaskImageView: UIImageView = { - let imageView = UIImageView(image: UIImage(named: "social_media_image_mask")) - return imageView - }() - - 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 { - voiceContainerView.audioPlaying = newValue - } - } - var playOrPauseAudioAction: (FeedSocialWorkCell -> Void)? - var audioPlayedDuration: NSTimeInterval = 0 { - willSet { - updateVoiceContainerView() - } - } - private func updateVoiceContainerView() { - - guard let feed = feed, realm = try? Realm(), feedAudio = FeedAudio.feedAudioWithFeedID(feed.id, inRealm: realm) else { - return - } - - if let (audioDuration, audioSamples) = feedAudio.audioMetaInfo { - - voiceContainerView.voiceSampleView.samples = audioSamples - voiceContainerView.voiceSampleView.progress = CGFloat(audioPlayedDuration / audioDuration) - } - - if let playingFeedAudio = YepAudioService.sharedManager.playingFeedAudio where playingFeedAudio.feedID == feedAudio.feedID, let audioPlayer = YepAudioService.sharedManager.audioPlayer where audioPlayer.playing { - audioPlaying = true - } else { - audioPlaying = false - } - } - - override func layoutSubviews() { - super.layoutSubviews() - - if feed?.hasSocialImage ?? false { - halfMaskImageView.frame = mediaContainerView.mediaImageView.bounds - } - - if feed?.hasMapImage ?? false { - halfMaskImageView.frame = locationContainerView.mapImageView.bounds - } - } - - override func prepareForReuse() { - super.prepareForReuse() - - mediaContainerView.mediaImageView.image = nil - locationContainerView.mapImageView.image = nil - } - - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - - contentView.addSubview(logoImageView) - contentView.addSubview(mediaContainerView) - contentView.addSubview(githubRepoContainerView) - contentView.addSubview(voiceContainerView) - contentView.addSubview(locationContainerView) - contentView.addSubview(socialWorkBorderImageView) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func setSelected(selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) - - // Configure the view for the selected state - } - - override class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - - var height = super.heightOfFeed(feed) - - switch feed.kind { - case .GithubRepo: - height += (80 + 15) - case .DribbbleShot: - height += (dribbbleShotHeight + 15) - case .Audio: - height += (44 + 15) - case .Location: - height += (110 + 15) - default: - break - } - - return ceil(height) - } - - override func configureWithFeed(feed: DiscoveredFeed, layoutCache: FeedCellLayout.Cache, needShowSkill: Bool) { - super.configureWithFeed(feed, layoutCache: layoutCache, needShowSkill: needShowSkill) - - if let - accountName = feed.kind.accountName, - socialAccount = SocialAccount(rawValue: accountName) { - logoImageView.image = UIImage(named: socialAccount.iconName) - logoImageView.tintColor = socialAccount.tintColor - logoImageView.hidden = false - - if needShowSkill, let _ = feed.skill { - logoImageView.frame.origin.x = skillButton.frame.origin.x - 8 - 18 - logoImageView.frame.origin.y = nicknameLabel.frame.origin.y - } else { - logoImageView.frame.origin.x = screenWidth - 18 - 15 - logoImageView.frame.origin.y = nicknameLabel.frame.origin.y - } - - } else { - logoImageView.hidden = true - } - - var socialWorkImageURL: NSURL? - - switch feed.kind { - - case .GithubRepo: - - mediaContainerView.hidden = true - githubRepoContainerView.hidden = false - voiceContainerView.hidden = true - locationContainerView.hidden = true - socialWorkBorderImageView.hidden = false - - if let attachment = feed.attachment { - if case let .Github(githubRepo) = attachment { - githubRepoContainerView.nameLabel.text = githubRepo.name - githubRepoContainerView.descriptionLabel.text = githubRepo.description - } - } - - githubRepoContainerView.tapAction = { [weak self] in - guard let attachment = feed.attachment else { - return - } - - if case .GithubRepo = feed.kind { - if case let .Github(repo) = attachment, let URL = NSURL(string: repo.URLString) { - self?.tapGithubRepoLinkAction?(URL) - } - } - } - - //socialWorkContainerViewHeightConstraint.constant = 80 - let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 - let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 - githubRepoContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) - - socialWorkBorderImageView.frame = githubRepoContainerView.frame - - case .DribbbleShot: - - mediaContainerView.hidden = false - githubRepoContainerView.hidden = true - voiceContainerView.hidden = true - locationContainerView.hidden = true - socialWorkBorderImageView.hidden = false - - if let attachment = feed.attachment { - if case let .Dribbble(dribbbleShot) = attachment { - socialWorkImageURL = NSURL(string: dribbbleShot.imageURLString) - mediaContainerView.linkContainerView.textLabel.text = dribbbleShot.title - } - } - - mediaContainerView.tapMediaAction = { [weak self] mediaImageView in - - guard let attachment = feed.attachment else { - return - } - - if case .DribbbleShot = feed.kind { - if case let .Dribbble(shot) = attachment, let imageURL = NSURL(string: shot.imageURLString), let linkURL = NSURL(string: shot.htmlURLString) { - self?.tapDribbbleShotMediaAction?(transitionView: mediaImageView, image: mediaImageView.image, imageURL: imageURL, linkURL: linkURL) - } - } - } - - mediaContainerView.linkContainerView.tapAction = { [weak self] in - - guard let attachment = feed.attachment else { - return - } - - if case .DribbbleShot = feed.kind { - if case let .Dribbble(shot) = attachment, let URL = NSURL(string: shot.htmlURLString) { - self?.tapDribbbleShotLinkAction?(URL) - } - } - } - - mediaContainerView.mediaImageView.maskView = halfMaskImageView - - //socialWorkContainerViewHeightConstraint.constant = dribbbleShotHeight - //contentView.layoutIfNeeded() - let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 - let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 - mediaContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) - mediaContainerView.layoutIfNeeded() - - socialWorkBorderImageView.frame = mediaContainerView.frame - - case .Audio: - - mediaContainerView.hidden = true - githubRepoContainerView.hidden = true - voiceContainerView.hidden = false - locationContainerView.hidden = true - socialWorkBorderImageView.hidden = true - - if let attachment = feed.attachment { - if case let .Audio(audioInfo) = attachment { - - voiceContainerView.voiceSampleView.sampleColor = UIColor.leftWaveColor() - voiceContainerView.voiceSampleView.samples = audioInfo.sampleValues - - let timeLengthString = String(format: "%.1f\"", audioInfo.duration) - voiceContainerView.timeLengthLabel.text = timeLengthString - - let rect = timeLengthString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.voiceTimeLengthTextAttributes, context: nil) - - //voiceContainerViewWidthConstraint.constant = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 - let width = 7 + 30 + 5 + CGFloat(audioInfo.sampleValues.count) * 3 + 5 + rect.width + 5 - let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 + 2 - voiceContainerView.frame = CGRect(x: 65, y: y, width: width, height: 40) - - if let realm = try? Realm() { - - let feedAudio = FeedAudio.feedAudioWithFeedID(audioInfo.feedID, inRealm: realm) - - if let feedAudio = feedAudio, playingFeedAudio = YepAudioService.sharedManager.playingFeedAudio, audioPlayer = YepAudioService.sharedManager.audioPlayer { - audioPlaying = (feedAudio.feedID == playingFeedAudio.feedID) && audioPlayer.playing - } else { - audioPlaying = false - } - - let needDownload = (feedAudio == nil) || (feedAudio?.fileName ?? "").isEmpty - - if needDownload { - if let URL = NSURL(string: audioInfo.URLString) { - YepDownloader.downloadDataFromURL(URL, reportProgress: { progress in - println("audio progress: \(progress)") - - }, finishedAction: { data in - println("audio finish: \(data.length)") - - dispatch_async(dispatch_get_main_queue()) { - if let realm = try? Realm() { - - var feedAudio = FeedAudio.feedAudioWithFeedID(audioInfo.feedID, inRealm: realm) - - if feedAudio == nil { - let newFeedAudio = FeedAudio() - newFeedAudio.feedID = audioInfo.feedID - newFeedAudio.URLString = audioInfo.URLString - newFeedAudio.metadata = audioInfo.metaData - - let _ = try? realm.write { - realm.add(newFeedAudio) - } - - feedAudio = newFeedAudio - } - - if let feedAudio = feedAudio where feedAudio.fileName.isEmpty { - - let fileName = NSUUID().UUIDString - if let _ = NSFileManager.saveMessageAudioData(data, withName: fileName) { - let _ = try? realm.write { - feedAudio.fileName = fileName - } - } - } - } - } - }) - } - } - - voiceContainerView.playOrPauseAudioAction = { [weak self] in - if let strongSelf = self { - strongSelf.playOrPauseAudioAction?(strongSelf) - } - } - } - } - } - - //socialWorkContainerViewHeightConstraint.constant = 44 - - case .Location: - - mediaContainerView.hidden = true - githubRepoContainerView.hidden = true - voiceContainerView.hidden = true - locationContainerView.hidden = false - socialWorkBorderImageView.hidden = false - - if let attachment = feed.attachment { - if case let .Location(locationInfo) = attachment { - - let location = CLLocation(latitude: locationInfo.latitude, longitude: locationInfo.longitude) - let size = CGSize(width: UIScreen.mainScreen().bounds.width - 65 - 60, height: 110 - locationContainerView.nameLabel.bounds.height) - locationContainerView.mapImageView.yep_showActivityIndicatorWhenLoading = true - locationContainerView.mapImageView.yep_setImageOfLocation(location, withSize: size) - - if locationInfo.name.isEmpty { - locationContainerView.nameLabel.text = NSLocalizedString("Unknown location", comment: "") - - } else { - locationContainerView.nameLabel.text = locationInfo.name - } - } - } - - locationContainerView.mapImageView.maskView = halfMaskImageView - - locationContainerView.tapAction = { [weak self] in - guard let attachment = feed.attachment else { - return - } - - if case .Location = feed.kind { - if case let .Location(locationInfo) = attachment { - self?.tapLocationAction?(locationName: locationInfo.name, locationCoordinate: locationInfo.coordinate) - } - } - } - - //socialWorkContainerViewHeightConstraint.constant = 110 - //contentView.layoutIfNeeded() - let y = messageTextView.frame.origin.y + messageTextView.frame.height + 15 - let height: CGFloat = leftBottomLabel.frame.origin.y - y - 15 - locationContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65 - 60, height: height) - locationContainerView.layoutIfNeeded() - - socialWorkBorderImageView.frame = locationContainerView.frame - - default: - break - } - - if let URL = socialWorkImageURL { - // ref https://github.com/onevcat/Kingfisher/pull/171 - mediaContainerView.mediaImageView.kf_showIndicatorWhenLoading = true - mediaContainerView.mediaImageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: MediaOptionsInfos) - } - } -} - From 132f5e9e35cf20f6476d18f8aaa7b0c5f7e709be Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Dec 2015 19:07:20 +0800 Subject: [PATCH 33/45] height in FeedCellLayout --- Yep/Views/Cells/Feed/FeedCellLayout.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index b4f0213b..330829f5 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -129,8 +129,17 @@ struct FeedCellLayout { height = FeedAnyImagesCell.heightOfFeed(feed) } - case .GithubRepo, .DribbbleShot, .Audio, .Location: - height = FeedSocialWorkCell.heightOfFeed(feed) + case .GithubRepo: + height = FeedGithubRepoCell.heightOfFeed(feed) + + case .DribbbleShot: + height = FeedDribbbleShotCell.heightOfFeed(feed) + + case .Audio: + height = FeedVoiceCell.heightOfFeed(feed) + + case .Location: + height = FeedLocationCell.heightOfFeed(feed) default: height = FeedBasicCell.heightOfFeed(feed) From 5cc540e879ed0637adce3cb2c8be2e0f90cf4afa Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 09:15:43 +0800 Subject: [PATCH 34/45] refactor heightOfFeed use FeedCellLayout --- .../Feeds/FeedsViewController.swift | 64 ++++--------------- 1 file changed, 12 insertions(+), 52 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 74388f22..1f5e1058 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -182,58 +182,6 @@ class FeedsViewController: BaseViewController { feedsTableView.tableFooterView = feeds.isEmpty ? noFeedsFooterView : UIView() } - private var feedHeightHash = [String: CGFloat]() - - private func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { - - let key = feed.id - - if let height = feedHeightHash[key] { - return height - - } else { - let height: CGFloat - - switch feed.kind { - - case .Text: - height = FeedBasicCell.heightOfFeed(feed) - - case .Image: - if feed.imageAttachmentsCount == 1 { - height = FeedBiggerImageCell.heightOfFeed(feed) - - } else if feed.imageAttachmentsCount <= 3 { - height = FeedNormalImagesCell.heightOfFeed(feed) - - } else { - height = FeedAnyImagesCell.heightOfFeed(feed) - } - - case .GithubRepo: - height = FeedGithubRepoCell.heightOfFeed(feed) - - case .DribbbleShot: - height = FeedDribbbleShotCell.heightOfFeed(feed) - - case .Audio: - height = FeedVoiceCell.heightOfFeed(feed) - - case .Location: - height = FeedLocationCell.heightOfFeed(feed) - - default: - height = FeedBasicCell.heightOfFeed(feed) - } - - if !key.isEmpty { - feedHeightHash[key] = height - } - - return height - } - } - private var feedCellLayoutHash = [String: FeedCellLayout]() private func feedCellLayoutOfFeed(feed: DiscoveredFeed) -> FeedCellLayout? { @@ -253,6 +201,18 @@ class FeedsViewController: BaseViewController { println("feedCellLayoutHash.count: \(feedCellLayoutHash.count)") } + private func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + if let layout = feedCellLayoutOfFeed(feed) { + return layout.height + + } else { + let layout = FeedCellLayout(feed: feed, needShowSkill: true) + updateFeedCellLayout(layout, forFeed: feed) + return layout.height + } + } + private var feedSortStyle: FeedSortStyle = .Match { didSet { feeds = [] From 7ab5d40f3d18b80a13d6dfbdf3775a819e812f5d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 09:19:16 +0800 Subject: [PATCH 35/45] refactor needShowSkill --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 1f5e1058..b514557f 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -14,6 +14,9 @@ import MapKit class FeedsViewController: BaseViewController { var skill: Skill? + var needShowSkill: Bool { + return (skill == nil) ? true : false + } var profileUser: ProfileUser? var preparedFeedsCount = 0 @@ -207,7 +210,7 @@ class FeedsViewController: BaseViewController { return layout.height } else { - let layout = FeedCellLayout(feed: feed, needShowSkill: true) + let layout = FeedCellLayout(feed: feed, needShowSkill: needShowSkill) updateFeedCellLayout(layout, forFeed: feed) return layout.height } @@ -460,7 +463,7 @@ class FeedsViewController: BaseViewController { let completion: [DiscoveredFeed] -> Void = { [weak self] feeds in - let needShowSkill: Bool = (self?.skill == nil) ? true : false + let needShowSkill: Bool = self?.needShowSkill ?? true feeds.forEach({ feed in let newLayout = FeedCellLayout(feed: feed, needShowSkill: needShowSkill) self?.updateFeedCellLayout(newLayout, forFeed: feed) @@ -921,8 +924,6 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { tableView.deselectRowAtIndexPath(indexPath, animated: true) } - let needShowSkill: Bool = (skill == nil) ? true : false - let layout = feedCellLayoutOfFeed(feed) let update: FeedCellLayout.Update = { [weak self] newLayout in self?.updateFeedCellLayout(newLayout, forFeed: feed) From 36dffd8da03f4f2a956c6fd2d1b91817c0b99240 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 09:46:58 +0800 Subject: [PATCH 36/45] FeedCellLayout do not consider needShowSkill --- .../Feeds/FeedsViewController.swift | 5 ++--- Yep/Views/Cells/Feed/FeedBasicCell.swift | 11 +++++++---- Yep/Views/Cells/Feed/FeedCellLayout.swift | 17 +++++++++++++---- Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift | 1 + Yep/Views/Cells/Feed/FeedGithubRepoCell.swift | 1 + 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index b514557f..bd6f55a1 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -210,7 +210,7 @@ class FeedsViewController: BaseViewController { return layout.height } else { - let layout = FeedCellLayout(feed: feed, needShowSkill: needShowSkill) + let layout = FeedCellLayout(feed: feed) updateFeedCellLayout(layout, forFeed: feed) return layout.height } @@ -463,9 +463,8 @@ class FeedsViewController: BaseViewController { let completion: [DiscoveredFeed] -> Void = { [weak self] feeds in - let needShowSkill: Bool = self?.needShowSkill ?? true feeds.forEach({ feed in - let newLayout = FeedCellLayout(feed: feed, needShowSkill: needShowSkill) + let newLayout = FeedCellLayout(feed: feed) self?.updateFeedCellLayout(newLayout, forFeed: feed) }) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 273e68cb..2877cf78 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -196,7 +196,7 @@ class FeedBasicCell: UITableViewCell { if let basicLayout = layout?.basicLayout { skillButton.frame = basicLayout.skillButtonFrame - nicknameLabel.frame = basicLayout.nicknameLabelFrame + nicknameLabel.frame = basicLayout.nicknameLabelFrameWhen(hasLogo: false, hasSkill: true) } else { let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) @@ -205,14 +205,14 @@ class FeedBasicCell: UITableViewCell { skillButton.frame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) - nicknameLabel.frame.size.width = screenWidth - 65 - skillButtonWidth - 15 - 16 - 18 + nicknameLabel.frame.size.width = screenWidth - 65 - skillButtonWidth - 20 - 10 - 15 } } else { skillButton.hidden = true if let basicLayout = layout?.basicLayout { - nicknameLabel.frame = basicLayout.nicknameLabelFrame + nicknameLabel.frame = basicLayout.nicknameLabelFrameWhen(hasLogo: false, hasSkill: false) } else { nicknameLabel.frame.size.width = screenWidth - 65 - 15 } @@ -246,7 +246,10 @@ class FeedBasicCell: UITableViewCell { if layoutCache.layout == nil { - let basicLayout = FeedCellLayout.BasicLayout(avatarImageViewFrame: avatarImageView.frame, nicknameLabelFrame: nicknameLabel.frame, skillButtonFrame: skillButton.frame, messageTextViewFrame: messageTextView.frame, leftBottomLabelFrame: leftBottomLabel.frame, messageCountLabelFrame: messageCountLabel.frame, discussionImageViewFrame: discussionImageView.frame) + var nicknameLabelFrame = nicknameLabel.frame + nicknameLabelFrame.size.width = screenWidth - 65 - 15 + + let basicLayout = FeedCellLayout.BasicLayout(avatarImageViewFrame: avatarImageView.frame, nicknameLabelFrame: nicknameLabelFrame, skillButtonFrame: skillButton.frame, messageTextViewFrame: messageTextView.frame, leftBottomLabelFrame: leftBottomLabel.frame, messageCountLabelFrame: messageCountLabel.frame, discussionImageViewFrame: discussionImageView.frame) let newLayout = FeedCellLayout(height: contentView.bounds.height, basicLayout: basicLayout) diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index 330829f5..e148acef 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -19,8 +19,17 @@ struct FeedCellLayout { struct BasicLayout { + func nicknameLabelFrameWhen(hasLogo hasLogo: Bool, hasSkill: Bool) -> CGRect { + + var frame = nicknameLabelFrame + frame.size.width -= hasLogo ? (18 + 10) : 0 + frame.size.width -= hasSkill ? (skillButtonFrame.width + 10) : 0 + + return frame + } + let avatarImageViewFrame: CGRect - let nicknameLabelFrame: CGRect + private let nicknameLabelFrame: CGRect let skillButtonFrame: CGRect let messageTextViewFrame: CGRect @@ -109,7 +118,7 @@ struct FeedCellLayout { self.basicLayout = basicLayout } - init(feed: DiscoveredFeed, needShowSkill: Bool) { + init(feed: DiscoveredFeed) { let height: CGFloat @@ -152,7 +161,7 @@ struct FeedCellLayout { let nicknameLabelFrame: CGRect let skillButtonFrame: CGRect - if needShowSkill, let skill = feed.skill { + if let skill = feed.skill { let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) @@ -160,7 +169,7 @@ struct FeedCellLayout { skillButtonFrame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) - let nicknameLabelWidth = screenWidth - 65 - skillButtonWidth - 15 - 16 - 18 + let nicknameLabelWidth = screenWidth - 65 - 15 nicknameLabelFrame = CGRect(x: 65, y: 21, width: nicknameLabelWidth, height: 18) } else { diff --git a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift index a859ce58..4b3bc367 100644 --- a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift +++ b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift @@ -88,6 +88,7 @@ class FeedDribbbleShotCell: FeedBasicCell { logoImageView.frame.origin.x = screenWidth - 18 - 15 logoImageView.frame.origin.y = nicknameLabel.frame.origin.y } + nicknameLabel.frame.size.width -= logoImageView.bounds.width + 10 if let attachment = feed.attachment { if case let .Dribbble(dribbbleShot) = attachment { diff --git a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift index 6171b54d..a7913234 100644 --- a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift +++ b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift @@ -74,6 +74,7 @@ class FeedGithubRepoCell: FeedBasicCell { logoImageView.frame.origin.x = screenWidth - 18 - 15 logoImageView.frame.origin.y = nicknameLabel.frame.origin.y } + nicknameLabel.frame.size.width -= logoImageView.bounds.width + 10 if let attachment = feed.attachment { if case let .Github(githubRepo) = attachment { From eabaf4cf7d50eb571528c9a3b0571ae547674f9a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 09:58:17 +0800 Subject: [PATCH 37/45] static FeedsViewController.layoutPool for reuse --- .../Feeds/FeedsViewController.swift | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index bd6f55a1..c92eebe5 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -185,36 +185,40 @@ class FeedsViewController: BaseViewController { feedsTableView.tableFooterView = feeds.isEmpty ? noFeedsFooterView : UIView() } - private var feedCellLayoutHash = [String: FeedCellLayout]() + struct LayoutPool { - private func feedCellLayoutOfFeed(feed: DiscoveredFeed) -> FeedCellLayout? { - let key = feed.id + private var feedCellLayoutHash = [String: FeedCellLayout]() - return feedCellLayoutHash[key] - } + private func feedCellLayoutOfFeed(feed: DiscoveredFeed) -> FeedCellLayout? { + let key = feed.id - private func updateFeedCellLayout(layout: FeedCellLayout, forFeed feed: DiscoveredFeed) { - - let key = feed.id - - if !key.isEmpty { - feedCellLayoutHash[key] = layout + return feedCellLayoutHash[key] } - println("feedCellLayoutHash.count: \(feedCellLayoutHash.count)") - } + private mutating func updateFeedCellLayout(layout: FeedCellLayout, forFeed feed: DiscoveredFeed) { - private func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + let key = feed.id - if let layout = feedCellLayoutOfFeed(feed) { - return layout.height + if !key.isEmpty { + feedCellLayoutHash[key] = layout + } - } else { - let layout = FeedCellLayout(feed: feed) - updateFeedCellLayout(layout, forFeed: feed) - return layout.height + println("feedCellLayoutHash.count: \(feedCellLayoutHash.count)") + } + + private mutating func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + if let layout = feedCellLayoutOfFeed(feed) { + return layout.height + + } else { + let layout = FeedCellLayout(feed: feed) + updateFeedCellLayout(layout, forFeed: feed) + return layout.height + } } } + static var layoutPool = LayoutPool() private var feedSortStyle: FeedSortStyle = .Match { didSet { @@ -461,11 +465,11 @@ class FeedsViewController: BaseViewController { defaultFailureHandler(reason, errorMessage: errorMessage) } - let completion: [DiscoveredFeed] -> Void = { [weak self] feeds in + let completion: [DiscoveredFeed] -> Void = { feeds in feeds.forEach({ feed in let newLayout = FeedCellLayout(feed: feed) - self?.updateFeedCellLayout(newLayout, forFeed: feed) + FeedsViewController.layoutPool.updateFeedCellLayout(newLayout, forFeed: feed) }) dispatch_async(dispatch_get_main_queue()) { [weak self] in @@ -923,9 +927,9 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { tableView.deselectRowAtIndexPath(indexPath, animated: true) } - let layout = feedCellLayoutOfFeed(feed) - let update: FeedCellLayout.Update = { [weak self] newLayout in - self?.updateFeedCellLayout(newLayout, forFeed: feed) + let layout = FeedsViewController.layoutPool.feedCellLayoutOfFeed(feed) + let update: FeedCellLayout.Update = { newLayout in + FeedsViewController.layoutPool.updateFeedCellLayout(newLayout, forFeed: feed) } let layoutCache = (layout: layout, update: update) @@ -1169,7 +1173,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { case Section.Feed.rawValue: let feed = feeds[indexPath.row] - return heightOfFeed(feed) + return FeedsViewController.layoutPool.heightOfFeed(feed) case Section.LoadMore.rawValue: return 60 From acfa27fa983c2440835bb80c52e611bc4956e1f6 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 10:08:03 +0800 Subject: [PATCH 38/45] private; do not updateFeedCellLayout when updateFeeds completion (call heighOfFeeds will do it) --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index c92eebe5..f1a765b1 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -185,7 +185,7 @@ class FeedsViewController: BaseViewController { feedsTableView.tableFooterView = feeds.isEmpty ? noFeedsFooterView : UIView() } - struct LayoutPool { + private struct LayoutPool { private var feedCellLayoutHash = [String: FeedCellLayout]() @@ -203,7 +203,7 @@ class FeedsViewController: BaseViewController { feedCellLayoutHash[key] = layout } - println("feedCellLayoutHash.count: \(feedCellLayoutHash.count)") + //println("feedCellLayoutHash.count: \(feedCellLayoutHash.count)") } private mutating func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { @@ -218,7 +218,7 @@ class FeedsViewController: BaseViewController { } } } - static var layoutPool = LayoutPool() + private static var layoutPool = LayoutPool() private var feedSortStyle: FeedSortStyle = .Match { didSet { @@ -467,11 +467,6 @@ class FeedsViewController: BaseViewController { let completion: [DiscoveredFeed] -> Void = { feeds in - feeds.forEach({ feed in - let newLayout = FeedCellLayout(feed: feed) - FeedsViewController.layoutPool.updateFeedCellLayout(newLayout, forFeed: feed) - }) - dispatch_async(dispatch_get_main_queue()) { [weak self] in self?.isFetchingFeeds = false From f8a8c18cba9e32d014dddcf69fc3bbe8af6591e7 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 10:33:45 +0800 Subject: [PATCH 39/45] opaque in FeedBasicCell --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 2877cf78..bcfa2b50 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -32,6 +32,9 @@ class FeedBasicCell: UITableViewCell { label.font = UIFont.systemFontOfSize(15) label.frame = CGRect(x: 65, y: 21, width: 100, height: 18) + label.opaque = true + label.backgroundColor = UIColor.whiteColor() + label.clipsToBounds = true return label }() @@ -62,6 +65,8 @@ class FeedBasicCell: UITableViewCell { textView.dataDetectorTypes = .Link textView.frame = CGRect(x: 65, y: 54, width: screenWidth - 65 - 15, height: 26) + textView.opaque = true + textView.backgroundColor = UIColor.whiteColor() textView.touchesBeganAction = { [weak self] in if let strongSelf = self { @@ -91,6 +96,9 @@ class FeedBasicCell: UITableViewCell { label.font = UIFont.feedBottomLabelsFont() label.frame = CGRect(x: 65, y: 0, width: 200, height: 17) + label.opaque = true + label.backgroundColor = UIColor.whiteColor() + label.clipsToBounds = true return label }() @@ -101,6 +109,9 @@ class FeedBasicCell: UITableViewCell { label.font = UIFont.feedBottomLabelsFont() label.frame = CGRect(x: 65, y: 0, width: 200, height: 17) + label.opaque = true + label.backgroundColor = UIColor.whiteColor() + label.clipsToBounds = true return label }() From 746f74c215e9acce305b3bb91689b08cd31cd837 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 10:43:33 +0800 Subject: [PATCH 40/45] adjust logoImageView.frame --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 2 ++ Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift | 2 +- Yep/Views/Cells/Feed/FeedGithubRepoCell.swift | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index bcfa2b50..e7e01425 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -32,9 +32,11 @@ class FeedBasicCell: UITableViewCell { label.font = UIFont.systemFontOfSize(15) label.frame = CGRect(x: 65, y: 21, width: 100, height: 18) + /* label.opaque = true label.backgroundColor = UIColor.whiteColor() label.clipsToBounds = true + */ return label }() diff --git a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift index 4b3bc367..217ef1a6 100644 --- a/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift +++ b/Yep/Views/Cells/Feed/FeedDribbbleShotCell.swift @@ -81,7 +81,7 @@ class FeedDribbbleShotCell: FeedBasicCell { }), needShowSkill: needShowSkill) if needShowSkill, let _ = feed.skill { - logoImageView.frame.origin.x = skillButton.frame.origin.x - 8 - 18 + logoImageView.frame.origin.x = skillButton.frame.origin.x - 10 - 18 logoImageView.frame.origin.y = nicknameLabel.frame.origin.y } else { diff --git a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift index a7913234..f9a477ba 100644 --- a/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift +++ b/Yep/Views/Cells/Feed/FeedGithubRepoCell.swift @@ -67,7 +67,7 @@ class FeedGithubRepoCell: FeedBasicCell { }), needShowSkill: needShowSkill) if needShowSkill, let _ = feed.skill { - logoImageView.frame.origin.x = skillButton.frame.origin.x - 8 - 18 + logoImageView.frame.origin.x = skillButton.frame.origin.x - 10 - 18 logoImageView.frame.origin.y = nicknameLabel.frame.origin.y } else { From c13e03930c09747728562aaa29c80aac6016be9b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 10:54:24 +0800 Subject: [PATCH 41/45] ceil rect.width --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 7 +++---- Yep/Views/Cells/Feed/FeedCellLayout.swift | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index e7e01425..8759b3ab 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -32,11 +32,9 @@ class FeedBasicCell: UITableViewCell { label.font = UIFont.systemFontOfSize(15) label.frame = CGRect(x: 65, y: 21, width: 100, height: 18) - /* label.opaque = true label.backgroundColor = UIColor.whiteColor() label.clipsToBounds = true - */ return label }() @@ -214,7 +212,7 @@ class FeedBasicCell: UITableViewCell { } else { let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) - let skillButtonWidth = rect.width + 20 + let skillButtonWidth = ceil(rect.width) + 20 skillButton.frame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) @@ -252,7 +250,8 @@ class FeedBasicCell: UITableViewCell { let rect = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) - messageCountLabel.frame = CGRect(x: screenWidth - rect.width - 45 - 8, y: leftBottomLabel.frame.origin.y, width: rect.width, height: 19) + let width = ceil(rect.width) + messageCountLabel.frame = CGRect(x: screenWidth - width - 45 - 8, y: leftBottomLabel.frame.origin.y, width: width, height: 19) discussionImageView.frame = CGRect(x: screenWidth - 30 - 15, y: leftBottomLabel.frame.origin.y - 1, width: 30, height: 19) } diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index e148acef..4adce52a 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -165,7 +165,7 @@ struct FeedCellLayout { let rect = skill.localName.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.skillTextAttributes, context: nil) - let skillButtonWidth = rect.width + 20 + let skillButtonWidth = ceil(rect.width) + 20 skillButtonFrame = CGRect(x: screenWidth - skillButtonWidth - 15, y: 19, width: skillButtonWidth, height: 22) @@ -190,7 +190,8 @@ struct FeedCellLayout { let _rect2 = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) - let messageCountLabelFrame = CGRect(x: screenWidth - _rect2.width - 45 - 8, y: leftBottomLabelOriginY, width: _rect2.width, height: 19) + let _width = ceil(_rect2.width) + let messageCountLabelFrame = CGRect(x: screenWidth - _width - 45 - 8, y: leftBottomLabelOriginY, width: _width, height: 19) let discussionImageViewFrame = CGRect(x: screenWidth - 30 - 15, y: leftBottomLabelOriginY - 1, width: 30, height: 19) @@ -215,7 +216,6 @@ struct FeedCellLayout { case .Image: - if feed.imageAttachmentsCount == 1 { let biggerImageViewFrame = CGRect(origin: CGPoint(x: 65, y: beginY), size: YepConfig.FeedBiggerImageCell.imageSize) From 24def648ff90d2344382699b4f240e11706d93a7 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 11:02:39 +0800 Subject: [PATCH 42/45] adjust messageTextView --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 8759b3ab..54e82924 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -62,7 +62,9 @@ class FeedBasicCell: UITableViewCell { textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) textView.editable = false textView.scrollEnabled = false - textView.dataDetectorTypes = .Link + textView.showsHorizontalScrollIndicator = false + textView.showsVerticalScrollIndicator = false + textView.dataDetectorTypes = [.Link, .CalendarEvent] textView.frame = CGRect(x: 65, y: 54, width: screenWidth - 65 - 15, height: 26) textView.opaque = true From 8c8194ac3b046f03beed5e698bdfc22d49d3ed6f Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 11:13:13 +0800 Subject: [PATCH 43/45] trimming(.WhitespaceAndNewline) for NewFeed message --- Yep/ViewControllers/NewFeed/NewFeedViewController.swift | 2 +- Yep/Views/Cells/Feed/FeedBasicCell.swift | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 8d7cdb3f..3f276d5d 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -558,7 +558,7 @@ class NewFeedViewController: UIViewController { uploadState = .Uploading - let message = messageTextView.text + let message = messageTextView.text.trimming(.WhitespaceAndNewline) let coordinate = YepLocationService.sharedManager.currentLocation?.coordinate var kind: FeedKind = .Text var mediaInfo: JSONDictionary? diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 54e82924..bba2c55b 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -197,6 +197,8 @@ class FeedBasicCell: UITableViewCell { messageTextView.text = "\u{200B}\(feed.body)" // ref http://stackoverflow.com/a/25994821 + //println("messageTextView.text: >>>\(messageTextView.text)<<<") + if let basicLayout = layout?.basicLayout { messageTextView.frame = basicLayout.messageTextViewFrame } else { From c73b417ae794e24c579523c0cde2ab6c97206369 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 13:34:09 +0800 Subject: [PATCH 44/45] update Pods (Realm 0.97) --- Podfile.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 368a0e8b..7ad2dda2 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,6 @@ PODS: - 1PasswordExtension (1.7) - - Alamofire (3.1.3) + - Alamofire (3.1.4) - APAddressBook/Core (0.2.1) - APAddressBook/Swift (0.2.1): - APAddressBook/Core @@ -8,7 +8,7 @@ PODS: - Base64 (1.0.1) - Crashlytics (3.4.1): - Fabric (~> 1.6.0) - - DeviceGuru (1.3.2) + - DeviceGuru (1.3.3) - Fabric (1.6.1) - FXBlurView (1.6.4) - JPush-iOS-SDK (1.8.8) @@ -21,11 +21,11 @@ PODS: - Navi (0.3.9) - pop (1.0.8) - Proposer (0.7.1) - - Realm (0.96.3): - - Realm/Headers (= 0.96.3) - - Realm/Headers (0.96.3) - - RealmSwift (0.96.3): - - Realm (= 0.96.3) + - Realm (0.97.0): + - Realm/Headers (= 0.97.0) + - Realm/Headers (0.97.0) + - RealmSwift (0.97.0): + - Realm (= 0.97.0) - Ruler (0.6) - SocketRocket (0.4.2) - TPKeyboardAvoiding (1.2.11) @@ -57,12 +57,12 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: 1PasswordExtension: a22573ad528dd63bd79c1f3b3813b17c2f86b91b - Alamofire: 9f93b56389e48def9220dd57d1f44b1927229a5a + Alamofire: fbc829692f351fa1d8a31dd75fd7f7f56fea31fb APAddressBook: 90c0fb07579a47e10ef1a2344e23cfd35f388bec Appsee: 77f144701aa1a53d854d319a46667561849e8cf5 Base64: 4924bf3ca6fa559a5161ef717291bd450eb7bd1a Crashlytics: 41574a245bc6ae10c55d57f385ebd2004e5bee05 - DeviceGuru: bbc2660d73211dd5d868bc85a1c2ca9607d01153 + DeviceGuru: 49c6178d77693f8459ace21cecaf4d1d26297d08 Fabric: bf0ceb04e7c924090efc5f8c55e4fbcca189e0a0 FXBlurView: db786c2561cb49a09ae98407f52460096ab8a44f JPush-iOS-SDK: d4c097d8abbdd0837e24d44b41aacf64a6feddfd @@ -73,8 +73,8 @@ SPEC CHECKSUMS: Navi: 24f5c81aeb46b89d27168ec1d459581230ae2675 pop: bb773ae2c791ca2629de13b347e7a8b450fa6a57 Proposer: e9759ad71a6702fd94315a0bff1f8c116edf6f07 - Realm: 145d3cdf78a03aee71bde5381ad7e542bd541720 - RealmSwift: aab84968aad662f61f36473d1aea019f63481505 + Realm: b498a6fb9d288b171ff98d0e2d4384c295be8990 + RealmSwift: d014810dec75c9a3f1a33926d2dabfed855c582c Ruler: b36ec3bbc5fc6c3b7f629a6052cc1c17ada4b280 SocketRocket: ffe08119b00ef982f6c37052a4705a057c8494ad TPKeyboardAvoiding: e5ce146b313de063957bfa75a13f1e9b0ff18ab7 From bc448d53a832cc928408811dff01ae9d2e6471e2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 18 Dec 2015 13:37:35 +0800 Subject: [PATCH 45/45] update shellScript for ${PODS_ROOT}/Fabric/run --- Yep.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 40c48c75..2c97b9aa 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -2541,7 +2541,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Fabric/Fabric.framework/run\" 3030ba006e21bcf8eb4a2127b6a7931ea6667486 1b6549ac285402b232e4718eda293559d8ed8df039017af3fa9593518395eef0"; + shellScript = "\"${PODS_ROOT}/Fabric/run\" 3030ba006e21bcf8eb4a2127b6a7931ea6667486 1b6549ac285402b232e4718eda293559d8ed8df039017af3fa9593518395eef0"; }; 39615BAC5D2C17889BD12838 /* Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase;