diff --git a/Tusker/Extensions/Visibility+Helpers.swift b/Tusker/Extensions/Visibility+Helpers.swift index bde6b28a18..b69dbad38e 100644 --- a/Tusker/Extensions/Visibility+Helpers.swift +++ b/Tusker/Extensions/Visibility+Helpers.swift @@ -7,6 +7,7 @@ // import Pachyderm +import UIKit extension Status.Visibility { @@ -23,4 +24,19 @@ extension Status.Visibility { } } + var image: UIImage { + let name: String + switch self { + case .public: + name = "globe" + case .unlisted: + name = "lock.open.fill" + case .private: + name = "lock.fill" + case .direct: + name = "envelope.fill" + } + return UIImage(systemName: name)! + } + } diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 49aadcbeed..bc75ff54a6 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -103,7 +103,7 @@ class ComposeViewController: UIViewController { let toolbar = UIToolbar() contentWarningBarButtonItem = UIBarButtonItem(title: "CW", style: .plain, target: self, action: #selector(contentWarningButtonPressed)) - visibilityBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(visbilityButtonPressed)) + visibilityBarButtonItem = UIBarButtonItem(image: Preferences.shared.defaultPostVisibility.image, style: .plain, target: self, action: #selector(visibilityButtonPressed)) toolbar.items = [ contentWarningBarButtonItem, visibilityBarButtonItem, @@ -193,10 +193,16 @@ class ComposeViewController: UIViewController { } return StatusFormat.allCases.map { (format) in - let (str, attributes) = format.title - let item = UIBarButtonItem(title: str, style: .plain, target: self, action: #selector(formatButtonPressed(_:))) - item.setTitleTextAttributes(attributes, for: .normal) - item.setTitleTextAttributes(attributes, for: .highlighted) + let item: UIBarButtonItem + if let image = format.image { + item = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(formatButtonPressed(_:))) + } else if let (str, attributes) = format.title { + item = UIBarButtonItem(title: str, style: .plain, target: self, action: #selector(formatButtonPressed(_:))) + item.setTitleTextAttributes(attributes, for: .normal) + item.setTitleTextAttributes(attributes, for: .highlighted) + } else { + fatalError("StatusFormat must have either an image or a title") + } item.tag = StatusFormat.allCases.firstIndex(of: format)! return item } @@ -279,7 +285,7 @@ class ComposeViewController: UIViewController { } func visibilityChanged() { - // TODO: update visiblity button image + visibilityBarButtonItem.image = visibility.image } func saveDraft() { @@ -349,7 +355,7 @@ class ComposeViewController: UIViewController { updateHasChanges() } - @objc func visbilityButtonPressed() { + @objc func visibilityButtonPressed() { let alertController = UIAlertController(currentVisibility: self.visibility) { (visibility) in guard let visibility = visibility else { return } self.visibility = visibility diff --git a/Tusker/Screens/Compose/StatusFormat.swift b/Tusker/Screens/Compose/StatusFormat.swift index 85c9ac598a..002a5fc5a9 100644 --- a/Tusker/Screens/Compose/StatusFormat.swift +++ b/Tusker/Screens/Compose/StatusFormat.swift @@ -23,16 +23,26 @@ enum StatusFormat: CaseIterable { } } - var title: (String, [NSAttributedString.Key: Any]) { + var image: UIImage? { + let name: String switch self { case .italics: - return ("I", [.font: UIFont.italicSystemFont(ofSize: 17)]) + name = "italic" case .bold: - return ("B", [.font: UIFont.boldSystemFont(ofSize: 17)]) + name = "bold" case .strikethrough: - return ("S", [.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue)]) - case .code: + name = "strikethrough" + default: + return nil + } + return UIImage(systemName: name) + } + + var title: (String, [NSAttributedString.Key: Any])? { + if self == .code { return ("", [.font: UIFont(name: "Menlo", size: 17)!]) + } else { + return nil } } } diff --git a/Tusker/Screens/Utilities/UIAlertController+Visibility.swift b/Tusker/Screens/Utilities/UIAlertController+Visibility.swift index 6be48450f2..41f5bc920e 100644 --- a/Tusker/Screens/Utilities/UIAlertController+Visibility.swift +++ b/Tusker/Screens/Utilities/UIAlertController+Visibility.swift @@ -21,6 +21,7 @@ extension UIAlertController { if visibility == currentVisibility { action.setValue(true, forKey: "checked") } + action.setValue(visibility.image, forKey: "image") addAction(action) }