From 82d4fe22cff90fabc85a3dd6e82666321088cb04 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 25 Oct 2018 21:54:07 -0400 Subject: [PATCH] Cleanup visibility selection --- Tusker.xcodeproj/project.pbxproj | 8 +-- .../Compose/ComposeViewController.swift | 17 ++---- .../BehaviorTableViewController.swift | 26 ++++++-- .../Preferences/Preferences.storyboard | 48 +-------------- .../VisibilityTableViewController.swift | 60 ------------------- .../UIAlertController+Visibility.swift | 32 ++++++++++ 6 files changed, 64 insertions(+), 127 deletions(-) delete mode 100644 Tusker/Screens/Preferences/VisibilityTableViewController.swift create mode 100644 Tusker/Screens/Utilities/UIAlertController+Visibility.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index b6d5f357a0..dedc0782da 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -80,7 +80,6 @@ D641C77B213CB017004B4513 /* FollowNotificationTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D641C77A213CB017004B4513 /* FollowNotificationTableViewCell.xib */; }; D641C77D213CB024004B4513 /* FollowNotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D641C77C213CB024004B4513 /* FollowNotificationTableViewCell.swift */; }; D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */; }; - D641C78F213DF2AA004B4513 /* VisibilityTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */; }; D6434EB3215B1856001A919A /* XCBRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6434EB2215B1856001A919A /* XCBRequest.swift */; }; D646C956213B365700269FB5 /* LargeImageExpandAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C955213B365700269FB5 /* LargeImageExpandAnimationController.swift */; }; D646C958213B367000269FB5 /* LargeImageShrinkAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */; }; @@ -115,6 +114,7 @@ D67E051521643C77000E0927 /* Tab.swift in Sources */ = {isa = PBXBuildFile; fileRef = D67E051421643C77000E0927 /* Tab.swift */; }; D6A5FAF1217B7E05003DB2D9 /* ComposeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6A5FAF0217B7E05003DB2D9 /* ComposeViewController.xib */; }; D6A5FAFB217B86CE003DB2D9 /* OnboardingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6A5FAFA217B86CE003DB2D9 /* OnboardingViewController.xib */; }; + D6B8DB342182A59300424AF7 /* UIAlertController+Visibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B8DB332182A59300424AF7 /* UIAlertController+Visibility.swift */; }; D6BED170212663DA00F02DA0 /* SwiftSoup.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BED173212667E900F02DA0 /* StatusTableViewCell.swift */; }; D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */; }; @@ -274,7 +274,6 @@ D641C77A213CB017004B4513 /* FollowNotificationTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FollowNotificationTableViewCell.xib; sourceTree = ""; }; D641C77C213CB024004B4513 /* FollowNotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowNotificationTableViewCell.swift; sourceTree = ""; }; D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineTextAttachment.swift; sourceTree = ""; }; - D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibilityTableViewController.swift; sourceTree = ""; }; D6434EB2215B1856001A919A /* XCBRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBRequest.swift; sourceTree = ""; }; D646C955213B365700269FB5 /* LargeImageExpandAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageExpandAnimationController.swift; sourceTree = ""; }; D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageShrinkAnimationController.swift; sourceTree = ""; }; @@ -308,6 +307,7 @@ D67E051421643C77000E0927 /* Tab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tab.swift; sourceTree = ""; }; D6A5FAF0217B7E05003DB2D9 /* ComposeViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ComposeViewController.xib; sourceTree = ""; }; D6A5FAFA217B86CE003DB2D9 /* OnboardingViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = OnboardingViewController.xib; sourceTree = ""; }; + D6B8DB332182A59300424AF7 /* UIAlertController+Visibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Visibility.swift"; sourceTree = ""; }; D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftSoup.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D6BED173212667E900F02DA0 /* StatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusTableViewCell.swift; sourceTree = ""; }; D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionsTableViewController.swift; sourceTree = ""; }; @@ -608,7 +608,6 @@ D67E0512216438A7000E0927 /* AppearanceTableViewController.swift */, D621544721682A9D0003D87D /* TabsTableViewController.swift */, D627FF80217FE8F400CC0648 /* BehaviorTableViewController.swift */, - D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */, D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */, ); path = Preferences; @@ -733,6 +732,7 @@ D6C693FD2162FEEA007D6A6D /* UIViewController+Children.swift */, D6E0DC8D216EDF1E00369478 /* Previewing.swift */, D6538944214D6D7500E3CEFC /* TableViewSwipeActionProvider.swift */, + D6B8DB332182A59300424AF7 /* UIAlertController+Visibility.swift */, ); path = Utilities; sourceTree = ""; @@ -1164,12 +1164,12 @@ D663626221360B1900C9CBA2 /* Preferences.swift in Sources */, D6333B792139AEFD00CE884A /* Date+TimeAgo.swift in Sources */, D621544821682A9D0003D87D /* TabsTableViewController.swift in Sources */, - D641C78F213DF2AA004B4513 /* VisibilityTableViewController.swift in Sources */, D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */, 04496BD721625361001F1B23 /* ContentLabel.swift in Sources */, D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */, D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */, D6333B372137838300CE884A /* AttributedString+Trim.swift in Sources */, + D6B8DB342182A59300424AF7 /* UIAlertController+Visibility.swift in Sources */, D641C777213CAA9E004B4513 /* ActionNotificationTableViewCell.swift in Sources */, D627FF74217BBC9700CC0648 /* AppRouter.swift in Sources */, D6C693FE2162FEEA007D6A6D /* UIViewController+Children.swift in Sources */, diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index af55d02ccb..1fefe8a4b9 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -186,20 +186,13 @@ class ComposeViewController: UIViewController { // MARK: - Interaction @IBAction func visibilityPressed(_ sender: Any) { - let alertController = UIAlertController(title: "Post Visibility", message: nil, preferredStyle: .actionSheet) - for visibility in Status.Visibility.allCases { - let action = UIAlertAction(title: visibility.displayName, style: .default, handler: { _ in - UIView.performWithoutAnimation { - self.visibility = visibility - self.visibilityButton.layoutIfNeeded() - } - }) - if visibility == self.visibility { - action.setValue(true, forKey: "checked") + let alertController = UIAlertController(currentVisibility: self.visibility) { (visibility) in + guard let visibility = visibility else { return } + UIView.performWithoutAnimation { + self.visibility = visibility + self.visibilityButton.layoutIfNeeded() } - alertController.addAction(action) } - alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) present(alertController, animated: true) } diff --git a/Tusker/Screens/Preferences/BehaviorTableViewController.swift b/Tusker/Screens/Preferences/BehaviorTableViewController.swift index 13e228ce08..a30ec27afa 100644 --- a/Tusker/Screens/Preferences/BehaviorTableViewController.swift +++ b/Tusker/Screens/Preferences/BehaviorTableViewController.swift @@ -16,17 +16,31 @@ class BehaviorTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() - automaticallySaveDraftsSwitch.setOn(Preferences.shared.automaticallySaveDrafts, animated: false) - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - defaultPostVisibilityLabel.text = Preferences.shared.defaultPostVisibility.displayName + automaticallySaveDraftsSwitch.setOn(Preferences.shared.automaticallySaveDrafts, animated: false) } @IBAction func automaticallySaveDraftsChanged(_ sender: Any) { Preferences.shared.automaticallySaveDrafts = automaticallySaveDraftsSwitch.isOn } + override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { + if indexPath.row == 0 { + return indexPath + } else { + return nil + } + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + + let alertController = UIAlertController(currentVisibility: Preferences.shared.defaultPostVisibility) { (visibility) in + guard let visibility = visibility else { return } + Preferences.shared.defaultPostVisibility = visibility + self.defaultPostVisibilityLabel.text = visibility.displayName + } + present(alertController, animated: true) + } + } diff --git a/Tusker/Screens/Preferences/Preferences.storyboard b/Tusker/Screens/Preferences/Preferences.storyboard index 7aeced17cf..1f3a33ba25 100644 --- a/Tusker/Screens/Preferences/Preferences.storyboard +++ b/Tusker/Screens/Preferences/Preferences.storyboard @@ -252,11 +252,11 @@ - + - + - - - @@ -348,45 +345,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tusker/Screens/Preferences/VisibilityTableViewController.swift b/Tusker/Screens/Preferences/VisibilityTableViewController.swift deleted file mode 100644 index d76c0de696..0000000000 --- a/Tusker/Screens/Preferences/VisibilityTableViewController.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// VisibilityTableViewController.swift -// Tusker -// -// Created by Shadowfacts on 9/3/18. -// Copyright © 2018 Shadowfacts. All rights reserved. -// - -import UIKit -import Pachyderm - -class VisibilityTableViewController: UITableViewController { - - // todo: description of visibility types - - override func viewDidLoad() { - super.viewDidLoad() - } - - // MARK: - Table view data source - - override func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return Status.Visibility.allCases.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let visibility = Status.Visibility.allCases[indexPath.row] - - let cell = tableView.dequeueReusableCell(withIdentifier: "visibilityCell", for: indexPath) - cell.textLabel!.text = visibility.displayName - cell.accessoryType = visibility == Preferences.shared.defaultPostVisibility ? .checkmark : .none - return cell - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let oldVisibility = Preferences.shared.defaultPostVisibility - let oldIndexPath = IndexPath(row: Status.Visibility.allCases.firstIndex(of: oldVisibility)!, section: 0) - - let visibility = Status.Visibility.allCases[indexPath.row] - Preferences.shared.defaultPostVisibility = visibility - - tableView.reloadRows(at: [indexPath], with: .automatic) - tableView.reloadRows(at: [oldIndexPath], with: .none) - } - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. - } - */ - -} diff --git a/Tusker/Screens/Utilities/UIAlertController+Visibility.swift b/Tusker/Screens/Utilities/UIAlertController+Visibility.swift new file mode 100644 index 0000000000..6be48450f2 --- /dev/null +++ b/Tusker/Screens/Utilities/UIAlertController+Visibility.swift @@ -0,0 +1,32 @@ +// +// UIAlertController+Visibility.swift +// Tusker +// +// Created by Shadowfacts on 10/25/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit +import Pachyderm + +extension UIAlertController { + + convenience init(currentVisibility: Status.Visibility?, completion: @escaping (Status.Visibility?) -> Void) { + self.init(title: "Post Visibility", message: nil, preferredStyle: .actionSheet) + + for visibility in Status.Visibility.allCases { + let action = UIAlertAction(title: visibility.displayName, style: .default) { (_) in + completion(visibility) + } + if visibility == currentVisibility { + action.setValue(true, forKey: "checked") + } + addAction(action) + } + + addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in + completion(nil) + })) + } + +}