diff --git a/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift b/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift index e3ab8d830..fd71a9829 100644 --- a/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift +++ b/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift @@ -28,6 +28,13 @@ extension UICollectionView { scrollToItem(at: indexPath, at: .centeredVertically, animated: true) } } + + public func middleVisibleRow() -> IndexPath? { + if indexPathsForVisibleItems.count > 2 { + return indexPathsForVisibleItems[indexPathsForVisibleItems.count / 2] + } + return nil + } } diff --git a/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift b/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift new file mode 100644 index 000000000..6e850b43c --- /dev/null +++ b/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift @@ -0,0 +1,262 @@ +// +// MainTimelineCollectionViewCell.swift +// NetNewsWire-iOS +// +// Created by Stuart Breckenridge on 24/01/2026. +// Copyright © 2026 Ranchero Software. All rights reserved. +// + +import UIKit + +class MainTimelineCollectionViewCell: UICollectionViewCell { + @IBOutlet var articleContent: UILabel! + @IBOutlet var articleByLine: UILabel! + @IBOutlet var feedIcon: IconView? + @IBOutlet var indicatorView: IconView! + @IBOutlet var articleDate: UILabel! + @IBOutlet var metaDataStackView: UIStackView! + + var cellData: MainTimelineCellData! { + didSet { + configure(cellData) + } + } + + var isPreview: Bool = false + + override func awakeFromNib() { + MainActor.assumeIsolated { + super.awakeFromNib() + indicatorView.alpha = 0.0 + feedIcon?.translatesAutoresizingMaskIntoConstraints = false + 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 { + articleByLine.text = cellData.byline + } 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 { + indicatorView.alpha = 1.0 + } + UIView.animate(withDuration: 0.25) { + self.indicatorView.iconImage = Assets.Images.unreadCellIndicator + self.indicatorView.tintColor = self.isActive(state) ? .white : Assets.Colors.secondaryAccent + } + return + } else if cellData.starred { + if indicatorView.alpha == 0.0 { + indicatorView.alpha = 1.0 + } + UIView.animate(withDuration: 0.25) { + self.indicatorView.iconImage = Assets.Images.starredFeed + self.indicatorView.tintColor = self.isActive(state) ? .white : Assets.Colors.star + } + return + } else if indicatorView.alpha == 1.0 { + UIView.animate(withDuration: 0.25) { + self.indicatorView.alpha = 0.0 + self.indicatorView.iconImage = nil + } + } + } + + private func configureStackView() { + switch traitCollection.preferredContentSizeCategory { + case .accessibilityMedium, .accessibilityLarge, .accessibilityExtraLarge, .accessibilityExtraExtraLarge, .accessibilityExtraExtraExtraLarge: + metaDataStackView.axis = .vertical + metaDataStackView.alignment = .leading + metaDataStackView.distribution = .fill + default: + metaDataStackView.axis = .horizontal + metaDataStackView.alignment = .bottom + metaDataStackView.distribution = .fillEqually + } + } + + private func isActive(_ state: UICellConfigurationState) -> Bool { + let active = state.isSwiped || state.isSelected || state.isEditing || state.isHighlighted + if cellData.title.contains("Vouchers") { + print("Vouchers: \(active)") + } + return active + } + + func setIconImage(_ iconImage: IconImage?) { + if feedIcon!.iconImage !== iconImage { + feedIcon!.iconImage = iconImage + } + } + + private func setIconImage(_ iconImage: IconImage?, with size: IconSize) { + feedIcon!.iconImage = iconImage + updateIconViewSizeConstraints(to: size.size) + } + + 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 + paragraphStyle.lineBreakMode = .byWordWrapping + paragraphStyle.lineBreakStrategy = [] + paragraphStyle.hyphenationFactor = 1.0 + paragraphStyle.allowsDefaultTighteningForTruncation = true + + let titleAttributes: [NSAttributedString.Key: Any] = [ + .font: titleFont, + .paragraphStyle: paragraphStyle, + .foregroundColor: titleTextColor(for: state) + ] + + let titleAttributed = NSAttributedString(string: cellData.title, attributes: titleAttributes) + let linesUsed = countLines(of: titleAttributed, width: articleContent.bounds.width) + // 2. Measure Title Height + if linesUsed >= cellData.numberOfLines { + // The title already fills 3 lines, set it and exit + articleContent.attributedText = titleAttributed + 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 + paragraphStyle.lineBreakMode = .byWordWrapping + paragraphStyle.lineBreakStrategy = [] + paragraphStyle.hyphenationFactor = 1.0 + paragraphStyle.allowsDefaultTighteningForTruncation = true + + let summaryAttributes: [NSAttributedString.Key: Any] = [ + .font: summaryFont, + .paragraphStyle: paragraphStyle, + .foregroundColor: titleTextColor(for: state) + ] + + 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 + articleContent.attributedText = attributedCellText + articleContent.lineBreakMode = .byTruncatingTail + return + } else { + articleContent.attributedText = attributedCellText + articleContent.lineBreakMode = .byWordWrapping + } + + } + + func titleTextColor(for state: UICellConfigurationState) -> UIColor { + if isActive(state) { + return .white + } else { + return .label + } + } + + 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) + lineCount += 1 + } + 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 ? -4 : -12, bottom: 0, trailing: !isPreview ? -4 : -12) + } + + if isActive(state) { + backgroundConfig.backgroundColor = Assets.Colors.primaryAccent + articleContent.textColor = titleTextColor(for: state) + articleDate.textColor = .lightText + articleByLine.textColor = .lightText + } else { + articleContent.textColor = titleTextColor(for: state) + articleDate.textColor = .secondaryLabel + articleByLine.textColor = .secondaryLabel + } + + updateIndicatorView(state) + + self.backgroundConfiguration = backgroundConfig + } + +} diff --git a/iOS/MainTimeline/MainTimelineCollectionViewController.swift b/iOS/MainTimeline/MainTimelineCollectionViewController.swift new file mode 100644 index 000000000..a7579b4eb --- /dev/null +++ b/iOS/MainTimeline/MainTimelineCollectionViewController.swift @@ -0,0 +1,1156 @@ +// +// MainTimelineCollectionViewController.swift +// NetNewsWire-iOS +// +// Created by Stuart Breckenridge on 24/01/2026. +// Copyright © 2026 Ranchero Software. All rights reserved. +// + +import UIKit +import os +import WebKit +import RSCore +import RSWeb +import Account +import Articles + +let standardCellIdentifier = "MainTimelineCellStandard" +let standardCellIdentifierIndex0 = "MainTimelineCellIndexZero" +let standardCellIdentifierIcon = "MainTimelineCellIcon" +let standardCellIdentifierIconIndex0 = "MainTimelineCellIconIndexZero" + + +final class MainTimelineCollectionViewController: UICollectionViewController, UndoableCommandRunner { + + // MARK: Private Variables + private var numberOfTextLines = 0 + private var iconSize = IconSize.medium + private var refreshProgressView: RefreshProgressView? + private lazy var feedTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showFeedInspector(_:))) + 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 + } + + private var showIcons: Bool { + assert(coordinator != nil) + return coordinator?.showIcons ?? false + } + + private var currentArticle: Article? { + assert(coordinator != nil) + return coordinator?.currentArticle + } + + private var timelineMiddleIndexPath: IndexPath? { + get { + coordinator?.timelineMiddleIndexPath + } + set { + coordinator?.timelineMiddleIndexPath = newValue + } + } + + private var isTimelineViewControllerPending: Bool { + get { + coordinator?.isTimelineViewControllerPending ?? false + } + set { + coordinator?.isTimelineViewControllerPending = newValue + } + } + + private var timelineIconImage: IconImage? { + assert(coordinator != nil) + return coordinator?.timelineIconImage + } + + private var timelineDefaultReadFilterType: ReadFilterType { + return timelineFeed?.defaultReadFilterType ?? .none + } + + private var isReadArticlesFiltered: Bool { + assert(coordinator != nil) + return coordinator?.isReadArticlesFiltered ?? false + } + + private var isTimelineUnreadAvailable: Bool { + assert(coordinator != nil) + return coordinator?.isTimelineUnreadAvailable ?? false + } + + private var isRootSplitCollapsed: Bool { + assert(coordinator != nil) + return coordinator?.isRootSplitCollapsed ?? false + } + + private var articles: ArticleArray? { + assert(coordinator != nil) + return coordinator?.articles + } + + private lazy var navigationBarTitleLabel: UILabel = { + let label = UILabel() + label.font = UIFont.preferredFont(forTextStyle: .subheadline).bold() + label.isUserInteractionEnabled = true + label.numberOfLines = 1 + label.textAlignment = .center + label.adjustsFontForContentSizeCategory = false + let tap = UITapGestureRecognizer(target: self, action: #selector(showFeedInspector(_:))) + label.addGestureRecognizer(tap) + let pointerInteraction = UIPointerInteraction(delegate: nil) + label.addInteraction(pointerInteraction) + return label + }() + + private lazy var navigationBarSubtitleTitleLabel: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Helvetica", size: 12) + label.textColor = .systemGray + label.textAlignment = .center + label.isUserInteractionEnabled = true + label.adjustsFontForContentSizeCategory = false + let tap = UITapGestureRecognizer(target: self, action: #selector(showFeedInspector(_:))) + label.addGestureRecognizer(tap) + return label + }() + + + // MARK: Variables + weak var coordinator: SceneCoordinator? + var undoableCommands = [UndoableCommand]() + override var keyCommands: [UIKeyCommand]? { + // If the first responder is the WKWebView (PreloadedWebView) we don't want to supply any keyboard + // commands that the system is looking for by going up the responder chain. They will interfere with + // the WKWebViews built in hardware keyboard shortcuts, specifically the up and down arrow keys. + guard let current = UIResponder.currentFirstResponder, !(current is PreloadedWebView) else { return nil } + + return keyboardManager.keyCommands + } + 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: "MainTimelineCollectionViewController") + + // MARK: Constantns + let scrollPositionQueue = CoalescingQueue(name: "Timeline Scroll Position", interval: 0.3, maxInterval: 1.0) + + + // MARK: - IBOutlets + @IBOutlet var markAllAsReadButton: UIBarButtonItem? + + // MARK: - Lifecycle + + override func viewDidLoad() { + Self.logger.debug("MainTimelineCollectionViewController: viewDidLoad") + assert(coordinator != nil) + + super.viewDidLoad() + + addNotificationObservers() + configureSearchController() + definesPresentationContext = true + + // Uncomment the following line to preserve selection between presentations + self.clearsSelectionOnViewWillAppear = false + + } + + func restoreSelectionIfNecessary(adjustScroll: Bool) { + if let article = currentArticle, let indexPath = dataSource.indexPath(for: article) { + if adjustScroll { + collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: []) + } else { + collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically) + } + } + } + + func updateNavigationBarTitle(_ text: String) { + navigationItem.title = text + if let label = navigationItem.titleView as? UILabel { + label.text = text + label.isUserInteractionEnabled = ((coordinator?.timelineFeed as? PseudoFeed) == nil) + label.sizeToFit() + } + } + + func updateNavigationBarSubtitle(_ text: String) { + if let label = navigationItem.subtitleView as? UILabel { + label.text = text + label.isUserInteractionEnabled = ((coordinator?.timelineFeed as? PseudoFeed) == nil) + label.sizeToFit() + } + } + + func reinitializeArticles(resetScroll: Bool) { + Self.logger.debug("MainTimelineViewController: reinitializeArticles") + resetUI(resetScroll: resetScroll) + } + + func reloadArticles(animated: Bool) { + Self.logger.debug("MainTimelineViewController: reloadArticles") + applyChanges(animated: animated) + } + + func updateArticleSelection(animations: Animations) { + Self.logger.debug("MainTimelineViewController: updateArticleSelection") + + if let article = currentArticle, let indexPath = dataSource.indexPath(for: article) { + if collectionView.indexPathsForSelectedItems?.first != indexPath { + collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: animations) + } + } else { + collectionView.selectItem(at: nil, animated: animations.contains(.select), scrollPosition: .centeredVertically) + } + + updateUI() + } + + func updateUI() { + Self.logger.debug("MainTimelineViewController: updateUI") + + refreshProgressView?.update() + updateToolbar() + } + + func hideSearch() { + navigationItem.searchController?.isActive = false + } + + func showSearchAll() { + navigationItem.searchController?.isActive = true + navigationItem.searchController?.searchBar.selectedScopeButtonIndex = 1 + navigationItem.searchController?.searchBar.becomeFirstResponder() + } + + func focus() { + Self.logger.debug("MainTimelineViewController: focus") + becomeFirstResponder() + } + + // MARK: - Reloading + + func queueReloadAvailableCells() { + CoalescingQueue.standard.add(self, #selector(reconfigureVisibleCells)) + } + + @objc private func reconfigureVisibleCells() { + guard isViewLoaded, view.window != nil else { + return + } + let indexPaths = collectionView.indexPathsForVisibleItems + + let visibleArticles = indexPaths.compactMap { dataSource.itemIdentifier(for: $0) } + reconfigureCells(visibleArticles) + } + + private func reconfigureCells(_ articles: [Article]) { + guard !articles.isEmpty else { + return + } + + var snapshot = dataSource.snapshot() + snapshot.reconfigureItems(articles) + dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in + self?.restoreSelectionIfNecessary(adjustScroll: false) + } + } + + @objc func refreshAccounts(_ sender: Any) { + collectionView.refreshControl?.endRefreshing() + + // This is a hack to make sure that an error dialog doesn't interfere with dismissing the refreshControl. + // If the error dialog appears too closely to the call to endRefreshing, then the refreshControl never disappears. + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self)) + } + } + + // MARK: - Keyboard shortcuts + + @objc func selectNextUp(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.selectPrevArticle() + } + + @objc func selectNextDown(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.selectNextArticle() + } + + @objc func navigateToSidebar(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.navigateToFeeds() + } + + @objc func navigateToDetail(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.navigateToDetail() + } + + @objc func showFeedInspector(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.showFeedInspector() + } + + // MARK: - IBActions + + @objc func openInBrowser(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.showBrowserForCurrentArticle() + } + + @objc func openInAppBrowser(_ sender: Any?) { + assert(coordinator != nil) + coordinator?.showInAppBrowser() + } + + @IBAction func toggleFilter(_ sender: Any) { + assert(coordinator != nil) + coordinator?.toggleReadArticlesFilter() + } + + private func markAllAsReadInTimeline() { + assert(coordinator != nil) + coordinator?.markAllAsReadInTimeline() + } + + @IBAction func markAllAsRead(_ sender: Any?) { + let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read") + + if let source = sender as? UIBarButtonItem { + MarkAsReadAlertController.confirm(self, coordinator: coordinator, confirmTitle: title, sourceType: source) { [weak self] in + self?.markAllAsReadInTimeline() + } + } + + if sender is UIKeyCommand { + guard let indexPath = collectionView.indexPathsForSelectedItems?.first, let contentView = collectionView.cellForItem(at: indexPath)?.contentView else { + return + } + + MarkAsReadAlertController.confirm(self, coordinator: coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in + self?.markAllAsReadInTimeline() + } + } + } + + @IBAction func firstUnread(_ sender: Any) { + assert(coordinator != nil) + coordinator?.selectFirstUnread() + } + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. + } + */ + + // MARK: UICollectionViewDataSource + + override func numberOfSections(in collectionView: UICollectionView) -> Int { + // #warning Incomplete implementation, return the number of sections + return 0 + } + + + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + // #warning Incomplete implementation, return the number of items + return 0 + } + + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: standardCellIdentifier, for: indexPath) + + // Configure the cell + + return cell + } + + // MARK: UICollectionViewDelegate + + /* + // Uncomment this method to specify if the specified item should be highlighted during tracking + override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { + return true + } + */ + + /* + // Uncomment this method to specify if the specified item should be selected + override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { + return true + } + */ + + /* + // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item + override func collectionView(_ collectionView: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool { + return false + } + + override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool { + return false + } + + override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) { + + } + */ + +} + + +// MARK: Private API +private extension MainTimelineCollectionViewController { + + func addNotificationObservers() { + NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil) + + // TODO: fix this temporary hack, which will probably require refactoring image handling. + // We want to know when to possibly reconfigure our cells with a new image, and we don’t + // always know when an image is available — but watching the .htmlMetadataAvailable Notification + // lets us know that it’s time to request an image. + NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .htmlMetadataAvailable, object: nil) + + NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in + Task { @MainActor in + self?.userDefaultsDidChange() + } + } + NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil) + 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 + searchController.searchResultsUpdater = self + searchController.obscuresBackgroundDuringPresentation = false + searchController.searchBar.delegate = self + searchController.searchBar.placeholder = NSLocalizedString("Search Articles", comment: "Search Articles") + searchController.searchBar.scopeButtonTitles = [ + NSLocalizedString("Here", comment: "Here"), + NSLocalizedString("All Articles", comment: "All Articles") + ] + searchController.searchBar.barTintColor = .clear + 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.separatorConfiguration.color = .separator + config.headerMode = .none + + 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") : + NSLocalizedString("Star", comment: "Star") + + let starAction = UIContextualAction(style: .normal, title: starTitle) { [weak self] _, _, completion in + self?.toggleStar(article) + completion(true) + } + + starAction.image = article.status.starred ? Assets.Images.starOpen : Assets.Images.starClosed + starAction.backgroundColor = Assets.Colors.star + + // Set up the read action + let moreTitle = NSLocalizedString("More", comment: "More") + let moreAction = UIContextualAction(style: .normal, title: moreTitle) { [weak self] (action, view, completion) in + + if let self = self { + + let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) + if let popoverController = alert.popoverPresentationController { + popoverController.sourceView = view + popoverController.sourceRect = CGRect(x: view.frame.size.width/2, y: view.frame.size.height/2, width: 1, height: 1) + } + + if let action = self.markAboveAsReadAlertAction(article, indexPath: indexPath, completion: completion) { + alert.addAction(action) + } + + if let action = self.markBelowAsReadAlertAction(article, indexPath: indexPath, completion: completion) { + alert.addAction(action) + } + + if let action = self.discloseFeedAlertAction(article, completion: completion) { + alert.addAction(action) + } + + if let action = self.markAllInFeedAsReadAlertAction(article, indexPath: indexPath, completion: completion) { + alert.addAction(action) + } + + if let action = self.openInBrowserAlertAction(article, completion: completion) { + alert.addAction(action) + } + + if let action = self.shareAlertAction(article, indexPath: indexPath, completion: completion) { + alert.addAction(action) + } + + let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel") + alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in + completion(true) + }) + + self.present(alert, animated: true) + + } + + } + + moreAction.image = Assets.Images.more + moreAction.backgroundColor = UIColor.systemGray + + actions.append(starAction) + actions.append(moreAction) + + let config = UISwipeActionsConfiguration(actions: actions) + config.performsFirstActionWithFullSwipe = false + + return config + } + + config.leadingSwipeActionsConfigurationProvider = { [unowned self] indexPath in + guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil } + var actions = [UIContextualAction]() + + guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil } + guard !article.status.read || article.isAvailableToMarkUnread else { return nil } + + // Set up the read action + let readTitle = article.status.read ? + NSLocalizedString("Mark as Unread", comment: "Mark as Unread") : + NSLocalizedString("Mark as Read", comment: "Mark as Read") + + let readAction = UIContextualAction(style: .normal, title: readTitle) { [weak self] _, _, completion in + self?.toggleRead(article) + completion(true) + } + + 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 = false + return config + } + + + let layout = UICollectionViewCompositionalLayout.list(using: config) + collectionView.setCollectionViewLayout(layout, animated: false) + collectionView.refreshControl = UIRefreshControl() + collectionView.refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged) + + if config.appearance == .sidebar { + // This defrosts the glass. + collectionView.backgroundColor = .clear + } + } + + private func makeDataSource() -> UICollectionViewDiffableDataSource { + let dataSource: UICollectionViewDiffableDataSource = + MainTimelineCollectionViewDataSource(collectionView: collectionView, cellProvider: { [weak self] collectionView, indexPath, article in + let cellData = self!.configure(article: article) + if self!.showIcons { + if indexPath.row == 0 { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: standardCellIdentifierIconIndex0, for: indexPath) as! MainTimelineCollectionViewCell + cell.cellData = cellData + return cell + } else { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: standardCellIdentifierIcon, for: indexPath) as! MainTimelineCollectionViewCell + cell.cellData = cellData + return cell + } + } else { + if indexPath.row == 0 { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: standardCellIdentifierIndex0, for: indexPath) as! MainTimelineCollectionViewCell + cell.cellData = cellData + return cell + } else { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: standardCellIdentifier, for: indexPath) as! MainTimelineCollectionViewCell + cell.cellData = cellData + return cell + } + } + + }) + + return dataSource + } + + @discardableResult + private func configure(article: Article) -> MainTimelineCellData { + let iconImage = iconImageFor(article) + let showFeedNames = coordinator?.showFeedNames ?? ShowFeedName.none + let showIcon = showIcons && iconImage != nil + 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) + } + + func configureToolbar() { + if traitCollection.userInterfaceIdiom == .phone { + toolbarItems?.insert(.flexibleSpace(), at: 1) + toolbarItems?.insert(navigationItem.searchBarPlacementBarButtonItem, at: 2) + } + } + + func resetUI(resetScroll: Bool) { + let shouldShowFilterButton = coordinator?.shouldShowFilterButton() ?? false + navigationItem.rightBarButtonItem = shouldShowFilterButton ? filterButton : nil + + if isReadArticlesFiltered { + filterButton.style = .prominent + filterButton.tintColor = Assets.Colors.primaryAccent + filterButton.accLabelText = NSLocalizedString("Selected - Filter Read Articles", comment: "Selected - Filter Read Articles") + } else { + filterButton.style = .plain + filterButton.tintColor = nil + filterButton.accLabelText = NSLocalizedString("Filter Read Articles", comment: "Filter Read Articles") + } + + collectionView.selectItem(at: nil, animated: false, scrollPosition: .top) + + 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) + } + } + + updateToolbar() + } + + func updateToolbar() { + markAllAsReadButton?.isEnabled = isTimelineUnreadAvailable + firstUnreadButton.isEnabled = coordinator?.isAnyUnreadAvailable ?? false + + if isRootSplitCollapsed { + if let toolbarItems = toolbarItems, toolbarItems.last != firstUnreadButton { + var items = toolbarItems + items.append(firstUnreadButton) + setToolbarItems(items, animated: false) + } + } else { + if let toolbarItems = toolbarItems, toolbarItems.last == firstUnreadButton { + let items = Array(toolbarItems[0.. Void)? = nil) { + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([0]) + snapshot.appendItems(articles ?? ArticleArray(), toSection: 0) + + dataSource.apply(snapshot, animatingDifferences: animated) { [weak self] in + self?.restoreSelectionIfNecessary(adjustScroll: false) + completion?() + } + } + +} + + + +// MARK: - Notifications API +private extension MainTimelineCollectionViewController { + @objc dynamic func unreadCountDidChange(_ notification: Notification) { + Self.logger.debug("MainTimelineViewController: unreadCountDidChange") + updateUI() + } + + @objc func statusesDidChange(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: statusesDidChange") + + guard isViewLoaded, view.window != nil else { + return + } + guard let articleIDs = note.userInfo?[Account.UserInfoKey.articleIDs] as? Set, !articleIDs.isEmpty else { + return + } + let indexPaths = collectionView.indexPathsForVisibleItems + if indexPaths.count == 0 { return } + + let visibleArticles = indexPaths.compactMap { dataSource.itemIdentifier(for: $0) } + let visibleUpdatedArticles = visibleArticles.filter { articleIDs.contains($0.articleID) } + reconfigureCells(visibleUpdatedArticles) + } + + @objc func feedIconDidBecomeAvailable(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: feedIconDidBecomeAvailable") + + guard isViewLoaded, view.window != nil else { + return + } + guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else { + return + } + + updateIconForVisibleArticles(feed) + } + + @objc func avatarDidBecomeAvailable(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: avatarDidBecomeAvailable") + + guard isViewLoaded, view.window != nil else { + return + } + guard showIcons, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else { + return + } + let indexPaths = collectionView.indexPathsForVisibleItems + + let articlesToReload = indexPaths.compactMap { indexPath -> Article? in + guard let article = dataSource.itemIdentifier(for: indexPath), + let authors = article.authors, + !authors.isEmpty else { + return nil + } + for author in authors { + if author.avatarURL == avatarURL { + return article + } + } + return nil + } + reconfigureCells(articlesToReload) + } + + @objc func faviconDidBecomeAvailable(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: faviconDidBecomeAvailable") + + guard isViewLoaded, view.window != nil else { + return + } + + 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 { + return + } + guard showIcons else { + return + } + let indexPaths = collectionView.indexPathsForVisibleItems + + let articlesToReload = indexPaths.compactMap { indexPath -> Article? in + guard let article = dataSource.itemIdentifier(for: indexPath) else { + return nil + } + if feed == nil || feed == article.feed { + return article + } + return nil + } + reconfigureCells(articlesToReload) + } + + func userDefaultsDidChange() { + Self.logger.debug("MainTimelineViewController: userDefaultsDidChange") + + if self.numberOfTextLines != AppDefaults.shared.timelineNumberOfLines || self.iconSize != AppDefaults.shared.timelineIconSize { + self.numberOfTextLines = AppDefaults.shared.timelineNumberOfLines + self.iconSize = AppDefaults.shared.timelineIconSize + self.reconfigureVisibleCells() + } + self.updateToolbar() + } + + @objc func contentSizeCategoryDidChange(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: contentSizeCategoryDidChange") + reconfigureVisibleCells() + } + + @objc func displayNameDidChange(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: displayNameDidChange") + updateNavigationBarTitle(timelineFeed?.nameForDisplay ?? "") + } + + @objc func willEnterForeground(_ note: Notification) { + Self.logger.debug("MainTimelineViewController: willEnterForeground") + updateUI() + } + + @objc func scrollPositionDidChange() { + Self.logger.debug("MainTimelineViewController: scrollPositionDidChange") + timelineMiddleIndexPath = collectionView.middleVisibleRow() + } + +} + + +extension MainTimelineCollectionViewController: UISearchControllerDelegate { + + func willPresentSearchController(_ searchController: UISearchController) { + coordinator?.beginSearching() + searchController.searchBar.showsScopeBar = true + } + + func willDismissSearchController(_ searchController: UISearchController) { + coordinator?.endSearching() + searchController.searchBar.showsScopeBar = false + updateToolbar() + } + +} + +extension MainTimelineCollectionViewController: UISearchResultsUpdating { + + func updateSearchResults(for searchController: UISearchController) { + let searchScope = SearchScope(rawValue: searchController.searchBar.selectedScopeButtonIndex)! + searchArticles(searchController.searchBar.text!, searchScope) + } + +} + +extension MainTimelineCollectionViewController: UISearchBarDelegate { + func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { + let searchScope = SearchScope(rawValue: selectedScope)! + searchArticles(searchBar.text!, searchScope) + } +} + +// MARK: Article Actions +extension MainTimelineCollectionViewController { + func toggleRead(_ article: Article) { + assert(coordinator != nil) + coordinator?.toggleRead(article) + } + + func toggleArticleReadStatusAction(_ article: Article) -> UIAction? { + guard !article.status.read || article.isAvailableToMarkUnread else { return nil } + + let title = article.status.read ? + NSLocalizedString("Mark as Unread", comment: "Mark as Unread") : + NSLocalizedString("Mark as Read", comment: "Mark as Read") + let image = article.status.read ? Assets.Images.circleClosed : Assets.Images.circleOpen + + let action = UIAction(title: title, image: image) { [weak self] _ in + self?.toggleRead(article) + } + + return action + } + + func toggleStar(_ article: Article) { + assert(coordinator != nil) + coordinator?.toggleStar(article) + } + + func toggleArticleStarStatusAction(_ article: Article) -> UIAction { + + let title = article.status.starred ? + NSLocalizedString("Mark as Unstarred", comment: "Mark as Unstarred") : + NSLocalizedString("Mark as Starred", comment: "Mark as Starred") + let image = article.status.starred ? Assets.Images.starOpen : Assets.Images.starClosed + + let action = UIAction(title: title, image: image) { [weak self] _ in + self?.toggleStar(article) + } + + return action + } + + func markAboveAsRead(_ article: Article) { + assert(coordinator != nil) + coordinator?.markAboveAsRead(article) + } + + func canMarkAboveAsRead(for article: Article) -> Bool { + assert(coordinator != nil) + return coordinator?.canMarkAboveAsRead(for: article) ?? false + } + + func markAboveAsReadAction(_ article: Article, indexPath: IndexPath) -> UIAction? { + guard canMarkAboveAsRead(for: article), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + return nil + } + + let title = NSLocalizedString("Mark Above as Read", comment: "Mark Above as Read") + let image = Assets.Images.markAboveAsRead + let action = UIAction(title: title, image: image) { [weak self] _ in + MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in + self?.markAboveAsRead(article) + } + } + return action + } + + func markBelowAsRead(_ article: Article) { + assert(coordinator != nil) + coordinator?.markBelowAsRead(article) + } + + func canMarkBelowAsRead(for article: Article) -> Bool { + assert(coordinator != nil) + return coordinator?.canMarkBelowAsRead(for: article) ?? false + } + + func markBelowAsReadAction(_ article: Article, indexPath: IndexPath) -> UIAction? { + guard canMarkBelowAsRead(for: article), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + return nil + } + + let title = NSLocalizedString("Mark Below as Read", comment: "Mark Below as Read") + let image = Assets.Images.markBelowAsRead + let action = UIAction(title: title, image: image) { [weak self] _ in + MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in + self?.markBelowAsRead(article) + } + } + return action + } + + func markAboveAsReadAlertAction(_ article: Article, indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { + guard canMarkAboveAsRead(for: article), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + return nil + } + + let title = NSLocalizedString("Mark Above as Read", comment: "Mark Above as Read") + let cancel = { + completion(true) + } + + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in + MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in + self?.markAboveAsRead(article) + completion(true) + } + } + return action + } + + func markBelowAsReadAlertAction(_ article: Article, indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { + guard canMarkBelowAsRead(for: article), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + return nil + } + + let title = NSLocalizedString("Mark Below as Read", comment: "Mark Below as Read") + let cancel = { + completion(true) + } + + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in + MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in + self?.markBelowAsRead(article) + completion(true) + } + } + return action + } + + func timelineFeedIsEqualTo(_ feed: Feed) -> Bool { + assert(coordinator != nil) + return coordinator?.timelineFeedIsEqualTo(feed) ?? false + } + + func discloseFeed(_ feed: Feed, animations: Animations = []) { + assert(coordinator != nil) + coordinator?.discloseFeed(feed, animations: animations) + } + + func discloseFeedAction(_ article: Article) -> UIAction? { + guard let feed = article.feed, + !timelineFeedIsEqualTo(feed) else { return nil } + + let title = NSLocalizedString("Go to Feed", comment: "Go to Feed") + let action = UIAction(title: title, image: Assets.Images.openInSidebar) { [weak self] _ in + self?.discloseFeed(feed, animations: [.scroll, .navigation]) + } + return action + } + + func discloseFeedAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction? { + guard let feed = article.feed, + !timelineFeedIsEqualTo(feed) else { return nil } + + let title = NSLocalizedString("Go to Feed", comment: "Go to Feed") + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in + self?.discloseFeed(feed, animations: [.scroll, .navigation]) + completion(true) + } + return action + } + + func markAllAsRead(_ articles: ArticleArray) { + assert(coordinator != nil) + coordinator?.markAllAsRead(articles) + } + + func markAllInFeedAsReadAction(_ article: Article, indexPath: IndexPath) -> UIAction? { + guard let feed = article.feed else { return nil } + guard let fetchedArticles = try? feed.fetchArticles() else { + return nil + } + + let articles = Array(fetchedArticles) + guard articles.canMarkAllAsRead(), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + return nil + } + + let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command") + let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String + + let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in + MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in + self?.markAllAsRead(articles) + } + } + return action + } + + func markAllInFeedAsReadAlertAction(_ article: Article, indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { + guard let feed = article.feed else { return nil } + guard let fetchedArticles = try? feed.fetchArticles() else { + return nil + } + + let articles = Array(fetchedArticles) + guard articles.canMarkAllAsRead(), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + return nil + } + + let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Mark All as Read in Feed") + let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String + let cancel = { + completion(true) + } + + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in + MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in + self?.markAllAsRead(articles) + completion(true) + } + } + return action + } + + func copyArticleURLAction(_ article: Article) -> UIAction? { + guard let url = article.preferredURL else { return nil } + let title = NSLocalizedString("Copy Article URL", comment: "Copy Article URL") + let action = UIAction(title: title, image: Assets.Images.copy) { _ in + UIPasteboard.general.url = url + } + return action + } + + func copyExternalURLAction(_ article: Article) -> UIAction? { + guard let externalLink = article.externalLink, externalLink != article.preferredLink, let url = URL(string: externalLink) else { return nil } + let title = NSLocalizedString("Copy External URL", comment: "Copy External URL") + let action = UIAction(title: title, image: Assets.Images.copy) { _ in + UIPasteboard.general.url = url + } + return action + } + + func showBrowserForArticle(_ article: Article) { + assert(coordinator != nil) + coordinator?.showBrowserForArticle(article) + } + + func openInBrowserAction(_ article: Article) -> UIAction? { + guard article.preferredURL != nil else { + return nil + } + let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") + let action = UIAction(title: title, image: Assets.Images.safari) { [weak self] _ in + self?.showBrowserForArticle(article) + } + return action + } + + func openInBrowserAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction? { + guard article.preferredURL != nil else { + return nil + } + + let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in + self?.showBrowserForArticle(article) + completion(true) + } + return action + } + + func shareDialogForTableCell(indexPath: IndexPath, url: URL, title: String?) { + let activityViewController = UIActivityViewController(url: url, title: title, applicationActivities: nil) + + guard let cell = collectionView.cellForItem(at: indexPath) else { + return + } + let popoverController = activityViewController.popoverPresentationController + popoverController?.sourceView = cell + popoverController?.sourceRect = CGRect(x: 0, y: 0, width: cell.frame.size.width, height: cell.frame.size.height) + + present(activityViewController, animated: true) + } + + func shareAction(_ article: Article, indexPath: IndexPath) -> UIAction? { + guard let url = article.preferredURL else { return nil } + let title = NSLocalizedString("Share", comment: "Share") + let action = UIAction(title: title, image: Assets.Images.share) { [weak self] _ in + self?.shareDialogForTableCell(indexPath: indexPath, url: url, title: article.title) + } + return action + } + + func shareAlertAction(_ article: Article, indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { + guard let url = article.preferredURL else { return nil } + let title = NSLocalizedString("Share", comment: "Share") + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in + completion(true) + self?.shareDialogForTableCell(indexPath: indexPath, url: url, title: article.title) + } + return action + } +} diff --git a/iOS/MainTimeline/MainTimelineDataSource.swift b/iOS/MainTimeline/MainTimelineDataSource.swift index 9b3925fbe..8374ad5ee 100644 --- a/iOS/MainTimeline/MainTimelineDataSource.swift +++ b/iOS/MainTimeline/MainTimelineDataSource.swift @@ -14,3 +14,12 @@ final class MainTimelineDataSource: U true } } + + +final class MainTimelineCollectionViewDataSource: UICollectionViewDiffableDataSource where SectionIdentifierType: Hashable, ItemIdentifierType: Hashable { + + override func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool { + false + } + +} diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 6224036ee..1429ced18 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -14,10 +14,10 @@ import RSWeb import Account import Articles -let standardCellIdentifier = "MainTimelineCellStandard" -let standardCellIdentifierIndex0 = "MainTimelineCellIndexZero" -let standardCellIdentifierIcon = "MainTimelineCellIcon" -let standardCellIdentifierIconIndex0 = "MainTimelineCellIconIndexZero" +//let standardCellIdentifier = "MainTimelineCellStandard" +//let standardCellIdentifierIndex0 = "MainTimelineCellIndexZero" +//let standardCellIdentifierIcon = "MainTimelineCellIcon" +//let standardCellIdentifierIconIndex0 = "MainTimelineCellIconIndexZero" final class MainTimelineViewController: UITableViewController, UndoableCommandRunner {