Add visiblity and formatting icons

This commit is contained in:
Shadowfacts 2019-06-13 12:38:40 -07:00
parent ee848d6284
commit 1997aaf915
Signed by untrusted user: shadowfacts
GPG Key ID: 83FB3304046BADA4
4 changed files with 45 additions and 12 deletions

View File

@ -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)!
}
}

View File

@ -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(_:)))
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

View File

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

View File

@ -21,6 +21,7 @@ extension UIAlertController {
if visibility == currentVisibility {
action.setValue(true, forKey: "checked")
}
action.setValue(visibility.image, forKey: "image")
addAction(action)
}