Copy content warning on reply

Closes #21
This commit is contained in:
Shadowfacts 2019-06-13 18:12:29 -07:00
parent b478f6e982
commit 2232bb8fb7
Signed by untrusted user: shadowfacts
GPG Key ID: 83FB3304046BADA4
1 changed files with 10 additions and 8 deletions

View File

@ -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(image: Preferences.shared.defaultPostVisibility.image, style: .plain, target: self, action: #selector(visibilityButtonPressed)) visibilityBarButtonItem = UIBarButtonItem(image: nil, style: .plain, target: self, action: #selector(visibilityButtonPressed))
toolbar.items = [ toolbar.items = [
contentWarningBarButtonItem, contentWarningBarButtonItem,
visibilityBarButtonItem, visibilityBarButtonItem,
@ -127,6 +127,9 @@ class ComposeViewController: UIViewController {
if let inReplyToID = inReplyToID, let inReplyTo = MastodonCache.status(for: inReplyToID) { if let inReplyToID = inReplyToID, let inReplyTo = MastodonCache.status(for: inReplyToID) {
visibility = inReplyTo.visibility visibility = inReplyTo.visibility
contentWarningEnabled = !inReplyTo.spoilerText.isEmpty
contentWarningContainerView.isHidden = !contentWarningEnabled
contentWarningTextField.text = inReplyTo.spoilerText
let replyView = ComposeStatusReplyView.create() let replyView = ComposeStatusReplyView.create()
replyView.updateUI(for: inReplyTo) replyView.updateUI(for: inReplyTo)
@ -159,11 +162,11 @@ class ComposeViewController: UIViewController {
updateCharactersRemaining() updateCharactersRemaining()
updatePlaceholder() updatePlaceholder()
contentWarningEnabled = false
NotificationCenter.default.addObserver(self, selector: #selector(contentWarningTextFieldDidChange), name: UITextField.textDidChangeNotification, object: contentWarningTextField) NotificationCenter.default.addObserver(self, selector: #selector(contentWarningTextFieldDidChange), name: UITextField.textDidChangeNotification, object: contentWarningTextField)
if inReplyToID == nil { if inReplyToID == nil {
visibility = Preferences.shared.defaultPostVisibility visibility = Preferences.shared.defaultPostVisibility
contentWarningEnabled = false
} }
} }
@ -288,12 +291,6 @@ class ComposeViewController: UIViewController {
func contentWarningStateChanged() { func contentWarningStateChanged() {
contentWarningContainerView.isHidden = !contentWarningEnabled contentWarningContainerView.isHidden = !contentWarningEnabled
contentWarningBarButtonItem.style = contentWarningEnabled ? .done : .plain
if contentWarningEnabled {
contentWarningTextField.becomeFirstResponder()
} else {
statusTextView.becomeFirstResponder()
}
} }
func visibilityChanged() { func visibilityChanged() {
@ -360,6 +357,11 @@ class ComposeViewController: UIViewController {
@objc func contentWarningButtonPressed() { @objc func contentWarningButtonPressed() {
contentWarningEnabled = !contentWarningEnabled contentWarningEnabled = !contentWarningEnabled
if contentWarningEnabled {
contentWarningTextField.becomeFirstResponder()
} else {
statusTextView.becomeFirstResponder()
}
} }
@objc func contentWarningTextFieldDidChange() { @objc func contentWarningTextFieldDidChange() {