Browse Source

Add scroll to main status on status table view controller fetch

master
Dwayne Harris 6 years ago
parent
commit
ce72962e2e
  1. 6
      elpha-ios/AccountTableViewController.swift
  2. 5
      elpha-ios/AttachmentPageViewController.swift
  3. 4
      elpha-ios/AttachmentViewController.swift
  4. 17
      elpha-ios/Base.lproj/Main.storyboard
  5. 45
      elpha-ios/StatusTableViewController.swift
  6. 6
      elpha-ios/TimelineTableViewController.swift

6
elpha-ios/AccountTableViewController.swift

@ -365,11 +365,7 @@ extension AccountTableViewController: NSFetchedResultsControllerDelegate {
}
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 {

5
elpha-ios/AttachmentPageViewController.swift

@ -31,7 +31,6 @@ class AttachmentPageViewController: UIPageViewController {
}
setViewControllers([controllers[attachmentIndex]], direction: .forward, animated: true, completion: nil)
setNeedsStatusBarAppearanceUpdate()
}
func dismissController() {
@ -43,6 +42,10 @@ class AttachmentPageViewController: UIPageViewController {
return .lightContent
}
override var prefersStatusBarHidden: Bool {
return true
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

4
elpha-ios/AttachmentViewController.swift

@ -46,6 +46,10 @@ class AttachmentViewController: UIViewController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override var prefersStatusBarHidden: Bool {
return true
}
}
extension AttachmentViewController: UIScrollViewDelegate {

17
elpha-ios/Base.lproj/Main.storyboard

@ -1602,7 +1602,12 @@
<rect key="frame" x="0.0" y="640" width="375" height="50"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mux-Se-p9C">
<rect key="frame" x="178.66666666666666" y="14" width="18" height="22"/>
<rect key="frame" x="180.66666666666666" y="16" width="14" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="9Jp-92-zA1"/>
<constraint firstAttribute="width" constant="14" id="PzK-u1-hOo"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<state key="normal" image="Share">
<color key="titleColor" name="Text"/>
</state>
@ -1699,14 +1704,8 @@
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="1F2-ct-Zy0">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
<attributedString key="attributedTitle">
<fragment content="Loading...">
<attributes>
<font key="NSFont" size="13" name=".AppleSystemUIFont"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
</attributedString>
<attributedString key="attributedTitle"/>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</refreshControl>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3LK-Q6-p6V" userLabel="First Responder" sceneMemberID="firstResponder"/>

45
elpha-ios/StatusTableViewController.swift

@ -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

6
elpha-ios/TimelineTableViewController.swift

@ -353,11 +353,7 @@ extension TimelineTableViewController {
}
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, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

Loading…
Cancel
Save