refactor heightOfFeed use FeedCellLayout

This commit is contained in:
nixzhu
2015-12-18 09:15:43 +08:00
parent 132f5e9e35
commit 5cc540e879
@@ -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 = []