From 0362e4e29daeceaeeeb3476a85903d36bb43be95 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 7 Feb 2022 13:35:21 -0800 Subject: [PATCH] Hide the bottom separator on the Timeline for the last cell --- iOS/MasterTimeline/Cell/MasterTimelineCellData.swift | 7 +++++-- .../Cell/MasterTimelineTableViewCell.swift | 12 +++++++++--- .../MasterTimelineViewController.swift | 11 ++++++----- .../TimelinePreviewTableViewController.swift | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/iOS/MasterTimeline/Cell/MasterTimelineCellData.swift b/iOS/MasterTimeline/Cell/MasterTimelineCellData.swift index 2c3c8b822..fa06cdadc 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineCellData.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineCellData.swift @@ -27,8 +27,9 @@ struct MasterTimelineCellData { let starred: Bool let numberOfLines: Int let iconSize: IconSize - - init(article: Article, showFeedName: ShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: UIImage?, numberOfLines: Int, iconSize: IconSize) { + let hideSeparator: Bool + + init(article: Article, showFeedName: ShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: UIImage?, numberOfLines: Int, iconSize: IconSize, hideSeparator: Bool) { self.title = ArticleStringFormatter.truncatedTitle(article) self.attributedTitle = ArticleStringFormatter.attributedTruncatedTitle(article) @@ -65,6 +66,7 @@ struct MasterTimelineCellData { self.starred = article.status.starred self.numberOfLines = numberOfLines self.iconSize = iconSize + self.hideSeparator = hideSeparator } @@ -83,6 +85,7 @@ struct MasterTimelineCellData { self.starred = false self.numberOfLines = 0 self.iconSize = .medium + self.hideSeparator = false } } diff --git a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift index 2ec879473..88c9fd782 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift @@ -82,7 +82,6 @@ class MasterTimelineTableViewCell: VibrantTableViewCell { } override func layoutSubviews() { - super.layoutSubviews() let layout = updatedLayout(width: bounds.width) @@ -94,8 +93,6 @@ class MasterTimelineTableViewCell: VibrantTableViewCell { setFrame(for: summaryView, rect: layout.summaryRect) feedNameView.setFrameIfNotEqual(layout.feedNameRect) dateView.setFrameIfNotEqual(layout.dateRect) - - separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) } func setIconImage(_ image: IconImage) { @@ -272,6 +269,14 @@ private extension MasterTimelineTableViewCell { accessibilityLabel = label } + func updateSeparator() { + if cellData?.hideSeparator ?? false { + separatorInset = UIEdgeInsets(top: 0, left: bounds.width + 1, bottom: 0, right: 0) + } else { + separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + } + } + func makeIconEmpty() { if iconView.iconImage != nil { iconView.iconImage = nil @@ -305,6 +310,7 @@ private extension MasterTimelineTableViewCell { updateStarView() updateIconImage() updateAccessiblityLabel() + updateSeparator() } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 3ad943c83..ba4cbb2be 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -447,7 +447,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner for article in visibleUpdatedArticles { if let indexPath = dataSource.indexPath(for: article) { if let cell = tableView.cellForRow(at: indexPath) as? MasterTimelineTableViewCell { - configure(cell, article: article) + configure(cell, article: article, indexPath: indexPath) } } } @@ -564,7 +564,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, webFeedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) - let prototypeCellData = MasterTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Prototype Feed Name", byline: nil, iconImage: nil, showIcon: false, featuredImage: nil, numberOfLines: numberOfTextLines, iconSize: iconSize) + let prototypeCellData = MasterTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Prototype Feed Name", byline: nil, iconImage: nil, showIcon: false, featuredImage: nil, numberOfLines: numberOfTextLines, iconSize: iconSize, hideSeparator: false) if UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory { let layout = MasterTimelineAccessibilityCellLayout(width: tableView.bounds.width, insets: tableView.safeAreaInsets, cellData: prototypeCellData) @@ -722,22 +722,23 @@ private extension MasterTimelineViewController { let dataSource: UITableViewDiffableDataSource = MasterTimelineDataSource(tableView: tableView, cellProvider: { [weak self] tableView, indexPath, article in let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MasterTimelineTableViewCell - self?.configure(cell, article: article) + self?.configure(cell, article: article, indexPath: indexPath) return cell }) dataSource.defaultRowAnimation = .middle return dataSource } - func configure(_ cell: MasterTimelineTableViewCell, article: Article) { + func configure(_ cell: MasterTimelineTableViewCell, article: Article, indexPath: IndexPath) { let iconImage = iconImageFor(article) let featuredImage = featuredImageFor(article) let showFeedNames = coordinator.showFeedNames let showIcon = coordinator.showIcons && iconImage != nil - cell.cellData = MasterTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.webFeed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcon, featuredImage: featuredImage, numberOfLines: numberOfTextLines, iconSize: iconSize) + let hideSeparater = indexPath.row == coordinator.articles.count - 1 + cell.cellData = MasterTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.webFeed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcon, featuredImage: featuredImage, numberOfLines: numberOfTextLines, iconSize: iconSize, hideSeparator: hideSeparater) } func iconImageFor(_ article: Article) -> IconImage? { diff --git a/iOS/Settings/TimelinePreviewTableViewController.swift b/iOS/Settings/TimelinePreviewTableViewController.swift index 5d6da3f0b..ad65dd052 100644 --- a/iOS/Settings/TimelinePreviewTableViewController.swift +++ b/iOS/Settings/TimelinePreviewTableViewController.swift @@ -71,7 +71,7 @@ private extension TimelinePreviewTableViewController { let iconImage = IconImage(AppAssets.faviconTemplateImage.withTintColor(AppAssets.secondaryAccentColor)) - return MasterTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Feed Name", byline: nil, iconImage: iconImage, showIcon: true, featuredImage: nil, numberOfLines: AppDefaults.shared.timelineNumberOfLines, iconSize: AppDefaults.shared.timelineIconSize) + return MasterTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Feed Name", byline: nil, iconImage: iconImage, showIcon: true, featuredImage: nil, numberOfLines: AppDefaults.shared.timelineNumberOfLines, iconSize: AppDefaults.shared.timelineIconSize, hideSeparator: false) } }