2019-04-15 22:03:05 +02:00
|
|
|
//
|
|
|
|
// MasterTimelineViewController.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/8/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import RSCore
|
|
|
|
import Account
|
|
|
|
import Articles
|
|
|
|
|
2019-04-23 14:26:35 +02:00
|
|
|
class MasterTimelineViewController: ProgressTableViewController, UndoableCommandRunner {
|
2019-04-17 01:08:02 +02:00
|
|
|
|
2019-04-29 12:51:47 +02:00
|
|
|
private static var minAvatarDimension: CGFloat = 20.0
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem!
|
|
|
|
@IBOutlet weak var firstUnreadButton: UIBarButtonItem!
|
2019-04-22 22:31:34 +02:00
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
weak var navState: NavigationStateController?
|
2019-04-21 20:57:23 +02:00
|
|
|
var undoableCommands = [UndoableCommand]()
|
|
|
|
|
2019-04-17 01:08:02 +02:00
|
|
|
override var canBecomeFirstResponder: Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
2019-04-15 22:03:05 +02:00
|
|
|
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(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(articlesReinitialized(_:)), name: .ArticlesReinitialized, object: navState)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(articleDataDidChange(_:)), name: .ArticleDataDidChange, object: navState)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(articlesDidChange(_:)), name: .ArticlesDidChange, object: navState)
|
2019-04-22 23:25:16 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(articleSelectionDidChange(_:)), name: .ArticleSelectionDidChange, object: navState)
|
2019-04-21 20:57:23 +02:00
|
|
|
|
2019-04-18 21:36:22 +02:00
|
|
|
refreshControl = UIRefreshControl()
|
|
|
|
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
|
|
|
|
2019-04-23 01:00:26 +02:00
|
|
|
resetUI()
|
2019-04-22 22:31:34 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 01:08:02 +02:00
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
becomeFirstResponder()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
|
super.viewWillDisappear(animated)
|
|
|
|
resignFirstResponder()
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
|
|
if segue.identifier == "showDetail" {
|
2019-04-22 00:42:26 +02:00
|
|
|
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
|
|
|
|
controller.navState = navState
|
|
|
|
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
|
|
|
|
controller.navigationItem.leftItemsSupplementBackButton = true
|
|
|
|
splitViewController?.toggleMasterView()
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK Actions
|
|
|
|
|
|
|
|
@IBAction func markAllAsRead(_ sender: Any) {
|
|
|
|
|
|
|
|
let title = NSLocalizedString("Mark All Read", comment: "Mark All Read")
|
|
|
|
let message = NSLocalizedString("Mark all articles in this timeline as read?", comment: "Mark all articles")
|
|
|
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
|
|
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel)
|
|
|
|
alertController.addAction(cancelAction)
|
|
|
|
|
|
|
|
let markTitle = NSLocalizedString("Mark All Read", comment: "Mark All Read")
|
|
|
|
let markAction = UIAlertAction(title: markTitle, style: .default) { [weak self] (action) in
|
2019-04-17 01:08:02 +02:00
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
guard let articles = self?.navState?.articles,
|
2019-04-17 01:08:02 +02:00
|
|
|
let undoManager = self?.undoManager,
|
|
|
|
let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self?.runCommand(markReadCommand)
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
alertController.addAction(markAction)
|
|
|
|
|
|
|
|
present(alertController, animated: true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
@IBAction func firstUnread(_ sender: Any) {
|
|
|
|
if let indexPath = navState?.firstUnreadArticleIndexPath {
|
|
|
|
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
|
|
|
|
}
|
2019-04-23 01:00:26 +02:00
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
// MARK: - Table view
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2019-04-22 00:42:26 +02:00
|
|
|
return navState?.articles.count ?? 0
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
guard let article = navState?.articles[indexPath.row] else {
|
|
|
|
return nil
|
|
|
|
}
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
// Set up the read action
|
|
|
|
let readTitle = article.status.read ?
|
|
|
|
NSLocalizedString("Unread", comment: "Unread") :
|
|
|
|
NSLocalizedString("Read", comment: "Read")
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
let readAction = UIContextualAction(style: .normal, title: readTitle) { [weak self] (action, view, completionHandler) in
|
2019-04-17 01:08:02 +02:00
|
|
|
guard let undoManager = self?.undoManager,
|
2019-04-29 13:01:53 +02:00
|
|
|
let markReadCommand = MarkStatusCommand(initialArticles: [article], markingRead: !article.status.read, undoManager: undoManager) else {
|
2019-04-17 01:08:02 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
self?.runCommand(markReadCommand)
|
2019-04-15 22:03:05 +02:00
|
|
|
completionHandler(true)
|
|
|
|
}
|
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
readAction.image = AppAssets.circleClosedImage
|
|
|
|
readAction.backgroundColor = AppAssets.timelineUnreadCircleColor
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
// Set up the star action
|
|
|
|
let starTitle = article.status.starred ?
|
|
|
|
NSLocalizedString("Unstar", comment: "Unstar") :
|
|
|
|
NSLocalizedString("Star", comment: "Star")
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
let starAction = UIContextualAction(style: .normal, title: starTitle) { [weak self] (action, view, completionHandler) in
|
2019-04-17 01:08:02 +02:00
|
|
|
guard let undoManager = self?.undoManager,
|
2019-04-29 13:01:53 +02:00
|
|
|
let markReadCommand = MarkStatusCommand(initialArticles: [article], markingStarred: !article.status.starred, undoManager: undoManager) else {
|
2019-04-17 01:08:02 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
self?.runCommand(markReadCommand)
|
2019-04-15 22:03:05 +02:00
|
|
|
completionHandler(true)
|
|
|
|
}
|
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
starAction.image = AppAssets.starClosedImage
|
|
|
|
starAction.backgroundColor = AppAssets.starColor
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2019-04-29 13:01:53 +02:00
|
|
|
let configuration = UISwipeActionsConfiguration(actions: [readAction, starAction])
|
2019-04-15 22:03:05 +02:00
|
|
|
return configuration
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MasterTimelineTableViewCell
|
2019-04-22 00:42:26 +02:00
|
|
|
|
|
|
|
guard let article = navState?.articles[indexPath.row] else {
|
|
|
|
return cell
|
|
|
|
}
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
configureTimelineCell(cell, article: article)
|
|
|
|
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
2019-04-22 00:42:26 +02:00
|
|
|
navState?.currentArticleIndexPath = indexPath
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Notifications
|
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
@objc dynamic func unreadCountDidChange(_ notification: Notification) {
|
|
|
|
updateUI()
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
@objc func statusesDidChange(_ note: Notification) {
|
|
|
|
|
|
|
|
guard let articles = note.userInfo?[Account.UserInfoKey.articles] as? Set<Article> else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
reloadVisibleCells(for: articles)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func feedIconDidBecomeAvailable(_ note: Notification) {
|
|
|
|
|
|
|
|
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
performBlockAndRestoreSelection {
|
|
|
|
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
guard let article = navState?.articles.articleAtRow(indexPath.row) else {
|
2019-04-15 22:03:05 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if feed == article.feed {
|
|
|
|
tableView.reloadRows(at: [indexPath], with: .none)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func avatarDidBecomeAvailable(_ note: Notification) {
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
guard navState?.showAvatars ?? false, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
|
2019-04-15 22:03:05 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
performBlockAndRestoreSelection {
|
|
|
|
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
guard let article = navState?.articles.articleAtRow(indexPath.row), let authors = article.authors, !authors.isEmpty else {
|
2019-04-15 22:03:05 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for author in authors {
|
|
|
|
if author.avatarURL == avatarURL {
|
|
|
|
tableView.reloadRows(at: [indexPath], with: .none)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func imageDidBecomeAvailable(_ note: Notification) {
|
2019-04-22 00:42:26 +02:00
|
|
|
if navState?.showAvatars ?? false {
|
2019-04-15 22:03:05 +02:00
|
|
|
queueReloadVisableCells()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 20:57:23 +02:00
|
|
|
@objc func articlesReinitialized(_ note: Notification) {
|
2019-04-23 01:00:26 +02:00
|
|
|
resetUI()
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
2019-04-21 20:57:23 +02:00
|
|
|
|
|
|
|
@objc func articleDataDidChange(_ note: Notification) {
|
|
|
|
reloadAllVisibleCells()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func articlesDidChange(_ note: Notification) {
|
2019-04-23 01:03:13 +02:00
|
|
|
performBlockAndRestoreSelection {
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
2019-04-21 20:57:23 +02:00
|
|
|
}
|
|
|
|
|
2019-04-22 23:25:16 +02:00
|
|
|
@objc func articleSelectionDidChange(_ note: Notification) {
|
2019-04-22 00:42:26 +02:00
|
|
|
|
2019-04-22 14:08:54 +02:00
|
|
|
if let indexPath = navState?.currentArticleIndexPath {
|
2019-04-22 00:55:28 +02:00
|
|
|
if tableView.indexPathForSelectedRow != indexPath {
|
|
|
|
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
|
|
|
|
}
|
2019-04-22 00:42:26 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
updateUI()
|
2019-04-23 01:00:26 +02:00
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
// MARK: Reloading
|
|
|
|
|
|
|
|
@objc func reloadAllVisibleCells() {
|
|
|
|
tableView.beginUpdates()
|
|
|
|
performBlockAndRestoreSelection {
|
|
|
|
tableView.reloadRows(at: tableView.indexPathsForVisibleRows!, with: .none)
|
|
|
|
}
|
|
|
|
tableView.endUpdates()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func reloadVisibleCells(for articles: [Article]) {
|
|
|
|
reloadVisibleCells(for: Set(articles.articleIDs()))
|
|
|
|
}
|
|
|
|
|
|
|
|
private func reloadVisibleCells(for articles: Set<Article>) {
|
|
|
|
reloadVisibleCells(for: articles.articleIDs())
|
|
|
|
}
|
|
|
|
|
|
|
|
private func reloadVisibleCells(for articleIDs: Set<String>) {
|
|
|
|
if articleIDs.isEmpty {
|
|
|
|
return
|
|
|
|
}
|
2019-04-22 00:42:26 +02:00
|
|
|
if let indexes = navState?.indexesForArticleIDs(articleIDs) {
|
|
|
|
reloadVisibleCells(for: indexes)
|
|
|
|
}
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private func reloadVisibleCells(for indexes: IndexSet) {
|
|
|
|
performBlockAndRestoreSelection {
|
|
|
|
tableView.indexPathsForVisibleRows?.forEach { indexPath in
|
|
|
|
if indexes.contains(indexPath.row) {
|
|
|
|
tableView.reloadRows(at: [indexPath], with: .none)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Private
|
|
|
|
|
|
|
|
private extension MasterTimelineViewController {
|
2019-04-22 23:25:16 +02:00
|
|
|
|
2019-04-18 21:36:22 +02:00
|
|
|
@objc private func refreshAccounts(_ sender: Any) {
|
|
|
|
AccountManager.shared.refreshAll()
|
2019-04-23 14:26:35 +02:00
|
|
|
refreshControl?.endRefreshing()
|
2019-04-18 21:36:22 +02:00
|
|
|
}
|
2019-04-22 23:25:16 +02:00
|
|
|
|
2019-04-23 01:00:26 +02:00
|
|
|
func resetUI() {
|
2019-04-22 23:25:16 +02:00
|
|
|
|
|
|
|
title = navState?.timelineName
|
2019-04-29 01:53:57 +02:00
|
|
|
navigationController?.title = navState?.timelineName
|
2019-04-22 23:25:16 +02:00
|
|
|
|
|
|
|
if navState?.articles.count ?? 0 > 0 {
|
|
|
|
tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
|
|
|
|
}
|
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
updateUI()
|
2019-04-23 01:00:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-23 11:35:48 +02:00
|
|
|
func updateUI() {
|
|
|
|
markAllAsReadButton.isEnabled = navState?.isTimelineUnreadAvailable ?? false
|
|
|
|
firstUnreadButton.isEnabled = navState?.isTimelineUnreadAvailable ?? false
|
2019-04-22 23:25:16 +02:00
|
|
|
}
|
2019-04-18 21:36:22 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
func configureTimelineCell(_ cell: MasterTimelineTableViewCell, article: Article) {
|
|
|
|
|
2019-04-29 12:51:47 +02:00
|
|
|
let avatar = avatarFor(article)
|
2019-04-15 22:03:05 +02:00
|
|
|
let featuredImage = featuredImageFor(article)
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
let showFeedNames = navState?.showFeedNames ?? false
|
2019-04-29 12:51:47 +02:00
|
|
|
let showAvatar = navState?.showAvatars ?? false && avatar != nil
|
|
|
|
cell.cellData = MasterTimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, avatar: avatar, showAvatar: showAvatar, featuredImage: featuredImage)
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func avatarFor(_ article: Article) -> UIImage? {
|
|
|
|
|
2019-04-22 00:42:26 +02:00
|
|
|
if !(navState?.showAvatars ?? false) {
|
2019-04-15 22:03:05 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if let authors = article.authors {
|
|
|
|
for author in authors {
|
2019-04-29 12:51:47 +02:00
|
|
|
if let image = avatarForAuthor(author), imagePassesQualityAssurance(image) {
|
2019-04-15 22:03:05 +02:00
|
|
|
return image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let feed = article.feed else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-29 12:51:47 +02:00
|
|
|
let feedIconImage = appDelegate.feedIconDownloader.icon(for: feed)
|
|
|
|
if imagePassesQualityAssurance(feedIconImage) {
|
|
|
|
return feedIconImage
|
|
|
|
}
|
|
|
|
|
|
|
|
if let feed = article.feed, let faviconImage = appDelegate.faviconDownloader.favicon(for: feed) {
|
|
|
|
if imagePassesQualityAssurance(faviconImage) {
|
|
|
|
return faviconImage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-29 14:07:57 +02:00
|
|
|
return FaviconGenerator.favicon(feed)
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-29 12:51:47 +02:00
|
|
|
func imagePassesQualityAssurance(_ image: UIImage?) -> Bool {
|
|
|
|
let minDimension = MasterTimelineViewController.minAvatarDimension * RSScreen.mainScreenScale
|
|
|
|
if let image = image, image.size.height >= minDimension, image.size.width >= minDimension {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
func avatarForAuthor(_ author: Author) -> UIImage? {
|
|
|
|
return appDelegate.authorAvatarDownloader.image(for: author)
|
|
|
|
}
|
|
|
|
|
|
|
|
func featuredImageFor(_ article: Article) -> UIImage? {
|
|
|
|
if let url = article.imageURL, let data = appDelegate.imageDownloader.image(for: url) {
|
|
|
|
return RSImage(data: data)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueReloadVisableCells() {
|
|
|
|
CoalescingQueue.standard.add(self, #selector(reloadAllVisibleCells))
|
|
|
|
}
|
|
|
|
|
|
|
|
func performBlockAndRestoreSelection(_ block: (() -> Void)) {
|
|
|
|
let indexPaths = tableView.indexPathsForSelectedRows
|
|
|
|
block()
|
|
|
|
indexPaths?.forEach { [weak self] indexPath in
|
|
|
|
self?.tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|