From f66146e9bcdbe77ff8e8253bc8b579da774c7e7a Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 23 Jan 2022 21:01:55 +0800 Subject: [PATCH] Refreshes Feeds screen --- .../Cell/MasterFeedTableViewCell.swift | 19 +++++++++++++++--- .../Cell/MasterFeedTableViewCellLayout.swift | 20 ++++++++++++------- iOS/MasterFeed/MasterFeedViewController.swift | 12 ++++++++++- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index eff30162e..cfe2de5c3 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -45,6 +45,14 @@ class MasterFeedTableViewCell : VibrantTableViewCell { } } + var itemIsInFolder = false { + didSet { + if itemIsInFolder != oldValue { + setNeedsLayout() + } + } + } + var isSeparatorShown = true { didSet { if isSeparatorShown != oldValue { @@ -88,7 +96,7 @@ class MasterFeedTableViewCell : VibrantTableViewCell { label.allowsDefaultTighteningForTruncation = false label.adjustsFontForContentSizeCategory = true label.lineBreakMode = .byTruncatingTail - label.font = .preferredFont(forTextStyle: .body).bold() + label.font = .preferredFont(forTextStyle: .body) return label }() @@ -136,14 +144,19 @@ class MasterFeedTableViewCell : VibrantTableViewCell { } override func sizeThatFits(_ size: CGSize) -> CGSize { - let layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, label: titleView, unreadCountView: unreadCountView, showingEditingControl: isShowingEditControl, indent: indentationLevel == 1, shouldShowDisclosure: isDisclosureAvailable) + let layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, label: titleView, unreadCountView: unreadCountView, showingEditingControl: isShowingEditControl, indent: indentationLevel == 1, shouldShowDisclosure: isDisclosureAvailable, itemIsInFolder: itemIsInFolder) return CGSize(width: bounds.width, height: layout.height) } override func layoutSubviews() { super.layoutSubviews() - let layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, label: titleView, unreadCountView: unreadCountView, showingEditingControl: isShowingEditControl, indent: indentationLevel == 1, shouldShowDisclosure: isDisclosureAvailable) + let layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, label: titleView, unreadCountView: unreadCountView, showingEditingControl: isShowingEditControl, indent: indentationLevel == 1, shouldShowDisclosure: isDisclosureAvailable, itemIsInFolder: itemIsInFolder) layoutWith(layout) + if isDisclosureAvailable { + titleView.font = .preferredFont(forTextStyle: .body).bold() + } else { + titleView.font = .preferredFont(forTextStyle: .body) + } } @objc func buttonPressed(_ sender: UIButton) { diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift index 4ff894978..2c8b9d6a4 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift @@ -11,13 +11,13 @@ import RSCore struct MasterFeedTableViewCellLayout { - private static let indentWidth = CGFloat(integerLiteral: 42) + private static let indentWidth = CGFloat(integerLiteral: 15) private static let editingControlIndent = CGFloat(integerLiteral: 40) private static let imageSize = CGSize(width: 24, height: 24) private static let imageMarginRight = CGFloat(integerLiteral: 11) private static let labelMarginRight = CGFloat(integerLiteral: 8) private static let unreadCountMarginRight = CGFloat(integerLiteral: 16) - private static let disclosureButtonSize = CGSize(width: 44, height: 44) + private static let disclosureButtonSize = CGSize(width: 55, height: 44) private static let verticalPadding = CGFloat(integerLiteral: 11) private static let minRowHeight = CGFloat(integerLiteral: 44) @@ -32,7 +32,7 @@ struct MasterFeedTableViewCellLayout { let height: CGFloat - init(cellWidth: CGFloat, insets: UIEdgeInsets, label: UILabel, unreadCountView: MasterFeedUnreadCountView, showingEditingControl: Bool, indent: Bool, shouldShowDisclosure: Bool) { + init(cellWidth: CGFloat, insets: UIEdgeInsets, label: UILabel, unreadCountView: MasterFeedUnreadCountView, showingEditingControl: Bool, indent: Bool, shouldShowDisclosure: Bool, itemIsInFolder: Bool) { var initialIndent = insets.left if indent { @@ -54,7 +54,12 @@ struct MasterFeedTableViewCellLayout { let y = UIFontMetrics.default.scaledValue(for: MasterFeedTableViewCellLayout.verticalPadding) + label.font.lineHeight / 2.0 - MasterFeedTableViewCellLayout.imageSize.height / 2.0 - rFavicon = CGRect(x: x, y: y, width: MasterFeedTableViewCellLayout.imageSize.width, height: MasterFeedTableViewCellLayout.imageSize.height) + if itemIsInFolder { + rFavicon = CGRect(x: x + MasterFeedTableViewCellLayout.disclosureButtonSize.width - (MasterFeedTableViewCellLayout.imageSize.width / 2), y: y, width: MasterFeedTableViewCellLayout.imageSize.width, height: MasterFeedTableViewCellLayout.imageSize.height) + } else { + rFavicon = CGRect(x: x, y: y, width: MasterFeedTableViewCellLayout.imageSize.width, height: MasterFeedTableViewCellLayout.imageSize.height) + } + } // Unread Count @@ -68,9 +73,9 @@ struct MasterFeedTableViewCellLayout { } // Title - var rLabelx = insets.left + MasterFeedTableViewCellLayout.disclosureButtonSize.width - if !shouldShowDisclosure { - rLabelx = rLabelx + MasterFeedTableViewCellLayout.imageSize.width + MasterFeedTableViewCellLayout.imageMarginRight + var rLabelx = MasterFeedTableViewCellLayout.disclosureButtonSize.width + if itemIsInFolder { + rLabelx += MasterFeedTableViewCellLayout.disclosureButtonSize.width - (rFavicon.width / 2) } let rLabely = UIFontMetrics.default.scaledValue(for: MasterFeedTableViewCellLayout.verticalPadding) @@ -127,6 +132,7 @@ struct MasterFeedTableViewCellLayout { let separatorInset = MasterFeedTableViewCellLayout.disclosureButtonSize.width separatorRect = CGRect(x: separatorInset, y: cellHeight - 0.5, width: cellWidth - separatorInset, height: 0.5) + // Assign the properties self.height = cellHeight self.faviconRect = rFavicon diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index c61d6d329..1526b98ff 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -739,7 +739,7 @@ private extension MasterFeedViewController { let unreadCountView = MasterFeedUnreadCountView() unreadCountView.unreadCount = 10 - let layout = MasterFeedTableViewCellLayout(cellWidth: tableView.bounds.size.width, insets: tableView.safeAreaInsets, label: titleLabel, unreadCountView: unreadCountView, showingEditingControl: false, indent: false, shouldShowDisclosure: false) + let layout = MasterFeedTableViewCellLayout(cellWidth: tableView.bounds.size.width, insets: tableView.safeAreaInsets, label: titleLabel, unreadCountView: unreadCountView, showingEditingControl: false, indent: false, shouldShowDisclosure: false, itemIsInFolder: false) tableView.estimatedRowHeight = layout.height } @@ -763,6 +763,16 @@ private extension MasterFeedViewController { if let feed = node.representedObject as? Feed { cell.name = feed.nameForDisplay cell.unreadCount = feed.unreadCount + cell.itemIsInFolder = false + if let account = feed.account, let folders = account.folders { + for folder in folders { + if folder.objectIsChild(node.representedObject) { + cell.itemIsInFolder = true + break + } + } + } + } configureIcon(cell, indexPath)