2025-07-23 21:58:07 +08:00
|
|
|
|
//
|
|
|
|
|
|
// MainFeedCollectionViewController.swift
|
|
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Stuart Breckenridge on 23/06/2025.
|
|
|
|
|
|
// Copyright © 2025 Ranchero Software. All rights reserved.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2025-09-30 12:07:54 -07:00
|
|
|
|
import os
|
2025-11-19 19:04:35 -08:00
|
|
|
|
import SafariServices
|
|
|
|
|
|
import UniformTypeIdentifiers
|
|
|
|
|
|
import WebKit
|
2025-07-23 21:58:07 +08:00
|
|
|
|
import RSCore
|
|
|
|
|
|
import RSTree
|
|
|
|
|
|
import RSWeb
|
2025-11-19 19:04:35 -08:00
|
|
|
|
import Account
|
|
|
|
|
|
import Articles
|
2025-07-23 21:58:07 +08:00
|
|
|
|
|
|
|
|
|
|
private let reuseIdentifier = "FeedCell"
|
|
|
|
|
|
private let folderIdentifier = "Folder"
|
|
|
|
|
|
private let containerReuseIdentifier = "Container"
|
|
|
|
|
|
|
2025-11-18 19:07:17 -08:00
|
|
|
|
final class MainFeedCollectionViewController: UICollectionViewController, UndoableCommandRunner {
|
2025-11-19 19:43:09 -08:00
|
|
|
|
@IBOutlet var filterButton: UIBarButtonItem!
|
|
|
|
|
|
@IBOutlet var addNewItemButton: UIBarButtonItem! {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
didSet {
|
|
|
|
|
|
if #available(iOS 14, *) {
|
|
|
|
|
|
addNewItemButton.primaryAction = nil
|
|
|
|
|
|
} else {
|
2025-08-15 20:14:28 +08:00
|
|
|
|
addNewItemButton.action = #selector(MainFeedCollectionViewController.add(_:))
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
private let keyboardManager = KeyboardManager(type: .sidebar)
|
|
|
|
|
|
override var keyCommands: [UIKeyCommand]? {
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// 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 }
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return keyboardManager.keyCommands
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
override var canBecomeFirstResponder: Bool {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
var undoableCommands = [UndoableCommand]()
|
|
|
|
|
|
weak var coordinator: SceneCoordinator!
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
/// On iPhone, this property is used to prevent the user from selecting a new feed while the current feed is being deselected.
|
|
|
|
|
|
/// While `isAnimating` is `true`, `shouldSelectItemAt()` will not allow new selection.
|
|
|
|
|
|
/// The value is set to `true` in `viewWillAppear(_:)` if a feed is selected, and reset to `false` in
|
|
|
|
|
|
/// `viewDidAppear(_:)` after a delay to allow the deselection animation to complete.
|
|
|
|
|
|
private var isAnimating: Bool = false
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-18 16:07:38 -08:00
|
|
|
|
var dataSource: UICollectionViewDiffableDataSource<String, FeedNode>!
|
2026-01-18 14:58:27 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
registerForNotifications()
|
|
|
|
|
|
configureCollectionView()
|
2026-01-18 14:58:27 -08:00
|
|
|
|
configureDiffableDataSource()
|
2025-07-23 21:58:07 +08:00
|
|
|
|
collectionView.dragDelegate = self
|
|
|
|
|
|
collectionView.dropDelegate = self
|
|
|
|
|
|
becomeFirstResponder()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
|
|
navigationController?.isToolbarHidden = false
|
|
|
|
|
|
updateUI()
|
|
|
|
|
|
super.viewWillAppear(animated)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if traitCollection.userInterfaceIdiom == .phone {
|
2026-01-17 00:10:33 +08:00
|
|
|
|
self.navigationController?.navigationBar.prefersLargeTitles = true
|
|
|
|
|
|
self.navigationItem.largeTitleDisplayMode = .always
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
|
/// This sizes the navigation bar to large.
|
|
|
|
|
|
self.navigationController?.navigationBar.sizeToFit()
|
|
|
|
|
|
}
|
2026-01-16 10:27:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
/// On iPhone, we want to deselect the feed when the user navigates
|
|
|
|
|
|
/// back to the feeds view. To prevent the user from selecting a new feed while
|
|
|
|
|
|
/// the current feed is being deselected, set `isAnimating` to true.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// `shouldSelectItemAt()` will not allow selection when `isAnimating`
|
|
|
|
|
|
/// is `true.`
|
2026-01-02 17:50:35 -08:00
|
|
|
|
if collectionView.indexPathsForSelectedItems != nil {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
isAnimating = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
|
|
super.viewDidAppear(animated)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
/// On iPhone, once the deselection animation has completed, set `isAnimating`
|
|
|
|
|
|
/// to false and this will allow selection.
|
|
|
|
|
|
if traitCollection.userInterfaceIdiom == .phone {
|
2026-01-02 17:50:35 -08:00
|
|
|
|
if collectionView.indexPathsForSelectedItems != nil {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
coordinator.selectFeed(indexPath: nil, animations: [.select])
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
|
|
|
|
|
|
self.isAnimating = false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func registerForNotifications() {
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, 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)
|
2025-11-02 16:17:42 -08:00
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil)
|
2025-11-03 09:12:49 -08:00
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .feedSettingDidChange, object: nil)
|
|
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
registerForTraitChanges([UITraitPreferredContentSizeCategory.self], target: self, action: #selector(preferredContentSizeCategoryDidChange))
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// MARK: - Collection View Configuration
|
|
|
|
|
|
func configureCollectionView() {
|
|
|
|
|
|
var config = UICollectionLayoutListConfiguration(appearance: traitCollection.userInterfaceIdiom == .pad ? .sidebar : .insetGrouped)
|
|
|
|
|
|
config.separatorConfiguration.color = .tertiarySystemFill
|
|
|
|
|
|
config.headerMode = .supplementary
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
config.trailingSwipeActionsConfigurationProvider = { [unowned self] indexPath in
|
|
|
|
|
|
if indexPath.section == 0 { return UISwipeActionsConfiguration(actions: []) }
|
|
|
|
|
|
var actions = [UIContextualAction]()
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// Set up the delete action
|
|
|
|
|
|
let deleteTitle = NSLocalizedString("Delete", comment: "Delete")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let deleteAction = UIContextualAction(style: .destructive, title: nil) { [weak self] _, _, completion in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.delete(indexPath: indexPath)
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
deleteAction.image = UIImage(systemName: "trash")
|
|
|
|
|
|
deleteAction.accessibilityLabel = deleteTitle
|
|
|
|
|
|
deleteAction.backgroundColor = UIColor.systemRed
|
|
|
|
|
|
actions.append(deleteAction)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// Set up the rename action
|
|
|
|
|
|
let renameTitle = NSLocalizedString("Rename", comment: "Rename")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let renameAction = UIContextualAction(style: .normal, title: nil) { [weak self] _, _, completion in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.rename(indexPath: indexPath)
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
renameAction.backgroundColor = UIColor.systemOrange
|
|
|
|
|
|
renameAction.image = UIImage(systemName: "pencil")
|
|
|
|
|
|
renameAction.accessibilityLabel = renameTitle
|
|
|
|
|
|
actions.append(renameAction)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:32:50 -08:00
|
|
|
|
if let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let moreTitle = NSLocalizedString("More", comment: "More")
|
|
|
|
|
|
let moreAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, completion) in
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let self = self {
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:32:50 -08:00
|
|
|
|
let alert = UIAlertController(title: feed.nameForDisplay, message: nil, preferredStyle: .actionSheet)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
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)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let action = self.getInfoAlertAction(indexPath: indexPath, completion: completion) {
|
|
|
|
|
|
alert.addAction(action)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let action = self.homePageAlertAction(indexPath: indexPath, completion: completion) {
|
|
|
|
|
|
alert.addAction(action)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let action = self.copyFeedPageAlertAction(indexPath: indexPath, completion: completion) {
|
|
|
|
|
|
alert.addAction(action)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let action = self.copyHomePageAlertAction(indexPath: indexPath, completion: completion) {
|
|
|
|
|
|
alert.addAction(action)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let action = self.markAllAsReadAlertAction(indexPath: indexPath, completion: completion) {
|
|
|
|
|
|
alert.addAction(action)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
|
|
alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
self.present(alert, animated: true)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
moreAction.backgroundColor = UIColor.systemGray
|
|
|
|
|
|
moreAction.image = UIImage(systemName: "ellipsis")
|
|
|
|
|
|
moreAction.accessibilityLabel = moreTitle
|
|
|
|
|
|
actions.append(moreAction)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let config = UISwipeActionsConfiguration(actions: actions)
|
|
|
|
|
|
config.performsFirstActionWithFullSwipe = false
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return config
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let layout = UICollectionViewCompositionalLayout.list(using: config)
|
|
|
|
|
|
collectionView.setCollectionViewLayout(layout, animated: false)
|
|
|
|
|
|
collectionView.refreshControl = UIRefreshControl()
|
|
|
|
|
|
collectionView.refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if config.appearance == .sidebar {
|
|
|
|
|
|
// This defrosts the glass.
|
|
|
|
|
|
collectionView.backgroundColor = .clear
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-18 14:58:27 -08:00
|
|
|
|
func configureDiffableDataSource() {
|
|
|
|
|
|
dataSource = UICollectionViewDiffableDataSource<String, FeedNode>(
|
|
|
|
|
|
collectionView: collectionView
|
|
|
|
|
|
) { [weak self] collectionView, indexPath, feedNode -> UICollectionViewCell? in
|
|
|
|
|
|
guard let self else { return nil }
|
|
|
|
|
|
|
|
|
|
|
|
if feedNode.node.representedObject is Folder {
|
|
|
|
|
|
let cell = collectionView.dequeueReusableCell(
|
|
|
|
|
|
withReuseIdentifier: folderIdentifier,
|
|
|
|
|
|
for: indexPath
|
|
|
|
|
|
) as! MainFeedCollectionViewFolderCell
|
|
|
|
|
|
self.configure(cell, feedNode: feedNode)
|
|
|
|
|
|
cell.delegate = self
|
|
|
|
|
|
return cell
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let cell = collectionView.dequeueReusableCell(
|
|
|
|
|
|
withReuseIdentifier: reuseIdentifier,
|
|
|
|
|
|
for: indexPath
|
|
|
|
|
|
) as! MainFeedCollectionViewCell
|
|
|
|
|
|
self.configure(cell, feedNode: feedNode)
|
|
|
|
|
|
return cell
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataSource.supplementaryViewProvider = { [weak self] collectionView, kind, indexPath in
|
|
|
|
|
|
guard let self else { return nil }
|
|
|
|
|
|
guard kind == UICollectionView.elementKindSectionHeader else {
|
|
|
|
|
|
return UICollectionReusableView()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let headerView = collectionView.dequeueReusableSupplementaryView(
|
|
|
|
|
|
ofKind: kind,
|
|
|
|
|
|
withReuseIdentifier: containerReuseIdentifier,
|
|
|
|
|
|
for: indexPath
|
|
|
|
|
|
) as! MainFeedCollectionHeaderReusableView
|
|
|
|
|
|
|
|
|
|
|
|
guard let nameProvider = self.coordinator.rootNode.childAtIndex(indexPath.section)?.representedObject as? DisplayNameProvider else {
|
|
|
|
|
|
return UICollectionReusableView()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
headerView.delegate = self
|
|
|
|
|
|
headerView.headerTitle.text = nameProvider.nameForDisplay
|
|
|
|
|
|
|
|
|
|
|
|
guard let sectionNode = self.coordinator.rootNode.childAtIndex(indexPath.section) else {
|
|
|
|
|
|
return headerView
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let account = sectionNode.representedObject as? Account {
|
|
|
|
|
|
headerView.unreadCount = account.unreadCount
|
|
|
|
|
|
} else {
|
|
|
|
|
|
headerView.unreadCount = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
headerView.tag = indexPath.section
|
|
|
|
|
|
headerView.disclosureExpanded = self.coordinator.isExpanded(sectionNode)
|
|
|
|
|
|
|
|
|
|
|
|
if indexPath.section != 0 {
|
|
|
|
|
|
headerView.addInteraction(UIContextMenuInteraction(delegate: self))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return headerView
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-18 15:43:51 -08:00
|
|
|
|
func applySnapshot(_ snapshot: NSDiffableDataSourceSnapshot<String, FeedNode>, animatingDifferences: Bool, completion: (() -> Void)? = nil) {
|
|
|
|
|
|
dataSource.apply(snapshot, animatingDifferences: animatingDifferences) {
|
|
|
|
|
|
completion?()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@IBAction func settings(_ sender: UIBarButtonItem) {
|
|
|
|
|
|
coordinator.showSettings()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-18 14:58:27 -08:00
|
|
|
|
// MARK: UICollectionViewDelegate
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
|
|
|
becomeFirstResponder()
|
|
|
|
|
|
coordinator.selectFeed(indexPath: indexPath, animations: [.navigation, .select, .scroll])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
if traitCollection.userInterfaceIdiom == .pad { return true }
|
|
|
|
|
|
return !isAnimating
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-01 17:55:12 -08:00
|
|
|
|
override func collectionView(_ collectionView: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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?) {
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
2025-11-02 12:17:44 -08:00
|
|
|
|
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-02 14:51:46 -08:00
|
|
|
|
if sidebarItem is Feed {
|
2025-11-03 09:32:50 -08:00
|
|
|
|
return makeFeedContextMenu(indexPath: indexPath, includeDeleteRename: true)
|
2025-11-02 12:17:44 -08:00
|
|
|
|
} else if sidebarItem is Folder {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return makeFolderContextMenu(indexPath: indexPath)
|
2026-01-02 17:50:35 -08:00
|
|
|
|
} else if sidebarItem is PseudoFeed {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return makePseudoFeedContextMenu(indexPath: indexPath)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// MARK: - Key Commands
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-01 17:55:12 -08:00
|
|
|
|
// MARK: - Keyboard shortcuts
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func collapseAllExceptForGroupItems(_ sender: Any?) {
|
|
|
|
|
|
coordinator.collapseAllFolders()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func collapseSelectedRows(_ sender: Any?) {
|
|
|
|
|
|
if let indexPath = coordinator.currentFeedIndexPath, let node = coordinator.nodeFor(indexPath) {
|
|
|
|
|
|
coordinator.collapse(node)
|
|
|
|
|
|
if let folder = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewFolderCell {
|
|
|
|
|
|
folder.disclosureExpanded = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc override func delete(_ sender: Any?) {
|
|
|
|
|
|
if let indexPath = coordinator.currentFeedIndexPath {
|
|
|
|
|
|
delete(indexPath: indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func expandAll(_ sender: Any?) {
|
|
|
|
|
|
coordinator.expandAllSectionsAndFolders()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func expandSelectedRows(_ sender: Any?) {
|
|
|
|
|
|
if let indexPath = coordinator.currentFeedIndexPath, let node = coordinator.nodeFor(indexPath) {
|
|
|
|
|
|
coordinator.expand(node)
|
|
|
|
|
|
if let folder = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewFolderCell {
|
|
|
|
|
|
folder.disclosureExpanded = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func markAllAsRead(_ sender: Any) {
|
|
|
|
|
|
guard let indexPath = collectionView.indexPathsForSelectedItems?.first, let contentView = collectionView.cellForItem(at: indexPath)?.contentView else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read")
|
|
|
|
|
|
MarkAsReadAlertController.confirm(self, coordinator: coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
|
|
|
|
|
|
self?.coordinator.markAllAsReadInTimeline()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func navigateToTimeline(_ sender: Any?) {
|
|
|
|
|
|
coordinator.navigateToTimeline()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func openInBrowser(_ sender: Any?) {
|
|
|
|
|
|
coordinator.showBrowserForCurrentFeed()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func selectNextDown(_ sender: Any?) {
|
|
|
|
|
|
coordinator.selectNextFeed()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func selectNextUp(_ sender: Any?) {
|
|
|
|
|
|
coordinator.selectPrevFeed()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func showFeedInspector(_ sender: Any?) {
|
|
|
|
|
|
coordinator.showFeedInspector()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - API
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func focus() {
|
|
|
|
|
|
becomeFirstResponder()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func updateUI() {
|
|
|
|
|
|
if coordinator.isReadFeedsFiltered {
|
|
|
|
|
|
setFilterButtonToActive()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setFilterButtonToInactive()
|
|
|
|
|
|
}
|
|
|
|
|
|
addNewItemButton?.isEnabled = !AccountManager.shared.activeAccounts.isEmpty
|
|
|
|
|
|
|
|
|
|
|
|
configureContextMenu()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func updateFeedSelection(animations: Animations) {
|
|
|
|
|
|
if let indexPath = coordinator.currentFeedIndexPath {
|
|
|
|
|
|
collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: animations)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if let indexPath = collectionView.indexPathsForSelectedItems?.first {
|
|
|
|
|
|
if animations.contains(.select) {
|
|
|
|
|
|
collectionView.deselectItem(at: indexPath, animated: true)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
collectionView.deselectItem(at: indexPath, animated: false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func openInAppBrowser() {
|
|
|
|
|
|
if let indexPath = coordinator.currentFeedIndexPath,
|
|
|
|
|
|
let url = coordinator.homePageURLForFeed(indexPath) {
|
|
|
|
|
|
let vc = SFSafariViewController(url: url)
|
|
|
|
|
|
vc.modalPresentationStyle = .overFullScreen
|
|
|
|
|
|
present(vc, animated: true)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func applyToAvailableCells(_ completion: (MainFeedCollectionViewCell, IndexPath) -> Void) {
|
2026-01-04 12:36:41 -08:00
|
|
|
|
for cell in collectionView.visibleCells {
|
|
|
|
|
|
guard let indexPath = collectionView.indexPath(for: cell) else {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let cell = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewCell {
|
|
|
|
|
|
completion(cell, indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-18 14:58:27 -08:00
|
|
|
|
func configureIcon(_ cell: MainFeedCollectionViewCell, sidebarItem: SidebarItem) {
|
|
|
|
|
|
guard let sidebarItemID = sidebarItem.sidebarItemID else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func configureIcon(_ cell: MainFeedCollectionViewFolderCell, sidebarItem: SidebarItem) {
|
|
|
|
|
|
guard let sidebarItemID = sidebarItem.sidebarItemID else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func configureIcon(_ cell: MainFeedCollectionViewCell, _ indexPath: IndexPath) {
|
2025-11-02 12:17:44 -08:00
|
|
|
|
guard let node = coordinator.nodeFor(indexPath), let sidebarItem = node.representedObject as? SidebarItem, let sidebarItemID = sidebarItem.sidebarItemID else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-02 11:48:14 -08:00
|
|
|
|
cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func configureIcon(_ cell: MainFeedCollectionViewFolderCell, _ indexPath: IndexPath) {
|
2025-11-02 12:17:44 -08:00
|
|
|
|
guard let node = coordinator.nodeFor(indexPath), let sidebarItem = node.representedObject as? SidebarItem, let sidebarItemID = sidebarItem.sidebarItemID else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-02 11:48:14 -08:00
|
|
|
|
cell.iconImage = IconImageCache.shared.imageFor(sidebarItemID)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func configureCellsForRepresentedObject(_ representedObject: AnyObject) {
|
2026-01-02 11:42:12 -08:00
|
|
|
|
// applyToCellsForRepresentedObject(representedObject, configure)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func applyToCellsForRepresentedObject(_ representedObject: AnyObject, _ completion: (MainFeedCollectionViewCell, IndexPath) -> Void) {
|
|
|
|
|
|
applyToAvailableCells { (cell, indexPath) in
|
|
|
|
|
|
if let node = coordinator.nodeFor(indexPath),
|
2025-11-02 12:17:44 -08:00
|
|
|
|
let representedSidebarItem = representedObject as? SidebarItem,
|
|
|
|
|
|
let candidateSidebarItem = node.representedObject as? SidebarItem,
|
|
|
|
|
|
representedSidebarItem.sidebarItemID == candidateSidebarItem.sidebarItemID {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
completion(cell, indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func restoreSelectionIfNecessary(adjustScroll: Bool) {
|
|
|
|
|
|
if let indexPath = coordinator.mainFeedIndexPathForCurrentTimeline() {
|
|
|
|
|
|
if adjustScroll {
|
|
|
|
|
|
collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: [])
|
|
|
|
|
|
} else {
|
|
|
|
|
|
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// MARK: - Private
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
/// Configure standard feed cells
|
2026-01-18 14:58:27 -08:00
|
|
|
|
func configure(_ cell: MainFeedCollectionViewCell, feedNode: FeedNode) {
|
|
|
|
|
|
let node = feedNode.node
|
|
|
|
|
|
var indentationLevel = 0
|
|
|
|
|
|
if node.parent?.representedObject is Folder {
|
|
|
|
|
|
indentationLevel = 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let sidebarItem = node.representedObject as? SidebarItem {
|
|
|
|
|
|
cell.feedTitle.text = sidebarItem.nameForDisplay
|
|
|
|
|
|
cell.unreadCount = sidebarItem.unreadCount
|
|
|
|
|
|
cell.indentationLevel = indentationLevel
|
|
|
|
|
|
configureIcon(cell, sidebarItem: sidebarItem)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Configure folders
|
|
|
|
|
|
func configure(_ cell: MainFeedCollectionViewFolderCell, feedNode: FeedNode) {
|
|
|
|
|
|
let node = feedNode.node
|
|
|
|
|
|
|
|
|
|
|
|
if let folder = node.representedObject as? Folder {
|
|
|
|
|
|
cell.folderTitle.text = folder.nameForDisplay
|
|
|
|
|
|
cell.unreadCount = folder.unreadCount
|
|
|
|
|
|
configureIcon(cell, sidebarItem: folder)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let containerID = (node.representedObject as? Container)?.containerID {
|
|
|
|
|
|
cell.setDisclosure(isExpanded: coordinator.isExpanded(containerID), animated: false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func configure(_ cell: MainFeedCollectionViewCell, indexPath: IndexPath) {
|
|
|
|
|
|
guard let node = coordinator.nodeFor(indexPath) else { return }
|
|
|
|
|
|
var indentationLevel = 0
|
2026-01-02 17:50:35 -08:00
|
|
|
|
if node.parent?.representedObject is Folder {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
indentationLevel = 1
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-02 12:17:44 -08:00
|
|
|
|
if let sidebarItem = node.representedObject as? SidebarItem {
|
|
|
|
|
|
cell.feedTitle.text = sidebarItem.nameForDisplay
|
|
|
|
|
|
cell.unreadCount = sidebarItem.unreadCount
|
2025-07-23 21:58:07 +08:00
|
|
|
|
cell.indentationLevel = indentationLevel
|
|
|
|
|
|
configureIcon(cell, indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
/// Configure folders
|
|
|
|
|
|
func configure(_ cell: MainFeedCollectionViewFolderCell, indexPath: IndexPath) {
|
|
|
|
|
|
guard let node = coordinator.nodeFor(indexPath) else { return }
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let folder = node.representedObject as? Folder {
|
|
|
|
|
|
cell.folderTitle.text = folder.nameForDisplay
|
|
|
|
|
|
cell.unreadCount = folder.unreadCount
|
|
|
|
|
|
configureIcon(cell, indexPath)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let containerID = (node.representedObject as? Container)?.containerID {
|
|
|
|
|
|
cell.setDisclosure(isExpanded: coordinator.isExpanded(containerID), animated: false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
private func headerViewForAccount(_ account: Account) -> MainFeedCollectionHeaderReusableView? {
|
|
|
|
|
|
|
|
|
|
|
|
guard let node = coordinator.rootNode.childNodeRepresentingObject(account),
|
|
|
|
|
|
let sectionIndex = coordinator.rootNode.indexOfChild(node) else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
if sectionIndex == 0 { return nil }
|
|
|
|
|
|
|
|
|
|
|
|
return collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: sectionIndex)) as? MainFeedCollectionHeaderReusableView
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
private func reloadAllVisibleCells(completion: (() -> Void)? = nil) {
|
|
|
|
|
|
guard let indexPaths = collectionView.indexPathsForSelectedItems else { return }
|
|
|
|
|
|
collectionView.reloadItems(at: indexPaths)
|
|
|
|
|
|
restoreSelectionIfNecessary(adjustScroll: false)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func setFilterButtonToActive() {
|
2025-11-19 10:38:18 -08:00
|
|
|
|
filterButton.tintColor = Assets.Colors.primaryAccent
|
2025-07-23 21:58:07 +08:00
|
|
|
|
filterButton?.accLabelText = NSLocalizedString("Selected - Filter Read Feeds", comment: "Selected - Filter Read Feeds")
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func setFilterButtonToInactive() {
|
|
|
|
|
|
filterButton.tintColor = nil
|
|
|
|
|
|
filterButton?.accLabelText = NSLocalizedString("Filter Read Feeds", comment: "Filter Read Feeds")
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// MARK: - Notifications
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func preferredContentSizeCategoryDidChange() {
|
|
|
|
|
|
IconImageCache.shared.emptyCache()
|
|
|
|
|
|
reloadAllVisibleCells()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func unreadCountDidChange(_ note: Notification) {
|
|
|
|
|
|
updateUI()
|
|
|
|
|
|
|
|
|
|
|
|
guard let unreadCountProvider = note.object as? UnreadCountProvider else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let account = unreadCountProvider as? Account {
|
|
|
|
|
|
if let headerView = headerViewForAccount(account) {
|
|
|
|
|
|
headerView.unreadCount = account.unreadCount
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-21 13:30:08 +08:00
|
|
|
|
let node: Node? = coordinator.rootNode.descendantNodeRepresentingObject(unreadCountProvider as AnyObject)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
|
|
|
|
|
|
guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { return }
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let cell = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewCell {
|
|
|
|
|
|
cell.unreadCount = unreadCountProvider.unreadCount
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let cell = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewFolderCell {
|
|
|
|
|
|
cell.unreadCount = unreadCountProvider.unreadCount
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:12:49 -08:00
|
|
|
|
@objc func feedSettingDidChange(_ note: Notification) {
|
2025-11-03 09:32:50 -08:00
|
|
|
|
guard let feed = note.object as? Feed, let key = note.userInfo?[Feed.SettingUserInfoKey] as? String else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-03 08:55:25 -08:00
|
|
|
|
if key == Feed.SettingKey.homePageURL || key == Feed.SettingKey.faviconURL {
|
2025-11-03 09:32:50 -08:00
|
|
|
|
configureCellsForRepresentedObject(feed)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func faviconDidBecomeAvailable(_ note: Notification) {
|
|
|
|
|
|
applyToAvailableCells(configureIcon)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-02 16:17:42 -08:00
|
|
|
|
@objc func feedIconDidBecomeAvailable(_ note: Notification) {
|
|
|
|
|
|
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-02 16:17:42 -08:00
|
|
|
|
applyToCellsForRepresentedObject(feed, configureIcon(_:_:))
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// MARK: - Actions
|
2026-01-01 17:55:12 -08:00
|
|
|
|
|
|
|
|
|
|
@objc func configureContextMenu(_: Any? = nil) {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
/*
|
|
|
|
|
|
Context Menu Order:
|
2025-11-02 16:17:42 -08:00
|
|
|
|
1. Add Feed
|
2025-07-23 21:58:07 +08:00
|
|
|
|
2. Add Folder
|
|
|
|
|
|
*/
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
var menuItems: [UIAction] = []
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-02 16:17:42 -08:00
|
|
|
|
let addFeedActionTitle = NSLocalizedString("Add Feed", comment: "Add Feed")
|
2025-11-19 10:38:18 -08:00
|
|
|
|
let addFeedAction = UIAction(title: addFeedActionTitle, image: Assets.Images.plus) { _ in
|
2025-11-03 09:32:50 -08:00
|
|
|
|
self.coordinator.showAddFeed()
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-02 16:17:42 -08:00
|
|
|
|
menuItems.append(addFeedAction)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-02 16:17:42 -08:00
|
|
|
|
let addFolderActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder")
|
2025-11-19 10:38:18 -08:00
|
|
|
|
let addFolderAction = UIAction(title: addFolderActionTitle, image: Assets.Images.folderOutlinePlus) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self.coordinator.showAddFolder()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-02 16:17:42 -08:00
|
|
|
|
menuItems.append(addFolderAction)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let contextMenu = UIMenu(title: NSLocalizedString("Add Item", comment: "Add Item"), image: nil, identifier: nil, options: [], children: menuItems.reversed())
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self.addNewItemButton.menu = contextMenu
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@objc func refreshAccounts(_ sender: Any) {
|
|
|
|
|
|
collectionView.refreshControl?.endRefreshing()
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
// 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))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-08-15 20:14:28 +08:00
|
|
|
|
@IBAction func add(_ sender: UIBarButtonItem) {
|
|
|
|
|
|
let title = NSLocalizedString("Add Item", comment: "Add Item")
|
|
|
|
|
|
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-08-15 20:14:28 +08:00
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
|
|
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:42:00 -08:00
|
|
|
|
let addFeedActionTitle = NSLocalizedString("Add Web Feed", comment: "Add Web Feed")
|
|
|
|
|
|
let addFeedAction = UIAlertAction(title: addFeedActionTitle, style: .default) { _ in
|
2025-11-03 09:32:50 -08:00
|
|
|
|
self.coordinator.showAddFeed()
|
2025-08-15 20:14:28 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:42:00 -08:00
|
|
|
|
let addFolderActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder")
|
|
|
|
|
|
let addFolderAction = UIAlertAction(title: addFolderActionTitle, style: .default) { _ in
|
2025-08-15 20:14:28 +08:00
|
|
|
|
self.coordinator.showAddFolder()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:42:00 -08:00
|
|
|
|
alertController.addAction(addFeedAction)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 09:42:00 -08:00
|
|
|
|
alertController.addAction(addFolderAction)
|
2025-08-15 20:14:28 +08:00
|
|
|
|
alertController.addAction(cancelAction)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-08-15 20:14:28 +08:00
|
|
|
|
alertController.popoverPresentationController?.barButtonItem = sender
|
|
|
|
|
|
|
|
|
|
|
|
present(alertController, animated: true)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
@IBAction func toggleFilter(_ sender: Any) {
|
|
|
|
|
|
coordinator.toggleReadFeedsFilter()
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func toggle(_ headerView: MainFeedCollectionHeaderReusableView) {
|
|
|
|
|
|
guard let sectionNode = coordinator.rootNode.childAtIndex(headerView.tag) else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if coordinator.isExpanded(sectionNode) {
|
|
|
|
|
|
headerView.disclosureExpanded = false
|
|
|
|
|
|
coordinator.collapse(sectionNode)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
headerView.disclosureExpanded = true
|
|
|
|
|
|
coordinator.expand(sectionNode)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension MainFeedCollectionViewController: MainFeedCollectionHeaderReusableViewDelegate {
|
|
|
|
|
|
func mainFeedCollectionHeaderReusableViewDidTapDisclosureIndicator(_ view: MainFeedCollectionHeaderReusableView) {
|
|
|
|
|
|
toggle(view)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension MainFeedCollectionViewController: MainFeedCollectionViewFolderCellDelegate {
|
|
|
|
|
|
func mainFeedCollectionFolderViewCellDisclosureDidToggle(_ sender: MainFeedCollectionViewFolderCell, expanding: Bool) {
|
|
|
|
|
|
if expanding {
|
|
|
|
|
|
expand(sender)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
collapse(sender)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func expand(_ cell: MainFeedCollectionViewFolderCell) {
|
|
|
|
|
|
guard let indexPath = collectionView.indexPath(for: cell), let node = coordinator.nodeFor(indexPath) else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
coordinator.expand(node)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func collapse(_ cell: MainFeedCollectionViewFolderCell) {
|
|
|
|
|
|
guard let indexPath = collectionView.indexPath(for: cell), let node = coordinator.nodeFor(indexPath) else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
coordinator.collapse(node)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension MainFeedCollectionViewController: UIContextMenuInteractionDelegate {
|
|
|
|
|
|
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
|
|
|
|
|
|
|
|
|
|
|
|
guard let sectionIndex = interaction.view?.tag,
|
|
|
|
|
|
let sectionNode = coordinator.rootNode.childAtIndex(sectionIndex),
|
|
|
|
|
|
let account = sectionNode.representedObject as? Account
|
|
|
|
|
|
else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-02 17:50:35 -08:00
|
|
|
|
return UIContextMenuConfiguration(identifier: sectionIndex as NSCopying, previewProvider: nil) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
|
|
|
|
|
|
var menuElements = [UIMenuElement]()
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [self.getAccountInfoAction(account: account)]))
|
|
|
|
|
|
|
|
|
|
|
|
if let markAllAction = self.markAllAsReadAction(account: account, contentView: interaction.view) {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [markAllAction]))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [self.deactivateAccountAction(account: account)]))
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return UIMenu(title: "", children: menuElements)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, previewForHighlightingMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
guard let sectionIndex = configuration.identifier as? Int,
|
|
|
|
|
|
let cell = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: sectionIndex)) as? MainFeedCollectionHeaderReusableView else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return UITargetedPreview(view: cell, parameters: CroppingPreviewParameters(view: cell))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension MainFeedCollectionViewController {
|
2025-11-03 09:32:50 -08:00
|
|
|
|
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
|
2026-01-02 17:50:35 -08:00
|
|
|
|
return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { [ weak self] _ in
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
guard let self = self else { return nil }
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
var menuElements = [UIMenuElement]()
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let inspectorAction = self.getInfoAction(indexPath: indexPath) {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [inspectorAction]))
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if let homePageAction = self.homePageAction(indexPath: indexPath) {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [homePageAction]))
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
var pageActions = [UIAction]()
|
|
|
|
|
|
if let copyFeedPageAction = self.copyFeedPageAction(indexPath: indexPath) {
|
|
|
|
|
|
pageActions.append(copyFeedPageAction)
|
|
|
|
|
|
}
|
|
|
|
|
|
if let copyHomePageAction = self.copyHomePageAction(indexPath: indexPath) {
|
|
|
|
|
|
pageActions.append(copyHomePageAction)
|
|
|
|
|
|
}
|
|
|
|
|
|
if !pageActions.isEmpty {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: pageActions))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let markAllAction = self.markAllAsReadAction(indexPath: indexPath) {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [markAllAction]))
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if includeDeleteRename {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "",
|
|
|
|
|
|
options: .displayInline,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
self.renameAction(indexPath: indexPath),
|
|
|
|
|
|
self.deleteAction(indexPath: indexPath)
|
|
|
|
|
|
]))
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return UIMenu(title: "", children: menuElements)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func makeFolderContextMenu(indexPath: IndexPath) -> UIContextMenuConfiguration {
|
2026-01-02 17:50:35 -08:00
|
|
|
|
return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
|
|
|
|
|
|
guard let self = self else { return nil }
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
var menuElements = [UIMenuElement]()
|
|
|
|
|
|
|
|
|
|
|
|
if let markAllAction = self.markAllAsReadAction(indexPath: indexPath) {
|
|
|
|
|
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [markAllAction]))
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
menuElements.append(UIMenu(title: "",
|
|
|
|
|
|
options: .displayInline,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
self.renameAction(indexPath: indexPath),
|
|
|
|
|
|
self.deleteAction(indexPath: indexPath)
|
|
|
|
|
|
]))
|
|
|
|
|
|
|
|
|
|
|
|
return UIMenu(title: "", children: menuElements)
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func makePseudoFeedContextMenu(indexPath: IndexPath) -> UIContextMenuConfiguration? {
|
|
|
|
|
|
guard let markAllAction = self.markAllAsReadAction(indexPath: indexPath) else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-02 17:50:35 -08:00
|
|
|
|
return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return UIMenu(title: "", children: [markAllAction])
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func homePageAction(indexPath: IndexPath) -> UIAction? {
|
|
|
|
|
|
guard coordinator.homePageURLForFeed(indexPath) != nil else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let title = NSLocalizedString("Open Home Page", comment: "Open Home Page")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.safari) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.coordinator.showBrowserForFeed(indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func homePageAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
|
|
|
|
|
|
guard coordinator.homePageURLForFeed(indexPath) != nil else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let title = NSLocalizedString("Open Home Page", comment: "Open Home Page")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAlertAction(title: title, style: .default) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.coordinator.showBrowserForFeed(indexPath)
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func copyFeedPageAction(indexPath: IndexPath) -> UIAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
|
|
|
|
|
|
let url = URL(string: feed.url) else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let title = NSLocalizedString("Copy Feed URL", comment: "Copy Feed URL")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.copy) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
UIPasteboard.general.url = url
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func copyFeedPageAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
|
|
|
|
|
|
let url = URL(string: feed.url) else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let title = NSLocalizedString("Copy Feed URL", comment: "Copy Feed URL")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAlertAction(title: title, style: .default) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
UIPasteboard.general.url = url
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func copyHomePageAction(indexPath: IndexPath) -> UIAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
|
|
|
|
|
|
let homePageURL = feed.homePageURL,
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let url = URL(string: homePageURL) else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let title = NSLocalizedString("Copy Home Page URL", comment: "Copy Home Page URL")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.copy) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
UIPasteboard.general.url = url
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func copyHomePageAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
|
|
|
|
|
|
let homePageURL = feed.homePageURL,
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let url = URL(string: homePageURL) else {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let title = NSLocalizedString("Copy Home Page URL", comment: "Copy Home Page URL")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAlertAction(title: title, style: .default) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
UIPasteboard.general.url = url
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func markAllAsReadAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
|
|
|
|
|
|
feed.unreadCount > 0,
|
|
|
|
|
|
let articles = try? feed.fetchArticles(), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
|
2025-11-03 09:42:00 -08:00
|
|
|
|
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let cancel = {
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAlertAction(title: title, style: .default) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in
|
|
|
|
|
|
self?.coordinator.markAllAsRead(Array(articles))
|
|
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func deleteAction(indexPath: IndexPath) -> UIAction {
|
|
|
|
|
|
let title = NSLocalizedString("Delete", comment: "Delete")
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.trash, attributes: .destructive) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.delete(indexPath: indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func renameAction(indexPath: IndexPath) -> UIAction {
|
|
|
|
|
|
let title = NSLocalizedString("Rename", comment: "Rename")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.edit) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.rename(indexPath: indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func getInfoAction(indexPath: IndexPath) -> UIAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let title = NSLocalizedString("Get Info", comment: "Get Info")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.info) { [weak self] _ in
|
2025-11-03 09:42:00 -08:00
|
|
|
|
self?.coordinator.showFeedInspector(for: feed)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getAccountInfoAction(account: Account) -> UIAction {
|
|
|
|
|
|
let title = NSLocalizedString("Get Info", comment: "Get Info")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.info) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.coordinator.showAccountInspector(for: account)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func deactivateAccountAction(account: Account) -> UIAction {
|
|
|
|
|
|
let title = NSLocalizedString("Deactivate", comment: "Deactivate")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.deactivate) { _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
account.isActive = false
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getInfoAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
|
2025-11-03 09:42:00 -08:00
|
|
|
|
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let title = NSLocalizedString("Get Info", comment: "Get Info")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAlertAction(title: title, style: .default) { [weak self] _ in
|
2025-11-03 09:42:00 -08:00
|
|
|
|
self?.coordinator.showFeedInspector(for: feed)
|
2025-07-23 21:58:07 +08:00
|
|
|
|
completion(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func markAllAsReadAction(indexPath: IndexPath) -> UIAction? {
|
2025-11-02 12:17:44 -08:00
|
|
|
|
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem,
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView,
|
2025-11-02 12:17:44 -08:00
|
|
|
|
sidebarItem.unreadCount > 0 else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
|
2025-11-02 12:17:44 -08:00
|
|
|
|
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, sidebarItem.nameForDisplay) as String
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
|
2025-11-02 12:17:44 -08:00
|
|
|
|
if let articles = try? sidebarItem.fetchUnreadArticles() {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.coordinator.markAllAsRead(Array(articles))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func markAllAsReadAction(account: Account, contentView: UIView?) -> UIAction? {
|
2026-01-02 17:50:35 -08:00
|
|
|
|
guard account.unreadCount > 0, let contentView else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
|
|
|
|
|
|
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, account.nameForDisplay) as String
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
|
|
|
|
|
|
// If you don't have this delay the screen flashes when it executes this code
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
|
|
if let articles = try? account.fetchArticles(.unread()) {
|
|
|
|
|
|
self?.coordinator.markAllAsRead(Array(articles))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return action
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func rename(indexPath: IndexPath) {
|
2025-11-02 12:17:44 -08:00
|
|
|
|
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return }
|
2025-07-23 21:58:07 +08:00
|
|
|
|
|
|
|
|
|
|
let formatString = NSLocalizedString("Rename “%@”", comment: "Rename feed")
|
2025-11-02 12:17:44 -08:00
|
|
|
|
let title = NSString.localizedStringWithFormat(formatString as NSString, sidebarItem.nameForDisplay) as String
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .alert)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
|
|
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let renameTitle = NSLocalizedString("Rename", comment: "Rename")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let renameAction = UIAlertAction(title: renameTitle, style: .default) { [weak self] _ in
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
guard let name = alertController.textFields?[0].text, !name.isEmpty else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-11-03 10:16:03 -08:00
|
|
|
|
if let feed = sidebarItem as? Feed {
|
|
|
|
|
|
feed.rename(to: name) { result in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
switch result {
|
|
|
|
|
|
case .success:
|
|
|
|
|
|
break
|
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
|
self?.presentError(error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-02 12:17:44 -08:00
|
|
|
|
} else if let folder = sidebarItem as? Folder {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
folder.rename(to: name) { result in
|
|
|
|
|
|
switch result {
|
|
|
|
|
|
case .success:
|
|
|
|
|
|
break
|
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
|
self?.presentError(error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
alertController.addAction(renameAction)
|
|
|
|
|
|
alertController.preferredAction = renameAction
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2026-01-02 17:50:35 -08:00
|
|
|
|
alertController.addTextField { textField in
|
2025-11-02 12:17:44 -08:00
|
|
|
|
textField.text = sidebarItem.nameForDisplay
|
2025-07-23 21:58:07 +08:00
|
|
|
|
textField.placeholder = NSLocalizedString("Name", comment: "Name")
|
2025-11-19 22:14:28 +01:00
|
|
|
|
textField.clearButtonMode = .always
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self.present(alertController, animated: true) {
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func delete(indexPath: IndexPath) {
|
2025-11-02 12:17:44 -08:00
|
|
|
|
guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return }
|
2025-07-23 21:58:07 +08:00
|
|
|
|
|
|
|
|
|
|
let title: String
|
|
|
|
|
|
let message: String
|
2025-11-02 12:17:44 -08:00
|
|
|
|
if sidebarItem is Folder {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
title = NSLocalizedString("Delete Folder", comment: "Delete folder")
|
|
|
|
|
|
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” folder?", comment: "Folder delete text")
|
2025-11-02 12:17:44 -08:00
|
|
|
|
message = NSString.localizedStringWithFormat(localizedInformativeText as NSString, sidebarItem.nameForDisplay) as String
|
2026-01-02 17:50:35 -08:00
|
|
|
|
} else {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
title = NSLocalizedString("Delete Feed", comment: "Delete feed")
|
|
|
|
|
|
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” feed?", comment: "Feed delete text")
|
2025-11-02 12:17:44 -08:00
|
|
|
|
message = NSString.localizedStringWithFormat(localizedInformativeText as NSString, sidebarItem.nameForDisplay) as String
|
2025-07-23 21:58:07 +08:00
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
|
|
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
let deleteTitle = NSLocalizedString("Delete", comment: "Delete")
|
2026-01-02 17:50:35 -08:00
|
|
|
|
let deleteAction = UIAlertAction(title: deleteTitle, style: .destructive) { [weak self] _ in
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self?.performDelete(indexPath: indexPath)
|
|
|
|
|
|
}
|
|
|
|
|
|
alertController.addAction(deleteAction)
|
|
|
|
|
|
alertController.preferredAction = deleteAction
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
self.present(alertController, animated: true)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
func performDelete(indexPath: IndexPath) {
|
|
|
|
|
|
guard let undoManager = undoManager,
|
|
|
|
|
|
let deleteNode = coordinator.nodeFor(indexPath),
|
|
|
|
|
|
let deleteCommand = DeleteCommand(nodesToDelete: [deleteNode], undoManager: undoManager, errorHandler: ErrorHandler.present(self)) else {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let folder = deleteNode.representedObject as? Folder {
|
|
|
|
|
|
ActivityManager.cleanUp(folder)
|
2025-11-02 14:51:46 -08:00
|
|
|
|
} else if let feed = deleteNode.representedObject as? Feed {
|
2025-07-23 21:58:07 +08:00
|
|
|
|
ActivityManager.cleanUp(feed)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
if indexPath == coordinator.currentFeedIndexPath {
|
|
|
|
|
|
coordinator.selectFeed(indexPath: nil)
|
|
|
|
|
|
}
|
2025-11-05 11:22:10 -08:00
|
|
|
|
|
2025-07-23 21:58:07 +08:00
|
|
|
|
pushUndoableCommand(deleteCommand)
|
|
|
|
|
|
deleteCommand.perform()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|