diff --git a/enzevalos_iphone/SendViewController+Invitation.swift b/enzevalos_iphone/SendViewController+Invitation.swift index 6035a99c686f430336879ddc2ec9e089323bead2..257a9690c79e27ad5f36d693041ff22eaff77ef4 100644 --- a/enzevalos_iphone/SendViewController+Invitation.swift +++ b/enzevalos_iphone/SendViewController+Invitation.swift @@ -12,36 +12,25 @@ import UIKit struct InvitationSelection { - var selectedWords = Set<NSRange>() - var showsButton = false + var selectedWords = Set<NSRange>() } // MARK: - SendViewController Extension extension SendViewController { - fileprivate func hideMarkButton() { + @IBAction + fileprivate func encryptSelectedText() { - guard (self.invitationSelection.showsButton == true) else { - return - } - - self.invitationSelection.showsButton = false - self.scrollview.contentOffset.y -= 50 } - fileprivate func showMarkButton() { - - guard (self.invitationSelection.showsButton == false) else { - return - } + @IBAction + fileprivate func decryptSelectedText() { - self.invitationSelection.showsButton = true - self.scrollview.contentOffset.y += 50 } func layoutInvitationButton() { - + } func htmlMessage() -> String? { @@ -55,24 +44,34 @@ extension SendViewController { return String(format: htmlString, self.textView.text, "google.com") } + + fileprivate func removeAllInvitationMarks() { + self.invitationSelection.selectedWords = Set<NSRange>() + } + + fileprivate func menuControllerItems(for textView: UITextView) -> [UIMenuItem]? { + return [ + UIMenuItem(title: "verschlüsseln", action: #selector(self.encryptSelectedText)), + UIMenuItem(title: "entschlüsseln", action: #selector(self.decryptSelectedText)) + ] + } } // MARK: - MarkHandler extension SendViewController { - /// Whenever the marked Text changed, the Buttons for "encrypting" or "decrypting" will change there visibility. /// /// - Parameter textView: that changed it's selected Text - fileprivate func updateMarkedText(for textView: UITextView) { + func updateMarkedText(for textView: UITextView) { - guard (textView.selectedRange.length != 0) else { - self.hideMarkButton() + guard (self.isEligibleForInvitation() == true) else { + self.removeAllInvitationMarks() return } - self.showMarkButton() + UIMenuController.shared.menuItems = self.menuControllerItems(for: textView) } /// Whenever text changes are made, the invitation Selection needs to be updated. @@ -106,6 +105,13 @@ extension SendViewController { fileprivate func unmarkSelectedText(for textView: UITextView) { } + + /// Should return true, if the current recipients are insecure + /// + /// - Returns: True if the current E-Mail is insecure + fileprivate func isEligibleForInvitation() -> Bool { + return (self.toSecure == false) + } } // MARK: - UITextViewDelegate diff --git a/enzevalos_iphone/SendViewController.swift b/enzevalos_iphone/SendViewController.swift index 980d2fa16725f921d2b52b4888fe057d2d032353..096709f525fed82c2d658a3e901677928bec54e2 100644 --- a/enzevalos_iphone/SendViewController.swift +++ b/enzevalos_iphone/SendViewController.swift @@ -46,7 +46,6 @@ class SendViewController: UIViewController { var keyboardY: CGFloat = 0 var keyboardHeight: CGFloat = 0 var UISecurityState = true - var toSecure = true var ccSecure = true var dataDelegate = VENDataDelegate() var mailHandler = AppDelegate.getAppDelegate().mailHandler @@ -60,6 +59,12 @@ class SendViewController: UIViewController { var invitationSelection = InvitationSelection() + var toSecure = true { + didSet { + self.updateMarkedText(for: self.textView) + } + } + override func viewDidLoad() { super.viewDidLoad()