|
|
@ -14,6 +14,7 @@ import SafariServices |
|
|
|
class StatusTableViewController: AbstractStatusTableViewController, UIGestureRecognizerDelegate { |
|
|
|
public var status: StatusMO? = nil |
|
|
|
var feedbackGenerator: UINotificationFeedbackGenerator? = nil |
|
|
|
var mainStatusIndexPath: IndexPath? = nil |
|
|
|
|
|
|
|
override func viewDidLoad() { |
|
|
|
super.viewDidLoad() |
|
|
@ -21,17 +22,23 @@ class StatusTableViewController: AbstractStatusTableViewController, UIGestureRec |
|
|
|
feedbackGenerator = UINotificationFeedbackGenerator() |
|
|
|
navigationItem.title = "Toot" |
|
|
|
|
|
|
|
refreshControl?.addTarget(self, action: #selector(self.fetch), for: .valueChanged) |
|
|
|
|
|
|
|
initializeFetchedResultsController() |
|
|
|
|
|
|
|
self.fetch() |
|
|
|
} |
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) { |
|
|
|
super.viewDidAppear(animated) |
|
|
|
|
|
|
|
if SettingsManager.automaticallyRefreshTimelines { |
|
|
|
fetchStatuses { error in |
|
|
|
if error != nil { |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
@objc func fetch() { |
|
|
|
fetchStatuses { error in |
|
|
|
if error == nil { |
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { |
|
|
|
if let mainStatusIndexPath = self.mainStatusIndexPath { |
|
|
|
self.tableView.scrollToRow(at: mainStatusIndexPath, at: .top, animated: true) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -192,7 +199,12 @@ class StatusTableViewController: AbstractStatusTableViewController, UIGestureRec |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func updateMainCell(_ cell: MainStatusTableViewCell, withStatus status: StatusMO) { |
|
|
|
func updateMainCell(_ cell: MainStatusTableViewCell, withStatusAt indexPath: IndexPath) { |
|
|
|
guard let status = status else { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
mainStatusIndexPath = indexPath |
|
|
|
cell.avatarImageView.setRoundedCorners() |
|
|
|
|
|
|
|
func updateAccountView(status: StatusMO) { |
|
|
@ -309,7 +321,8 @@ extension StatusTableViewController: NSFetchedResultsControllerDelegate { |
|
|
|
case let cell as StatusTableViewCell: |
|
|
|
updateCell(cell, withStatusAt: indexPath!) |
|
|
|
case let cell as MainStatusTableViewCell: |
|
|
|
updateMainCell(cell, withStatus: anObject as! StatusMO) |
|
|
|
self.status = anObject as? StatusMO |
|
|
|
updateMainCell(cell, withStatusAt: indexPath!) |
|
|
|
default: |
|
|
|
return |
|
|
|
} |
|
|
@ -336,11 +349,7 @@ extension StatusTableViewController { |
|
|
|
} |
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { |
|
|
|
guard let status = fetchedResultsController?.object(at: indexPath) else { |
|
|
|
return UITableView.automaticDimension |
|
|
|
} |
|
|
|
|
|
|
|
if status == self.status { |
|
|
|
guard let status = fetchedResultsController?.object(at: indexPath), status != self.status else { |
|
|
|
return UITableView.automaticDimension |
|
|
|
} |
|
|
|
|
|
|
@ -348,11 +357,7 @@ extension StatusTableViewController { |
|
|
|
} |
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
|
|
|
guard let count = fetchedResultsController?.fetchedObjects?.count else { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
|
|
|
|
return count |
|
|
|
return fetchedResultsController?.fetchedObjects?.count ?? 0 |
|
|
|
} |
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
|
|
@ -365,7 +370,7 @@ extension StatusTableViewController { |
|
|
|
fatalError("Unable to find reusable cell") |
|
|
|
} |
|
|
|
|
|
|
|
updateMainCell(cell, withStatus: status) |
|
|
|
updateMainCell(cell, withStatusAt: indexPath) |
|
|
|
cell.contentTextView.delegate = self |
|
|
|
|
|
|
|
return cell |
|
|
|