2020-02-23 19:57:20 +01:00
|
|
|
//
|
|
|
|
// UpdateSelectionOperation.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 2/22/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import RSCore
|
|
|
|
|
|
|
|
class UpdateSelectionOperation: MainThreadOperation {
|
|
|
|
|
|
|
|
// MainThreadOperation
|
|
|
|
public var isCanceled = false
|
|
|
|
public var id: Int?
|
|
|
|
public weak var operationDelegate: MainThreadOperationDelegate?
|
|
|
|
public var name: String? = "UpdateSelectionOperation"
|
|
|
|
public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock?
|
|
|
|
|
|
|
|
private var coordinator: SceneCoordinator
|
|
|
|
private var dataSource: MasterFeedDataSource
|
|
|
|
private var tableView: UITableView
|
|
|
|
private var animations: Animations
|
|
|
|
|
|
|
|
init(coordinator: SceneCoordinator, dataSource: MasterFeedDataSource, tableView: UITableView, animations: Animations) {
|
|
|
|
self.coordinator = coordinator
|
|
|
|
self.dataSource = dataSource
|
|
|
|
self.tableView = tableView
|
|
|
|
self.animations = animations
|
|
|
|
}
|
|
|
|
|
|
|
|
func run() {
|
|
|
|
if dataSource.snapshot().numberOfItems > 0 {
|
|
|
|
if let indexPath = coordinator.currentFeedIndexPath {
|
|
|
|
CATransaction.begin()
|
|
|
|
CATransaction.setCompletionBlock {
|
|
|
|
self.operationDelegate?.operationDidComplete(self)
|
|
|
|
}
|
|
|
|
tableView.selectRowAndScrollIfNotVisible(at: indexPath, animations: animations)
|
|
|
|
CATransaction.commit()
|
|
|
|
} else {
|
2020-10-23 02:48:09 +02:00
|
|
|
if let indexPath = tableView.indexPathForSelectedRow {
|
|
|
|
if animations.contains(.select) {
|
|
|
|
CATransaction.begin()
|
|
|
|
CATransaction.setCompletionBlock {
|
|
|
|
self.operationDelegate?.operationDidComplete(self)
|
|
|
|
}
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
CATransaction.commit()
|
|
|
|
} else {
|
|
|
|
tableView.deselectRow(at: indexPath, animated: false)
|
2020-02-24 17:07:14 +01:00
|
|
|
self.operationDelegate?.operationDidComplete(self)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self.operationDelegate?.operationDidComplete(self)
|
|
|
|
}
|
2020-02-23 19:57:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self.operationDelegate?.operationDidComplete(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|