mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 01:40:22 +00:00
Fix SwiftLint issues.
This commit is contained in:
1 parent
4a581e69df
commit
e80a44a080
5 files changed
+139
-166
No files matched your search
@@ -28,7 +28,7 @@ extension UICollectionView {
|
||||
scrollToItem(at: indexPath, at: .centeredVertically, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func middleVisibleRow() -> IndexPath? {
|
||||
if indexPathsForVisibleItems.count > 2 {
|
||||
return indexPathsForVisibleItems[indexPathsForVisibleItems.count / 2]
|
||||
|
||||
@@ -21,11 +21,11 @@ final class MainTimelineCell: UITableViewCell {
|
||||
configure(cellData)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isPreview: Bool = false
|
||||
|
||||
|
||||
private static let indicatorAnimationDuration = 0.25
|
||||
|
||||
|
||||
override func awakeFromNib() {
|
||||
MainActor.assumeIsolated {
|
||||
super.awakeFromNib()
|
||||
@@ -34,15 +34,11 @@ final class MainTimelineCell: UITableViewCell {
|
||||
configureStackView()
|
||||
}
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
}
|
||||
|
||||
|
||||
private func configure(_ cellData: MainTimelineCellData) {
|
||||
articleContent.numberOfLines = cellData.numberOfLines
|
||||
addArticleContent(configurationState)
|
||||
|
||||
|
||||
if cellData.showFeedName == .feed {
|
||||
articleByLine.text = cellData.feedName
|
||||
} else if cellData.showFeedName == .byline {
|
||||
@@ -50,14 +46,14 @@ final class MainTimelineCell: UITableViewCell {
|
||||
} else if cellData.showFeedName == .none {
|
||||
articleByLine.text = ""
|
||||
}
|
||||
|
||||
|
||||
if feedIcon != nil {
|
||||
setIconImage(cellData.iconImage, with: cellData.iconSize)
|
||||
}
|
||||
|
||||
|
||||
articleDate.text = cellData.dateString
|
||||
}
|
||||
|
||||
|
||||
private func updateIndicatorView(_ state: UICellConfigurationState) {
|
||||
if cellData.read == false {
|
||||
if indicatorView.alpha == 0.0 {
|
||||
@@ -68,8 +64,7 @@ final class MainTimelineCell: UITableViewCell {
|
||||
self.indicatorView.tintColor = (state.isSelected && !state.isSwiped) ? .white : Assets.Colors.secondaryAccent
|
||||
}
|
||||
return
|
||||
}
|
||||
else if cellData.starred {
|
||||
} else if cellData.starred {
|
||||
if indicatorView.alpha == 0.0 {
|
||||
indicatorView.alpha = 1.0
|
||||
}
|
||||
@@ -78,15 +73,14 @@ final class MainTimelineCell: UITableViewCell {
|
||||
self.indicatorView.tintColor = (state.isSelected && !state.isSwiped) ? .white : Assets.Colors.star
|
||||
}
|
||||
return
|
||||
}
|
||||
else if indicatorView.alpha == 1.0 {
|
||||
} else if indicatorView.alpha == 1.0 {
|
||||
UIView.animate(withDuration: Self.indicatorAnimationDuration) {
|
||||
self.indicatorView.alpha = 0.0
|
||||
self.indicatorView.iconImage = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func configureStackView() {
|
||||
switch traitCollection.preferredContentSizeCategory {
|
||||
case .accessibilityMedium, .accessibilityLarge, .accessibilityExtraLarge, .accessibilityExtraExtraLarge, .accessibilityExtraExtraExtraLarge:
|
||||
@@ -99,37 +93,37 @@ final class MainTimelineCell: UITableViewCell {
|
||||
metaDataStackView.distribution = .fillEqually
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func setIconImage(_ iconImage: IconImage?, with size: IconSize) {
|
||||
if feedIcon != nil {
|
||||
updateIconViewSizeConstraints(to: size.size)
|
||||
feedIcon!.iconImage = iconImage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updateIconViewSizeConstraints(to size: CGSize) {
|
||||
guard feedIcon != nil else { return }
|
||||
|
||||
|
||||
for constraint in feedIcon!.constraints.compactMap({ $0 }) {
|
||||
constraint.isActive = false
|
||||
}
|
||||
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
feedIcon!.widthAnchor.constraint(equalToConstant: size.width),
|
||||
feedIcon!.heightAnchor.constraint(equalToConstant: size.height)
|
||||
])
|
||||
|
||||
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
|
||||
private func addArticleContent(_ state: UICellConfigurationState) {
|
||||
let attributedCellText = NSMutableAttributedString()
|
||||
|
||||
|
||||
// 1. Prepare Title
|
||||
if cellData.title != "" {
|
||||
let titleFont = UIFont.preferredFont(forTextStyle: .headline)
|
||||
let lineHeight = titleFont.lineHeight
|
||||
|
||||
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.minimumLineHeight = lineHeight
|
||||
paragraphStyle.maximumLineHeight = lineHeight
|
||||
@@ -137,13 +131,13 @@ final class MainTimelineCell: UITableViewCell {
|
||||
paragraphStyle.lineBreakStrategy = []
|
||||
paragraphStyle.hyphenationFactor = 1.0
|
||||
paragraphStyle.allowsDefaultTighteningForTruncation = true
|
||||
|
||||
|
||||
let titleAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: titleFont,
|
||||
.paragraphStyle: paragraphStyle,
|
||||
.foregroundColor: UIColor.label
|
||||
]
|
||||
|
||||
|
||||
let titleAttributed = NSAttributedString(string: cellData.title, attributes: titleAttributes)
|
||||
let linesUsed = countLines(of: titleAttributed, width: articleContent.bounds.width)
|
||||
// 2. Measure Title Height
|
||||
@@ -153,15 +147,15 @@ final class MainTimelineCell: UITableViewCell {
|
||||
articleContent.lineBreakMode = .byTruncatingTail
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
attributedCellText.append(titleAttributed)
|
||||
}
|
||||
|
||||
|
||||
// 3. Prepare Summary (Only reached if Title < 3 lines)
|
||||
if cellData.summary != "" {
|
||||
let summaryFont = UIFont.preferredFont(forTextStyle: .body)
|
||||
let summaryLineHeight = summaryFont.lineHeight
|
||||
|
||||
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.minimumLineHeight = summaryLineHeight
|
||||
paragraphStyle.maximumLineHeight = summaryLineHeight
|
||||
@@ -169,18 +163,18 @@ final class MainTimelineCell: UITableViewCell {
|
||||
paragraphStyle.lineBreakStrategy = []
|
||||
paragraphStyle.hyphenationFactor = 1.0
|
||||
paragraphStyle.allowsDefaultTighteningForTruncation = true
|
||||
|
||||
|
||||
let summaryAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: summaryFont,
|
||||
.paragraphStyle: paragraphStyle,
|
||||
.foregroundColor: cellData.title != "" ? UIColor.secondaryLabel : UIColor.label
|
||||
]
|
||||
|
||||
|
||||
let prefix = cellData.title != "" ? "\n" : ""
|
||||
let summaryAttributed = NSAttributedString(string: prefix + cellData.summary, attributes: summaryAttributes)
|
||||
attributedCellText.append(summaryAttributed)
|
||||
}
|
||||
|
||||
|
||||
let linesUsed = countLines(of: attributedCellText, width: articleContent.bounds.width)
|
||||
if linesUsed >= cellData.numberOfLines {
|
||||
// The title already fills 3 lines, set it and exit
|
||||
@@ -193,7 +187,7 @@ final class MainTimelineCell: UITableViewCell {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func adjustArticleContentColor() {
|
||||
if configurationState.isSwiped && configurationState.isSelected {
|
||||
articleContent.textColor = .white
|
||||
@@ -213,22 +207,22 @@ final class MainTimelineCell: UITableViewCell {
|
||||
articleDate.textColor = .secondaryLabel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func countLines(of attributedString: NSAttributedString, width: CGFloat) -> Int {
|
||||
let textStorage = NSTextStorage(attributedString: attributedString)
|
||||
let textContainer = NSTextContainer(size: CGSize(width: width, height: .greatestFiniteMagnitude))
|
||||
let layoutManager = NSLayoutManager()
|
||||
|
||||
|
||||
layoutManager.addTextContainer(textContainer)
|
||||
textStorage.addLayoutManager(layoutManager)
|
||||
|
||||
|
||||
textContainer.lineFragmentPadding = 0 // UILabel uses 0 or very small
|
||||
layoutManager.ensureLayout(for: textContainer)
|
||||
|
||||
|
||||
var lineCount = 0
|
||||
var index = 0
|
||||
var lineRange = NSRange()
|
||||
|
||||
|
||||
while index < layoutManager.numberOfGlyphs {
|
||||
layoutManager.lineFragmentRect(forGlyphAt: index, effectiveRange: &lineRange)
|
||||
index = NSMaxRange(lineRange)
|
||||
@@ -236,18 +230,18 @@ final class MainTimelineCell: UITableViewCell {
|
||||
}
|
||||
return lineCount
|
||||
}
|
||||
|
||||
|
||||
override func updateConfiguration(using state: UICellConfigurationState) {
|
||||
super.updateConfiguration(using: state)
|
||||
|
||||
|
||||
var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state)
|
||||
backgroundConfig.cornerRadius = 20
|
||||
|
||||
|
||||
if traitCollection.userInterfaceIdiom == .pad {
|
||||
backgroundConfig.edgesAddingLayoutMarginsToBackgroundInsets = [.leading, .trailing]
|
||||
backgroundConfig.backgroundInsets = NSDirectionalEdgeInsets(top: 0, leading: !isPreview ? -12 : -12, bottom: 0, trailing: !isPreview ? -12 : -12)
|
||||
}
|
||||
|
||||
|
||||
if state.isSwiped && state.isSelected {
|
||||
backgroundConfig.backgroundColor = Assets.Colors.primaryAccent
|
||||
} else if state.isSwiped && !state.isSelected {
|
||||
@@ -259,8 +253,7 @@ final class MainTimelineCell: UITableViewCell {
|
||||
}
|
||||
adjustArticleContentColor()
|
||||
updateIndicatorView(state)
|
||||
|
||||
|
||||
self.backgroundConfiguration = backgroundConfig
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
@IBOutlet var articleDate: UILabel!
|
||||
@IBOutlet var metaDataStackView: UIStackView!
|
||||
@IBOutlet var topSeparator: UIView!
|
||||
|
||||
|
||||
var cellData: MainTimelineCellData! {
|
||||
didSet {
|
||||
configure(cellData)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isPreview: Bool = false
|
||||
|
||||
|
||||
private var rangeOfTitle: NSRange?
|
||||
private var rangeOfSummary: NSRange?
|
||||
|
||||
|
||||
private static let indicatorAnimationDuration = 0.25
|
||||
|
||||
|
||||
override func awakeFromNib() {
|
||||
MainActor.assumeIsolated {
|
||||
super.awakeFromNib()
|
||||
@@ -38,21 +38,17 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
configureStackView()
|
||||
}
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
}
|
||||
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
rangeOfTitle = nil
|
||||
rangeOfSummary = nil
|
||||
}
|
||||
|
||||
|
||||
private func configure(_ cellData: MainTimelineCellData) {
|
||||
articleContent.numberOfLines = cellData.numberOfLines
|
||||
addArticleContent(configurationState)
|
||||
|
||||
|
||||
if cellData.showFeedName == .feed {
|
||||
articleByLine.text = cellData.feedName
|
||||
} else if cellData.showFeedName == .byline {
|
||||
@@ -60,14 +56,14 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
} else if cellData.showFeedName == .none {
|
||||
articleByLine.text = ""
|
||||
}
|
||||
|
||||
|
||||
if feedIcon != nil {
|
||||
setIconImage(cellData.iconImage, with: cellData.iconSize)
|
||||
}
|
||||
|
||||
|
||||
articleDate.text = cellData.dateString
|
||||
}
|
||||
|
||||
|
||||
private func updateIndicatorView(_ state: UICellConfigurationState) {
|
||||
if cellData.read == false {
|
||||
if indicatorView.alpha == 0.0 {
|
||||
@@ -78,8 +74,7 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
self.indicatorView.tintColor = (state.isSelected && !state.isSwiped) ? .white : Assets.Colors.secondaryAccent
|
||||
}
|
||||
return
|
||||
}
|
||||
else if cellData.starred {
|
||||
} else if cellData.starred {
|
||||
if indicatorView.alpha == 0.0 {
|
||||
indicatorView.alpha = 1.0
|
||||
}
|
||||
@@ -88,15 +83,14 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
self.indicatorView.tintColor = (state.isSelected && !state.isSwiped) ? .white : Assets.Colors.star
|
||||
}
|
||||
return
|
||||
}
|
||||
else if indicatorView.alpha == 1.0 {
|
||||
} else if indicatorView.alpha == 1.0 {
|
||||
UIView.animate(withDuration: Self.indicatorAnimationDuration) {
|
||||
self.indicatorView.alpha = 0.0
|
||||
self.indicatorView.iconImage = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func configureStackView() {
|
||||
switch traitCollection.preferredContentSizeCategory {
|
||||
case .accessibilityMedium, .accessibilityLarge, .accessibilityExtraLarge, .accessibilityExtraExtraLarge, .accessibilityExtraExtraExtraLarge:
|
||||
@@ -109,37 +103,37 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
metaDataStackView.distribution = .fillEqually
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func setIconImage(_ iconImage: IconImage?, with size: IconSize) {
|
||||
if feedIcon != nil {
|
||||
updateIconViewSizeConstraints(to: size.size)
|
||||
feedIcon!.iconImage = iconImage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updateIconViewSizeConstraints(to size: CGSize) {
|
||||
guard feedIcon != nil else { return }
|
||||
|
||||
|
||||
for constraint in feedIcon!.constraints.compactMap({ $0 }) {
|
||||
constraint.isActive = false
|
||||
}
|
||||
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
feedIcon!.widthAnchor.constraint(equalToConstant: size.width),
|
||||
feedIcon!.heightAnchor.constraint(equalToConstant: size.height)
|
||||
])
|
||||
|
||||
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
|
||||
private func addArticleContent(_ state: UICellConfigurationState) {
|
||||
let attributedCellText = NSMutableAttributedString()
|
||||
|
||||
|
||||
// 1. Prepare Title
|
||||
if cellData.title != "" {
|
||||
let titleFont = UIFont.preferredFont(forTextStyle: .headline)
|
||||
let lineHeight = titleFont.lineHeight
|
||||
|
||||
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.minimumLineHeight = lineHeight
|
||||
paragraphStyle.maximumLineHeight = lineHeight
|
||||
@@ -147,18 +141,18 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
paragraphStyle.lineBreakStrategy = []
|
||||
paragraphStyle.hyphenationFactor = 1.0
|
||||
paragraphStyle.allowsDefaultTighteningForTruncation = true
|
||||
|
||||
|
||||
let titleAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: titleFont,
|
||||
.paragraphStyle: paragraphStyle,
|
||||
.foregroundColor: UIColor.label
|
||||
]
|
||||
|
||||
|
||||
let titleAttributed = NSAttributedString(string: cellData.title, attributes: titleAttributes)
|
||||
let titleLength = titleAttributed.length
|
||||
let tentativeTitleRange = NSRange(location: 0, length: titleLength)
|
||||
rangeOfTitle = tentativeTitleRange
|
||||
|
||||
|
||||
let linesUsed = countLines(of: titleAttributed, width: articleContent.bounds.width)
|
||||
// 2. Measure Title Height
|
||||
if linesUsed >= cellData.numberOfLines {
|
||||
@@ -169,16 +163,16 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
rangeOfTitle = NSRange(location: 0, length: titleAttributed.length)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
attributedCellText.append(titleAttributed)
|
||||
rangeOfTitle = NSRange(location: 0, length: titleAttributed.length)
|
||||
}
|
||||
|
||||
|
||||
// 3. Prepare Summary (Only reached if Title < 3 lines)
|
||||
if cellData.summary != "" {
|
||||
let summaryFont = UIFont.preferredFont(forTextStyle: .body)
|
||||
let summaryLineHeight = summaryFont.lineHeight
|
||||
|
||||
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.minimumLineHeight = summaryLineHeight
|
||||
paragraphStyle.maximumLineHeight = summaryLineHeight
|
||||
@@ -186,23 +180,23 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
paragraphStyle.lineBreakStrategy = []
|
||||
paragraphStyle.hyphenationFactor = 1.0
|
||||
paragraphStyle.allowsDefaultTighteningForTruncation = true
|
||||
|
||||
|
||||
let summaryAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: summaryFont,
|
||||
.paragraphStyle: paragraphStyle,
|
||||
.foregroundColor: cellData.title != "" ? UIColor.secondaryLabel : UIColor.label
|
||||
]
|
||||
|
||||
|
||||
let prefix = cellData.title != "" ? "\n" : ""
|
||||
let summaryAttributed = NSAttributedString(string: prefix + cellData.summary, attributes: summaryAttributes)
|
||||
let currentLength = attributedCellText.length
|
||||
let start = currentLength
|
||||
let length = summaryAttributed.length
|
||||
rangeOfSummary = NSRange(location: start, length: length)
|
||||
|
||||
|
||||
attributedCellText.append(summaryAttributed)
|
||||
}
|
||||
|
||||
|
||||
let linesUsed = countLines(of: attributedCellText, width: articleContent.bounds.width)
|
||||
if linesUsed >= cellData.numberOfLines {
|
||||
// The title already fills 3 lines, set it and exit
|
||||
@@ -215,7 +209,7 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func adjustArticleContentColor() {
|
||||
func applyTitleColour() {
|
||||
guard let titleRange = rangeOfTitle, titleRange.location != NSNotFound, titleRange.length > 0 else { return }
|
||||
@@ -252,22 +246,22 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
articleDate.textColor = .secondaryLabel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func countLines(of attributedString: NSAttributedString, width: CGFloat) -> Int {
|
||||
let textStorage = NSTextStorage(attributedString: attributedString)
|
||||
let textContainer = NSTextContainer(size: CGSize(width: width, height: .greatestFiniteMagnitude))
|
||||
let layoutManager = NSLayoutManager()
|
||||
|
||||
|
||||
layoutManager.addTextContainer(textContainer)
|
||||
textStorage.addLayoutManager(layoutManager)
|
||||
|
||||
|
||||
textContainer.lineFragmentPadding = 0 // UILabel uses 0 or very small
|
||||
layoutManager.ensureLayout(for: textContainer)
|
||||
|
||||
|
||||
var lineCount = 0
|
||||
var index = 0
|
||||
var lineRange = NSRange()
|
||||
|
||||
|
||||
while index < layoutManager.numberOfGlyphs {
|
||||
layoutManager.lineFragmentRect(forGlyphAt: index, effectiveRange: &lineRange)
|
||||
index = NSMaxRange(lineRange)
|
||||
@@ -275,18 +269,18 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
}
|
||||
return lineCount
|
||||
}
|
||||
|
||||
|
||||
override func updateConfiguration(using state: UICellConfigurationState) {
|
||||
super.updateConfiguration(using: state)
|
||||
|
||||
|
||||
var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state)
|
||||
backgroundConfig.cornerRadius = 20
|
||||
|
||||
|
||||
if traitCollection.userInterfaceIdiom == .pad {
|
||||
backgroundConfig.edgesAddingLayoutMarginsToBackgroundInsets = [.leading, .trailing]
|
||||
backgroundConfig.backgroundInsets = NSDirectionalEdgeInsets(top: 0, leading: !isPreview ? -12 : -12, bottom: 0, trailing: !isPreview ? -12 : -12)
|
||||
}
|
||||
|
||||
|
||||
if state.isSwiped && state.isSelected {
|
||||
backgroundConfig.backgroundColor = Assets.Colors.primaryAccent
|
||||
topSeparator.alpha = 0.0
|
||||
@@ -302,9 +296,8 @@ class MainTimelineCollectionViewCell: UICollectionViewCell {
|
||||
}
|
||||
adjustArticleContentColor()
|
||||
updateIndicatorView(state)
|
||||
|
||||
|
||||
self.backgroundConfiguration = backgroundConfig
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,11 +15,10 @@ final class MainTimelineDataSource<SectionIdentifierType, ItemIdentifierType>: U
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class MainTimelineCollectionViewDataSource<SectionIdentifierType, ItemIdentifierType>: UICollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> where SectionIdentifierType: Hashable, ItemIdentifierType: Hashable {
|
||||
|
||||
|
||||
override func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,9 +14,8 @@ import RSWeb
|
||||
import Account
|
||||
import Articles
|
||||
|
||||
|
||||
final class MainTimelineModernViewController: UIViewController, UndoableCommandRunner {
|
||||
|
||||
|
||||
struct CellIdentifier {
|
||||
static let standard = "MainTimelineCellStandard"
|
||||
static let standardIndex0 = "MainTimelineCellIndexZero"
|
||||
@@ -32,7 +31,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
private lazy var filterButton = UIBarButtonItem(image: Assets.Images.filter, style: .plain, target: self, action: #selector(toggleFilter(_:)))
|
||||
private lazy var firstUnreadButton = UIBarButtonItem(image: Assets.Images.nextUnread, style: .plain, target: self, action: #selector(firstUnread(_:)))
|
||||
private lazy var dataSource = makeDataSource()
|
||||
|
||||
|
||||
private var timelineFeed: SidebarItem? {
|
||||
assert(coordinator != nil)
|
||||
return coordinator?.timelineFeed
|
||||
@@ -94,7 +93,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
assert(coordinator != nil)
|
||||
return coordinator?.articles
|
||||
}
|
||||
|
||||
|
||||
private lazy var navigationBarTitleLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.font = UIFont.preferredFont(forTextStyle: .subheadline).bold()
|
||||
@@ -121,7 +120,6 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
return label
|
||||
}()
|
||||
|
||||
|
||||
// MARK: Variables
|
||||
weak var coordinator: SceneCoordinator?
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
@@ -136,29 +134,27 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private Constants
|
||||
private let searchController = UISearchController(searchResultsController: nil)
|
||||
private let keyboardManager = KeyboardManager(type: .timeline)
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "MainTimelineModernViewController")
|
||||
|
||||
|
||||
// MARK: Constants
|
||||
let scrollPositionQueue = CoalescingQueue(name: "Timeline Scroll Position", interval: 0.3, maxInterval: 1.0)
|
||||
|
||||
|
||||
// MARK: - IBOutlets
|
||||
@IBOutlet var markAllAsReadButton: UIBarButtonItem?
|
||||
@IBOutlet var collectionView: UICollectionView!
|
||||
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
||||
addNotificationObservers()
|
||||
configureCollectionView()
|
||||
configureSearchController()
|
||||
definesPresentationContext = true
|
||||
|
||||
|
||||
numberOfTextLines = AppDefaults.shared.timelineNumberOfLines
|
||||
iconSize = AppDefaults.shared.timelineIconSize
|
||||
|
||||
@@ -187,7 +183,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
navigationItem.subtitleView = navigationBarSubtitleTitleLabel
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
Self.logger.debug("MainTimelineModernViewController: viewWillAppear")
|
||||
|
||||
@@ -256,7 +252,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
label.sizeToFit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func reinitializeArticles(resetScroll: Bool) {
|
||||
Self.logger.debug("MainTimelineModernViewController: reinitializeArticles")
|
||||
resetUI(resetScroll: resetScroll)
|
||||
@@ -269,7 +265,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
|
||||
func updateArticleSelection(animations: Animations) {
|
||||
Self.logger.debug("MainTimelineModernViewController: updateArticleSelection")
|
||||
|
||||
|
||||
if let article = currentArticle,
|
||||
let indexPath = dataSource.indexPath(for: article), let indexPaths = collectionView.indexPathsForSelectedItems {
|
||||
if indexPaths.contains(indexPath) {
|
||||
@@ -304,7 +300,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
Self.logger.debug("MainTimelineModernViewController: focus")
|
||||
becomeFirstResponder()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Reloading
|
||||
|
||||
func queueReloadAvailableCells() {
|
||||
@@ -335,9 +331,9 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
self?.restoreSelectionIfNecessary(adjustScroll: false)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@objc func refreshAccounts(_ sender: Any) {
|
||||
collectionView.refreshControl?.endRefreshing()
|
||||
|
||||
@@ -347,7 +343,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Keyboard shortcuts
|
||||
|
||||
@objc func selectNextUp(_ sender: Any?) {
|
||||
@@ -374,7 +370,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
assert(coordinator != nil)
|
||||
coordinator?.showFeedInspector()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - IBActions
|
||||
|
||||
@objc func openInBrowser(_ sender: Any?) {
|
||||
@@ -434,7 +430,6 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
|
||||
}
|
||||
|
||||
|
||||
// MARK: - UICollectionViewDelegate
|
||||
|
||||
extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
@@ -443,16 +438,16 @@ extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
let article = dataSource.itemIdentifier(for: indexPath)
|
||||
coordinator?.selectArticle(article, animations: [.scroll, .select, .navigation])
|
||||
}
|
||||
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
guard let firstIndex = indexPaths.first, let article = dataSource.itemIdentifier(for: firstIndex) else { return nil }
|
||||
|
||||
|
||||
return UIContextMenuConfiguration(identifier: firstIndex.row as NSCopying, previewProvider: nil, actionProvider: { [weak self] _ in
|
||||
|
||||
|
||||
guard let self = self else { return nil }
|
||||
|
||||
|
||||
var menuElements = [UIMenuElement]()
|
||||
|
||||
|
||||
var markActions = [UIAction]()
|
||||
if let action = self.toggleArticleReadStatusAction(article) {
|
||||
markActions.append(action)
|
||||
@@ -465,7 +460,7 @@ extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
markActions.append(action)
|
||||
}
|
||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: markActions))
|
||||
|
||||
|
||||
var secondaryActions = [UIAction]()
|
||||
if let action = self.discloseFeedAction(article) {
|
||||
secondaryActions.append(action)
|
||||
@@ -476,7 +471,7 @@ extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
if !secondaryActions.isEmpty {
|
||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: secondaryActions))
|
||||
}
|
||||
|
||||
|
||||
var copyActions = [UIAction]()
|
||||
if let action = self.copyArticleURLAction(article) {
|
||||
copyActions.append(action)
|
||||
@@ -487,26 +482,26 @@ extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
if !copyActions.isEmpty {
|
||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: copyActions))
|
||||
}
|
||||
|
||||
|
||||
if let action = self.openInBrowserAction(article) {
|
||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: [action]))
|
||||
}
|
||||
|
||||
|
||||
if let action = self.shareAction(article, indexPath: firstIndex) {
|
||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: [action]))
|
||||
}
|
||||
|
||||
|
||||
return UIMenu(title: "", children: menuElements)
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, highlightPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? {
|
||||
guard let row = configuration.identifier as? Int,
|
||||
let cell = collectionView.cellForItem(at: IndexPath(row: row, section: 0)) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let previewView = cell.contentView
|
||||
let parameters = UIPreviewParameters()
|
||||
parameters.backgroundColor = .tertiarySystemBackground
|
||||
@@ -514,14 +509,13 @@ extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
cornerRadius: 20)
|
||||
return UITargetedPreview(view: cell, parameters: parameters)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, dismissalPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? {
|
||||
guard let row = configuration.identifier as? Int,
|
||||
let cell = collectionView.cellForItem(at: IndexPath(row: row, section: 0)), let _ = view.window else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let previewView = cell.contentView
|
||||
let parameters = UIPreviewParameters()
|
||||
parameters.backgroundColor = .clear
|
||||
@@ -529,13 +523,12 @@ extension MainTimelineModernViewController: UICollectionViewDelegate {
|
||||
cornerRadius: 20)
|
||||
return UITargetedPreview(view: cell, parameters: parameters)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: Private API
|
||||
private extension MainTimelineModernViewController {
|
||||
|
||||
|
||||
func addNotificationObservers() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||
@@ -558,7 +551,7 @@ private extension MainTimelineModernViewController {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange), name: .DisplayNameDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)
|
||||
}
|
||||
|
||||
|
||||
private func configureSearchController() {
|
||||
// Setup the Search Controller
|
||||
searchController.delegate = self
|
||||
@@ -574,13 +567,13 @@ private extension MainTimelineModernViewController {
|
||||
searchController.searchBar.scopeBarBackgroundImage = UIImage()
|
||||
searchController.searchBar.autocapitalizationType = .none
|
||||
navigationItem.searchController = searchController
|
||||
|
||||
|
||||
if traitCollection.userInterfaceIdiom == .pad {
|
||||
searchController.searchBar.selectedScopeButtonIndex = 1
|
||||
navigationItem.searchBarPlacementAllowsExternalIntegration = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func configureCollectionView() {
|
||||
var config = UICollectionLayoutListConfiguration(appearance: .plain)
|
||||
config.showsSeparators = false
|
||||
@@ -588,7 +581,7 @@ private extension MainTimelineModernViewController {
|
||||
config.trailingSwipeActionsConfigurationProvider = { [unowned self] indexPath in
|
||||
guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil }
|
||||
var actions = [UIContextualAction]()
|
||||
|
||||
|
||||
// Set up the star action
|
||||
let starTitle = article.status.starred ?
|
||||
NSLocalizedString("Unstar", comment: "Unstar") :
|
||||
@@ -602,7 +595,7 @@ private extension MainTimelineModernViewController {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.85, execute: {
|
||||
self?.toggleStar(article)
|
||||
})
|
||||
|
||||
|
||||
completion(true)
|
||||
}
|
||||
|
||||
@@ -658,7 +651,7 @@ private extension MainTimelineModernViewController {
|
||||
|
||||
moreAction.image = Assets.Images.more
|
||||
moreAction.backgroundColor = UIColor.systemGray
|
||||
|
||||
|
||||
actions.append(starAction)
|
||||
actions.append(moreAction)
|
||||
|
||||
@@ -671,7 +664,7 @@ private extension MainTimelineModernViewController {
|
||||
guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil }
|
||||
guard !article.status.read || article.isAvailableToMarkUnread else { return nil }
|
||||
var actions = [UIContextualAction]()
|
||||
|
||||
|
||||
// Set up the read action
|
||||
let readTitle = article.status.read ?
|
||||
NSLocalizedString("Mark as Unread", comment: "Mark as Unread") :
|
||||
@@ -691,21 +684,21 @@ private extension MainTimelineModernViewController {
|
||||
readAction.image = article.status.read ? Assets.Images.circleClosed : Assets.Images.circleOpen
|
||||
readAction.backgroundColor = Assets.Colors.primaryAccent
|
||||
actions.append(readAction)
|
||||
|
||||
|
||||
let config = UISwipeActionsConfiguration(actions: actions)
|
||||
config.performsFirstActionWithFullSwipe = true
|
||||
return config
|
||||
}
|
||||
|
||||
|
||||
collectionView.refreshControl = UIRefreshControl()
|
||||
collectionView.refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
||||
collectionView.contentInsetAdjustmentBehavior = .automatic
|
||||
|
||||
let layout = UICollectionViewCompositionalLayout { sectionIndex, layoutEnvironment in
|
||||
|
||||
let layout = UICollectionViewCompositionalLayout { _, layoutEnvironment in
|
||||
let listConfig = config
|
||||
|
||||
|
||||
let section = NSCollectionLayoutSection.list(using: listConfig, layoutEnvironment: layoutEnvironment)
|
||||
|
||||
|
||||
/// Note to future self: apply insets that affect cell width
|
||||
/// calculations (leading swipe actions with sidebar visible)
|
||||
section.contentInsets = NSDirectionalEdgeInsets(
|
||||
@@ -714,13 +707,13 @@ private extension MainTimelineModernViewController {
|
||||
bottom: 0,
|
||||
trailing: 0
|
||||
)
|
||||
|
||||
|
||||
return section
|
||||
}
|
||||
layout.configuration.contentInsetsReference = .safeArea
|
||||
collectionView.collectionViewLayout = layout
|
||||
}
|
||||
|
||||
|
||||
private func makeDataSource() -> UICollectionViewDiffableDataSource<Int, Article> {
|
||||
let dataSource: UICollectionViewDiffableDataSource<Int, Article> =
|
||||
MainTimelineCollectionViewDataSource(collectionView: collectionView, cellProvider: { [weak self] collectionView, indexPath, article in
|
||||
@@ -747,10 +740,10 @@ private extension MainTimelineModernViewController {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return dataSource
|
||||
}
|
||||
|
||||
|
||||
@discardableResult
|
||||
private func configure(article: Article) -> MainTimelineCellData {
|
||||
let iconImage = iconImageFor(article)
|
||||
@@ -759,14 +752,14 @@ private extension MainTimelineModernViewController {
|
||||
let cellData = MainTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcon, numberOfLines: numberOfTextLines, iconSize: iconSize)
|
||||
return cellData
|
||||
}
|
||||
|
||||
|
||||
private func iconImageFor(_ article: Article) -> IconImage? {
|
||||
if !showIcons {
|
||||
return nil
|
||||
}
|
||||
return article.iconImage()
|
||||
}
|
||||
|
||||
|
||||
func searchArticles(_ searchString: String, _ searchScope: SearchScope) {
|
||||
assert(coordinator != nil)
|
||||
coordinator?.searchArticles(searchString, searchScope)
|
||||
@@ -798,7 +791,7 @@ private extension MainTimelineModernViewController {
|
||||
if resetScroll {
|
||||
let snapshot = dataSource.snapshot()
|
||||
if snapshot.sectionIdentifiers.count > 0 && snapshot.itemIdentifiers(inSection: 0).count > 0 {
|
||||
//collectionView.selectItem(at: IndexPath(item: 0, section: 0), animated: false, scrollPosition: .top)
|
||||
// collectionView.selectItem(at: IndexPath(item: 0, section: 0), animated: false, scrollPosition: .top)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,10 +827,6 @@ private extension MainTimelineModernViewController {
|
||||
completion?()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -916,7 +905,7 @@ private extension MainTimelineModernViewController {
|
||||
|
||||
updateIconForVisibleArticles()
|
||||
}
|
||||
|
||||
|
||||
/// Update icon for all visible articles — or, if feed is non-nil, update articles only from that feed.
|
||||
private func updateIconForVisibleArticles(_ feed: Feed? = nil) {
|
||||
guard isViewLoaded, view.window != nil else {
|
||||
@@ -1297,4 +1286,3 @@ extension MainTimelineModernViewController {
|
||||
return action
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user