Implemented undo for Timeline actions.

This commit is contained in:
Maurice Parker 2019-04-16 18:08:02 -05:00
parent 41926b4c69
commit 18621000f6

View File

@ -11,7 +11,9 @@ import RSCore
import Account import Account
import Articles import Articles
class MasterTimelineViewController: UITableViewController { class MasterTimelineViewController: UITableViewController, UndoableCommandRunner {
var undoableCommands = [UndoableCommand]()
private var showAvatars = false private var showAvatars = false
private var rowHeightWithFeedName: CGFloat = 0.0 private var rowHeightWithFeedName: CGFloat = 0.0
@ -93,6 +95,10 @@ class MasterTimelineViewController: UITableViewController {
} }
} }
override var canBecomeFirstResponder: Bool {
return true
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -108,6 +114,16 @@ class MasterTimelineViewController: UITableViewController {
} }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
becomeFirstResponder()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
resignFirstResponder()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" { if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow { if let indexPath = tableView.indexPathForSelectedRow {
@ -134,8 +150,14 @@ class MasterTimelineViewController: UITableViewController {
let markTitle = NSLocalizedString("Mark All Read", comment: "Mark All Read") let markTitle = NSLocalizedString("Mark All Read", comment: "Mark All Read")
let markAction = UIAlertAction(title: markTitle, style: .default) { [weak self] (action) in let markAction = UIAlertAction(title: markTitle, style: .default) { [weak self] (action) in
guard let articles = self?.articles else { return }
markArticles(Set(articles), statusKey: .read, flag: true) guard let articles = self?.articles,
let undoManager = self?.undoManager,
let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else {
return
}
self?.runCommand(markReadCommand)
} }
alertController.addAction(markAction) alertController.addAction(markAction)
@ -162,8 +184,12 @@ class MasterTimelineViewController: UITableViewController {
NSLocalizedString("Unstar", comment: "Unstar") : NSLocalizedString("Unstar", comment: "Unstar") :
NSLocalizedString("Star", comment: "Star") NSLocalizedString("Star", comment: "Star")
let starAction = UIContextualAction(style: .normal, title: starTitle) { (action, view, completionHandler) in let starAction = UIContextualAction(style: .normal, title: starTitle) { [weak self] (action, view, completionHandler) in
markArticles(Set([article]), statusKey: .starred, flag: !article.status.starred) guard let undoManager = self?.undoManager,
let markReadCommand = MarkStatusCommand(initialArticles: [article], markingStarred: !article.status.starred, undoManager: undoManager) else {
return
}
self?.runCommand(markReadCommand)
completionHandler(true) completionHandler(true)
} }
@ -175,8 +201,12 @@ class MasterTimelineViewController: UITableViewController {
NSLocalizedString("Unread", comment: "Unread") : NSLocalizedString("Unread", comment: "Unread") :
NSLocalizedString("Read", comment: "Read") NSLocalizedString("Read", comment: "Read")
let readAction = UIContextualAction(style: .normal, title: readTitle) { (action, view, completionHandler) in let readAction = UIContextualAction(style: .normal, title: readTitle) { [weak self] (action, view, completionHandler) in
markArticles(Set([article]), statusKey: .read, flag: !article.status.read) guard let undoManager = self?.undoManager,
let markReadCommand = MarkStatusCommand(initialArticles: [article], markingRead: !article.status.read, undoManager: undoManager) else {
return
}
self?.runCommand(markReadCommand)
completionHandler(true) completionHandler(true)
} }