Add visiblity and formatting icons
This commit is contained in:
parent
ee848d6284
commit
1997aaf915
|
@ -7,6 +7,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
import UIKit
|
||||||
|
|
||||||
extension Status.Visibility {
|
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)!
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ class ComposeViewController: UIViewController {
|
||||||
|
|
||||||
let toolbar = UIToolbar()
|
let toolbar = UIToolbar()
|
||||||
contentWarningBarButtonItem = UIBarButtonItem(title: "CW", style: .plain, target: self, action: #selector(contentWarningButtonPressed))
|
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 = [
|
toolbar.items = [
|
||||||
contentWarningBarButtonItem,
|
contentWarningBarButtonItem,
|
||||||
visibilityBarButtonItem,
|
visibilityBarButtonItem,
|
||||||
|
@ -193,10 +193,16 @@ class ComposeViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
return StatusFormat.allCases.map { (format) in
|
return StatusFormat.allCases.map { (format) in
|
||||||
let (str, attributes) = format.title
|
let item: UIBarButtonItem
|
||||||
let item = UIBarButtonItem(title: str, style: .plain, target: self, action: #selector(formatButtonPressed(_:)))
|
if let image = format.image {
|
||||||
item.setTitleTextAttributes(attributes, for: .normal)
|
item = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(formatButtonPressed(_:)))
|
||||||
item.setTitleTextAttributes(attributes, for: .highlighted)
|
} 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)!
|
item.tag = StatusFormat.allCases.firstIndex(of: format)!
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
@ -279,7 +285,7 @@ class ComposeViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func visibilityChanged() {
|
func visibilityChanged() {
|
||||||
// TODO: update visiblity button image
|
visibilityBarButtonItem.image = visibility.image
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveDraft() {
|
func saveDraft() {
|
||||||
|
@ -349,7 +355,7 @@ class ComposeViewController: UIViewController {
|
||||||
updateHasChanges()
|
updateHasChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func visbilityButtonPressed() {
|
@objc func visibilityButtonPressed() {
|
||||||
let alertController = UIAlertController(currentVisibility: self.visibility) { (visibility) in
|
let alertController = UIAlertController(currentVisibility: self.visibility) { (visibility) in
|
||||||
guard let visibility = visibility else { return }
|
guard let visibility = visibility else { return }
|
||||||
self.visibility = visibility
|
self.visibility = visibility
|
||||||
|
|
|
@ -23,16 +23,26 @@ enum StatusFormat: CaseIterable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var title: (String, [NSAttributedString.Key: Any]) {
|
var image: UIImage? {
|
||||||
|
let name: String
|
||||||
switch self {
|
switch self {
|
||||||
case .italics:
|
case .italics:
|
||||||
return ("I", [.font: UIFont.italicSystemFont(ofSize: 17)])
|
name = "italic"
|
||||||
case .bold:
|
case .bold:
|
||||||
return ("B", [.font: UIFont.boldSystemFont(ofSize: 17)])
|
name = "bold"
|
||||||
case .strikethrough:
|
case .strikethrough:
|
||||||
return ("S", [.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue)])
|
name = "strikethrough"
|
||||||
case .code:
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return UIImage(systemName: name)
|
||||||
|
}
|
||||||
|
|
||||||
|
var title: (String, [NSAttributedString.Key: Any])? {
|
||||||
|
if self == .code {
|
||||||
return ("</>", [.font: UIFont(name: "Menlo", size: 17)!])
|
return ("</>", [.font: UIFont(name: "Menlo", size: 17)!])
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ extension UIAlertController {
|
||||||
if visibility == currentVisibility {
|
if visibility == currentVisibility {
|
||||||
action.setValue(true, forKey: "checked")
|
action.setValue(true, forKey: "checked")
|
||||||
}
|
}
|
||||||
|
action.setValue(visibility.image, forKey: "image")
|
||||||
addAction(action)
|
addAction(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue