Add IconImage to encapsulate our icon processing logic

This commit is contained in:
Maurice Parker
2019-11-05 18:05:57 -06:00
parent 05e0e34f6b
commit 560f36621f
46 changed files with 336 additions and 323 deletions

View File

@@ -14,7 +14,7 @@ struct MasterTimelineAccessibilityCellLayout: MasterTimelineCellLayout {
let height: CGFloat
let unreadIndicatorRect: CGRect
let starRect: CGRect
let avatarImageRect: CGRect
let iconImageRect: CGRect
let titleRect: CGRect
let summaryRect: CGRect
let feedNameRect: CGRect
@@ -37,12 +37,12 @@ struct MasterTimelineAccessibilityCellLayout: MasterTimelineCellLayout {
// Separator Insets
self.separatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
// Avatar
if cellData.showAvatar {
self.avatarImageRect = MasterTimelineAccessibilityCellLayout.rectForAvatar(currentPoint)
currentPoint.y = self.avatarImageRect.maxY
// Icon Image
if cellData.showIcon {
self.iconImageRect = MasterTimelineAccessibilityCellLayout.rectForIconView(currentPoint)
currentPoint.y = self.iconImageRect.maxY
} else {
self.avatarImageRect = CGRect.zero
self.iconImageRect = CGRect.zero
}
let textAreaWidth = width - (currentPoint.x + MasterTimelineDefaultCellLayout.cellPadding.right + insets.right)

View File

@@ -16,14 +16,14 @@ struct MasterTimelineCellData {
let dateString: String
let feedName: String
let showFeedName: Bool
let avatar: UIImage? // feed icon, user avatar, or favicon
let showAvatar: Bool // Make space even when avatar is nil
let iconImage: IconImage? // feed icon, user avatar, or favicon
let showIcon: Bool // Make space even when icon is nil
let featuredImage: UIImage? // image from within the article
let read: Bool
let starred: Bool
let numberOfLines: Int
init(article: Article, showFeedName: Bool, feedName: String?, avatar: UIImage?, showAvatar: Bool, featuredImage: UIImage?, numberOfLines: Int) {
init(article: Article, showFeedName: Bool, feedName: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: UIImage?, numberOfLines: Int) {
self.title = ArticleStringFormatter.truncatedTitle(article)
self.summary = ArticleStringFormatter.truncatedSummary(article)
@@ -39,8 +39,8 @@ struct MasterTimelineCellData {
self.showFeedName = showFeedName
self.showAvatar = showAvatar
self.avatar = avatar
self.showIcon = showIcon
self.iconImage = iconImage
self.featuredImage = featuredImage
self.read = article.status.read
@@ -55,8 +55,8 @@ struct MasterTimelineCellData {
self.dateString = ""
self.feedName = ""
self.showFeedName = false
self.showAvatar = false
self.avatar = nil
self.showIcon = false
self.iconImage = nil
self.featuredImage = nil
self.read = true
self.starred = false

View File

@@ -13,7 +13,7 @@ protocol MasterTimelineCellLayout {
var height: CGFloat {get}
var unreadIndicatorRect: CGRect {get}
var starRect: CGRect {get}
var avatarImageRect: CGRect {get}
var iconImageRect: CGRect {get}
var titleRect: CGRect {get}
var summaryRect: CGRect {get}
var feedNameRect: CGRect {get}
@@ -42,9 +42,9 @@ extension MasterTimelineCellLayout {
return r
}
static func rectForAvatar(_ point: CGPoint) -> CGRect {
static func rectForIconView(_ point: CGPoint) -> CGRect {
var r = CGRect.zero
r.size = MasterTimelineDefaultCellLayout.avatarSize
r.size = MasterTimelineDefaultCellLayout.iconImageSize
r.origin.x = point.x
r.origin.y = point.y + 4
return r

View File

@@ -21,9 +21,9 @@ struct MasterTimelineDefaultCellLayout: MasterTimelineCellLayout {
static let starDimension = CGFloat(integerLiteral: 16)
static let starSize = CGSize(width: MasterTimelineDefaultCellLayout.starDimension, height: MasterTimelineDefaultCellLayout.starDimension)
static let avatarSize = CGSize(width: 32.0, height: 32.0)
static let avatarMarginRight = CGFloat(integerLiteral: 8)
static let avatarCornerRadius = CGFloat(integerLiteral: 4)
static let iconImageSize = CGSize(width: 32.0, height: 32.0)
static let iconMarginRight = CGFloat(integerLiteral: 8)
static let iconCornerRadius = CGFloat(integerLiteral: 4)
static var titleFont: UIFont {
return UIFont.preferredFont(forTextStyle: .headline)
@@ -47,7 +47,7 @@ struct MasterTimelineDefaultCellLayout: MasterTimelineCellLayout {
let height: CGFloat
let unreadIndicatorRect: CGRect
let starRect: CGRect
let avatarImageRect: CGRect
let iconImageRect: CGRect
let titleRect: CGRect
let summaryRect: CGRect
let feedNameRect: CGRect
@@ -70,12 +70,12 @@ struct MasterTimelineDefaultCellLayout: MasterTimelineCellLayout {
// Separator Insets
self.separatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
// Avatar
if cellData.showAvatar {
self.avatarImageRect = MasterTimelineDefaultCellLayout.rectForAvatar(currentPoint)
currentPoint.x = self.avatarImageRect.maxX + MasterTimelineDefaultCellLayout.avatarMarginRight
// Icon Image
if cellData.showIcon {
self.iconImageRect = MasterTimelineDefaultCellLayout.rectForIconView(currentPoint)
currentPoint.x = self.iconImageRect.maxX + MasterTimelineDefaultCellLayout.iconMarginRight
} else {
self.avatarImageRect = CGRect.zero
self.iconImageRect = CGRect.zero
}
let textAreaWidth = width - (currentPoint.x + MasterTimelineDefaultCellLayout.cellPadding.right + insets.right)
@@ -98,7 +98,7 @@ struct MasterTimelineDefaultCellLayout: MasterTimelineCellLayout {
let feedNameWidth = textAreaWidth - (MasterTimelineDefaultCellLayout.feedRightMargin + self.dateRect.size.width)
self.feedNameRect = MasterTimelineDefaultCellLayout.rectForFeedName(cellData, currentPoint, feedNameWidth)
self.height = [self.avatarImageRect, self.feedNameRect].maxY() + MasterTimelineDefaultCellLayout.cellPadding.bottom
self.height = [self.iconImageRect, self.feedNameRect].maxY() + MasterTimelineDefaultCellLayout.cellPadding.bottom
}

View File

@@ -17,7 +17,7 @@ class MasterTimelineTableViewCell: VibrantTableViewCell {
private let dateView = MasterTimelineTableViewCell.singleLineUILabel()
private let feedNameView = MasterTimelineTableViewCell.singleLineUILabel()
private lazy var avatarView = AvatarView()
private lazy var iconView = IconView()
private lazy var starView = {
return NonIntrinsicImageView(image: AppAssets.timelineStarImage)
@@ -68,7 +68,7 @@ class MasterTimelineTableViewCell: VibrantTableViewCell {
unreadIndicatorView.setFrameIfNotEqual(layout.unreadIndicatorRect)
starView.setFrameIfNotEqual(layout.starRect)
avatarView.setFrameIfNotEqual(layout.avatarImageRect)
iconView.setFrameIfNotEqual(layout.iconImageRect)
setFrame(for: titleView, rect: layout.titleRect)
setFrame(for: summaryView, rect: layout.summaryRect)
feedNameView.setFrameIfNotEqual(layout.feedNameRect)
@@ -77,8 +77,8 @@ class MasterTimelineTableViewCell: VibrantTableViewCell {
separatorInset = layout.separatorInsets
}
func setAvatarImage(_ image: UIImage) {
avatarView.image = image
func setIconImage(_ image: IconImage) {
iconView.iconImage = image
}
}
@@ -128,7 +128,7 @@ private extension MasterTimelineTableViewCell {
addSubviewAtInit(unreadIndicatorView, hidden: true)
addSubviewAtInit(dateView, hidden: false)
addSubviewAtInit(feedNameView, hidden: true)
addSubviewAtInit(avatarView, hidden: true)
addSubviewAtInit(iconView, hidden: true)
addSubviewAtInit(starView, hidden: true)
}
@@ -167,7 +167,6 @@ private extension MasterTimelineTableViewCell {
}
func updateFeedNameView() {
if cellData.showFeedName {
showView(feedNameView)
feedNameView.font = MasterTimelineDefaultCellLayout.feedNameFont
@@ -187,28 +186,26 @@ private extension MasterTimelineTableViewCell {
showOrHideView(starView, !cellData.starred)
}
func updateAvatar() {
guard let image = cellData.avatar, cellData.showAvatar else {
makeAvatarEmpty()
func updateIconImage() {
guard let image = cellData.iconImage, cellData.showIcon else {
makeIconEmpty()
return
}
showView(avatarView)
showView(iconView)
if avatarView.image !== cellData.avatar {
avatarView.image = image
if iconView.iconImage !== cellData.iconImage {
iconView.iconImage = image
setNeedsLayout()
}
}
func makeAvatarEmpty() {
if avatarView.image != nil {
avatarView.image = nil
func makeIconEmpty() {
if iconView.iconImage != nil {
iconView.iconImage = nil
setNeedsLayout()
}
hideView(avatarView)
hideView(iconView)
}
func hideView(_ view: UIView) {
@@ -234,7 +231,7 @@ private extension MasterTimelineTableViewCell {
updateFeedNameView()
updateUnreadIndicator()
updateStarView()
updateAvatar()
updateIconImage()
}
}