diff --git a/enzevalos_iphone.xcodeproj/project.pbxproj b/enzevalos_iphone.xcodeproj/project.pbxproj index 069345f277c54c98b6f50a0749fd3044c0dd8fe0..e334266ac9aa526b68fe83d40733303900f5e2c5 100644 --- a/enzevalos_iphone.xcodeproj/project.pbxproj +++ b/enzevalos_iphone.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 472F398E1E251B8D009260FB /* MailAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 472F398D1E251B8D009260FB /* MailAddress.swift */; }; 472F39901E252470009260FB /* CNMailAddressesExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 472F398F1E252470009260FB /* CNMailAddressesExtension.swift */; }; 474054982244D7A9007CF83B /* MailServerConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474054972244D7A9007CF83B /* MailServerConfigurationTest.swift */; }; + 474994022261E4E6000F8DA5 /* SimpleSendIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474994012261E4E6000F8DA5 /* SimpleSendIcon.swift */; }; 4756DE0E20402F8E00452288 /* invitationTextCensor.html in Resources */ = {isa = PBXBuildFile; fileRef = 4756DE0D20402F8E00452288 /* invitationTextCensor.html */; }; 475B00331F7B9565006CDD41 /* SwiftPGP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475B00301F7B9565006CDD41 /* SwiftPGP.swift */; }; 475B00341F7B9565006CDD41 /* Cryptography.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475B00311F7B9565006CDD41 /* Cryptography.swift */; }; @@ -178,7 +179,7 @@ F12041FD1DA409A5002E4940 /* ListViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12041FC1DA409A5002E4940 /* ListViewCell.swift */; }; F12060801DA540FE00F6EF37 /* RefreshControlExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F120607F1DA540FE00F6EF37 /* RefreshControlExtension.swift */; }; F12060821DA552FC00F6EF37 /* MailHandlerDelegator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12060811DA552FC00F6EF37 /* MailHandlerDelegator.swift */; }; - F120A7D31F7937BB006D5BF1 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + F120A7D31F7937BB006D5BF1 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; F12D8DBB2069422A0068788E /* About.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F12D8DBD2069422A0068788E /* About.storyboard */; }; F14239C11F30A99C00998A83 /* QRCodeGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F14239C01F30A99C00998A83 /* QRCodeGenerator.swift */; }; F1737ACB2031D7D70000312B /* StudySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17FDFF2202C685800F7BA89 /* StudySettings.swift */; }; @@ -262,6 +263,7 @@ 472F398D1E251B8D009260FB /* MailAddress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MailAddress.swift; sourceTree = "<group>"; }; 472F398F1E252470009260FB /* CNMailAddressesExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNMailAddressesExtension.swift; sourceTree = "<group>"; }; 474054972244D7A9007CF83B /* MailServerConfigurationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailServerConfigurationTest.swift; sourceTree = "<group>"; }; + 474994012261E4E6000F8DA5 /* SimpleSendIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleSendIcon.swift; sourceTree = "<group>"; }; 4756DE0D20402F8E00452288 /* invitationTextCensor.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = invitationTextCensor.html; path = Invitation/invitationTextCensor.html; sourceTree = "<group>"; }; 475B00301F7B9565006CDD41 /* SwiftPGP.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftPGP.swift; sourceTree = "<group>"; }; 475B00311F7B9565006CDD41 /* Cryptography.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cryptography.swift; sourceTree = "<group>"; }; @@ -455,7 +457,7 @@ 47F867E42052B49800AA832F /* libbz2.tbd in Frameworks */, 47F867E22052B48E00AA832F /* libz.tbd in Frameworks */, 47F867E02052B47C00AA832F /* Security.framework in Frameworks */, - F120A7D31F7937BB006D5BF1 /* BuildFile in Frameworks */, + F120A7D31F7937BB006D5BF1 /* (null) in Frameworks */, 472F396E1E14F384009260FB /* CoreData.framework in Frameworks */, 9935BC866A86C4A4B9819F35 /* Pods_enzevalos_iphone.framework in Frameworks */, ); @@ -950,6 +952,7 @@ children = ( A1EB057F1D956851008659C1 /* SendViewController.swift */, F119D28F1E364B59001D732A /* AnimatedSendIcon.swift */, + 474994012261E4E6000F8DA5 /* SimpleSendIcon.swift */, A1EB057D1D956848008659C1 /* VENDataDelegate.swift */, A1EB05811D95685B008659C1 /* CollectionDataDelegate.swift */, A1EB05831D956867008659C1 /* TableViewDataDelegate.swift */, @@ -1442,6 +1445,7 @@ 472F398E1E251B8D009260FB /* MailAddress.swift in Sources */, A198D2292056B384004CC838 /* SendViewDelegate.swift in Sources */, F12060821DA552FC00F6EF37 /* MailHandlerDelegator.swift in Sources */, + 474994022261E4E6000F8DA5 /* SimpleSendIcon.swift in Sources */, A12F91D821F3A99800AB0589 /* NSLayoutConstraintExtension.swift in Sources */, A18E7D771FBDE5D9002F7CC9 /* LoggingEventType.swift in Sources */, F1984D741E1E92B300804E1E /* LabelStyleKit.swift in Sources */, diff --git a/enzevalos_iphone/AnimatedSendIcon.swift b/enzevalos_iphone/AnimatedSendIcon.swift index 79a93830e4eccd4a59a7c43adb25663c317361ae..196d76bc2940c49d1270665f537073322e1c365a 100644 --- a/enzevalos_iphone/AnimatedSendIcon.swift +++ b/enzevalos_iphone/AnimatedSendIcon.swift @@ -22,7 +22,7 @@ import Foundation import UIKit -class AnimatedSendIcon: UIView { +class AnimatedSendIcon: UIView, SendIcon { var isPostcardOnTop = false var square = UIImageView(image: StudySettings.securityIndicator.imageOfSecureIndicator(background: true, open: false)) var square2 = UIImageView(image: StudySettings.securityIndicator.imageOfInsecureIndicator(background: true)) diff --git a/enzevalos_iphone/IconsStyleKit.swift b/enzevalos_iphone/IconsStyleKit.swift index b8b92a757126e14ab60b7ec21f00ee69f7f098e9..e04466625d767dc82f1433a6fd632aeca3114f50 100644 --- a/enzevalos_iphone/IconsStyleKit.swift +++ b/enzevalos_iphone/IconsStyleKit.swift @@ -19,20 +19,25 @@ internal class IconsStyleKit: NSObject { private struct Cache { static let strokeColor: UIColor = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000) + static let buttonStrokeColor: UIColor = UIView().tintColor static var imageOfLetter: UIImage? static var imageOfLetterBG: UIImage? + static var imageOfLetterButton: UIImage? static var letterTargets: [AnyObject]? static var imageOfLetterCorrupted: UIImage? static var letterCorruptedTargets: [AnyObject]? static var imageOfPostcard: UIImage? + static var imageOfPostcardButton: UIImage? static var imageOfPostcardBG: UIImage? static var postcardTargets: [AnyObject]? static var imageOfLetterOpen: UIImage? static var letterOpenTargets: [AnyObject]? static var imageOfPadlockSecure: UIImage? + static var imageOfPadlockSecureButton: UIImage? static var imageOfPadlockSecureBG: UIImage? static var padlockSecureTargets: [AnyObject]? static var imageOfPadlockInsecure: UIImage? + static var imageOfPadlockInsecureButton: UIImage? static var imageOfPadlockInsecureBG: UIImage? static var padlockInsecureTargets: [AnyObject]? static var imageOfPadlockError: UIImage? @@ -606,9 +611,7 @@ internal class IconsStyleKit: NSObject { @objc dynamic public class func drawPadlockError(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 35, height: 50), resizing: ResizingBehavior = .aspectFit, color: UIColor = strokeColor, fillBackground: Bool = false) { //// General Declarations let context = UIGraphicsGetCurrentContext()! - - //// Resize to Target Frame context.saveGState() let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 35, height: 50), target: targetFrame) @@ -816,6 +819,20 @@ internal class IconsStyleKit: NSObject { return Cache.imageOfLetter! } + + @objc open dynamic class var imageOfLetterButton: UIImage { + if Cache.imageOfLetterButton != nil { + return Cache.imageOfLetterButton! + } + + UIGraphicsBeginImageContextWithOptions(CGSize(width: 50, height: 35), false, 0) + IconsStyleKit.drawLetter(color: IconsStyleKit.Cache.buttonStrokeColor) + + Cache.imageOfLetterButton = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext() + + return Cache.imageOfLetterButton! + } @objc open dynamic class var imageOfLetterBG: UIImage { if Cache.imageOfLetterBG != nil { @@ -858,6 +875,21 @@ internal class IconsStyleKit: NSObject { return Cache.imageOfPostcard! } + + @objc open dynamic class var imageOfPostcardButton: UIImage { + if Cache.imageOfPostcardButton != nil { + return Cache.imageOfPostcardButton! + } + + UIGraphicsBeginImageContextWithOptions(CGSize(width: 49, height: 34), false, 0) + IconsStyleKit.drawPostcard(color: Cache.buttonStrokeColor) + + Cache.imageOfPostcardButton = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext() + + return Cache.imageOfPostcardButton! + } + @objc open dynamic class var imageOfPostcardBG: UIImage { if Cache.imageOfPostcardBG != nil { @@ -901,6 +933,20 @@ internal class IconsStyleKit: NSObject { return Cache.imageOfPadlockSecure! } + @objc dynamic public class var imageOfPadlockSecureButton: UIImage { + if Cache.imageOfPadlockSecureButton != nil { + return Cache.imageOfPadlockSecureButton! + } + + UIGraphicsBeginImageContextWithOptions(CGSize(width: height, height: width), false, 0) + IconsStyleKit.drawPadlockSecure(color: Cache.buttonStrokeColor, fillBackground: false) + + Cache.imageOfPadlockSecureButton = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext() + + return Cache.imageOfPadlockSecureButton! + } + @objc dynamic public class var imageOfPadlockSecureBG: UIImage { if Cache.imageOfPadlockSecureBG != nil { return Cache.imageOfPadlockSecureBG! @@ -929,6 +975,20 @@ internal class IconsStyleKit: NSObject { return Cache.imageOfPadlockInsecure! } + @objc dynamic public class var imageOfPadlockInsecureButton: UIImage { + if Cache.imageOfPadlockInsecureButton != nil { + return Cache.imageOfPadlockInsecureButton! + } + + UIGraphicsBeginImageContextWithOptions(CGSize(width: height, height: width), false, 0) + IconsStyleKit.drawPadlockInsecure(color: Cache.buttonStrokeColor ,fillBackground: false) + + Cache.imageOfPadlockInsecureButton = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext() + + return Cache.imageOfPadlockInsecureButton! + } + @objc dynamic public class var imageOfPadlockInsecureBG: UIImage { if Cache.imageOfPadlockInsecureBG != nil { return Cache.imageOfPadlockInsecureBG! diff --git a/enzevalos_iphone/SendViewController.swift b/enzevalos_iphone/SendViewController.swift index 06ebc37462870f1a0f82eb69d2e3c1fe89236fa6..f0b254576f86068019f75c9eb8bf0ea32409c1de 100644 --- a/enzevalos_iphone/SendViewController.swift +++ b/enzevalos_iphone/SendViewController.swift @@ -50,7 +50,7 @@ class SendViewController: UIViewController { @IBOutlet weak var scrollViewBottom: NSLayoutConstraint! @IBOutlet weak var scrollviewRecognizer: UITapGestureRecognizer! @IBOutlet weak var sendButton: UIBarButtonItem! - + var keyboardOpened = false var keyboardY: CGFloat = 0 var keyboardHeight: CGFloat = 0 @@ -137,8 +137,14 @@ class SendViewController: UIViewController { subjectText.toLabelText = NSLocalizedString("Subject", comment: "subject label") + ": " - let iconView = AnimatedSendIcon() - iconView.frame = iconView.frame.offsetBy(dx: 0, dy: -10) + var iconView: SendIcon & UIView = SimpleSendIcon() + if StudySettings.showBothSecurityIconsInSend { + iconView = AnimatedSendIcon() + iconView.frame = iconView.frame.offsetBy(dx: 0, dy: -10) + } + else { + iconView.frame = iconView.frame.offsetBy(dx: 10, dy: 0) + } iconButton.addSubview(iconView) toText.delegate = dataDelegate @@ -662,7 +668,7 @@ class SendViewController: UIViewController { func animateIfNeeded() { var uiSecurityState: SendViewMailSecurityState = .letter - if let view = iconButton.subviews.first as? AnimatedSendIcon, view.isPostcardOnTop { + if let view = iconButton.subviews.first as? SendIcon, view.isPostcardOnTop { uiSecurityState = .postcard } @@ -684,7 +690,7 @@ class SendViewController: UIViewController { } func startIconAnimation() { - if let view = iconButton.subviews.first as? AnimatedSendIcon { + if let view = iconButton.subviews.first as? SendIcon { view.switchIcons() } } diff --git a/enzevalos_iphone/SimpleSendIcon.swift b/enzevalos_iphone/SimpleSendIcon.swift new file mode 100644 index 0000000000000000000000000000000000000000..2d796f2bfea0aa27ff85e526a82447bed34993fa --- /dev/null +++ b/enzevalos_iphone/SimpleSendIcon.swift @@ -0,0 +1,66 @@ +// +// SimpleSendIcon.swift +// enzevalos_iphone +// +// Created by Oliver on 13.04.2019. +// Copyright © 2018 fu-berlin. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. +// +// RezisingBehavior taken from PaintCode generated file + +import Foundation +import UIKit + +protocol SendIcon { + func switchIcons() + var isPostcardOnTop: Bool { + get + } +} + +class SimpleSendIcon: UIView, SendIcon { + var isPostcardOnTop = false + + override init(frame: CGRect) { + super.init(frame: frame) + setIcon(toLetter: true) + } + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setIcon(toLetter: Bool) { + for subView in self.subviews { + self.willRemoveSubview(subView) + subView.removeFromSuperview() + } + var icon = StudySettings.securityIndicator.imageOfSecureIndicator(button: true) + isPostcardOnTop = false + if !toLetter { + // move to secure state + isPostcardOnTop = true + icon = StudySettings.securityIndicator.imageOfInsecureIndicator(button: true) + } + + let iconView = UIImageView(image: icon) + iconView.autoresizingMask = [.flexibleHeight, .flexibleWidth] + iconView.contentMode = .scaleAspectFit + self.addSubview(iconView) + self.reloadInputViews() + } + + func switchIcons() { + setIcon(toLetter: isPostcardOnTop) + } +} diff --git a/enzevalos_iphone/StudySettings.swift b/enzevalos_iphone/StudySettings.swift index 3280c3d7145a8218a1d4e115a249f55e2cf01481..f9322771f7377d232cdbfb29fb09c9a9e1e554c3 100644 --- a/enzevalos_iphone/StudySettings.swift +++ b/enzevalos_iphone/StudySettings.swift @@ -37,6 +37,7 @@ class StudySettings { } static var presentFirstQuestionaireMail = false + static var showBothSecurityIconsInSend = false static var securityIndicator: SecurityIndicator = SecurityIndicator.load() as! SecurityIndicator static var invitationsmode: Inviation = Inviation.load() as! Inviation diff --git a/enzevalos_iphone/Theme.swift b/enzevalos_iphone/Theme.swift index ed06dfd185ca210efe28ae38358574e58df43b77..5b93c095c2495ff8d816c1fbad5e4d39fbe39460 100644 --- a/enzevalos_iphone/Theme.swift +++ b/enzevalos_iphone/Theme.swift @@ -94,7 +94,7 @@ struct ThemeManager { if let storedTheme = (UserDefaults.standard.value(forKey: SelectedThemeKey) as? Int) { return Theme(rawValue: storedTheme)! } else { - return .very_strong_security_indicator + return .no_security_indicator } } @@ -115,7 +115,7 @@ struct ThemeManager { } static func animation() -> Bool { - return currentTheme() == .very_strong_security_indicator + return true } static func applyTheme(_ theme: Theme) { diff --git a/enzevalos_iphone/study parameters/SecurityIndicator.swift b/enzevalos_iphone/study parameters/SecurityIndicator.swift index 8c1489cf932d7396d21cdf80daa73b48d5066440..aa25e283f21ca62d96a1a17dd09dd25abd470766 100644 --- a/enzevalos_iphone/study parameters/SecurityIndicator.swift +++ b/enzevalos_iphone/study parameters/SecurityIndicator.swift @@ -62,9 +62,12 @@ enum SecurityIndicator: Int, StudyParameterProtocol { - func imageOfSecureIndicator(background: Bool = false, open: Bool = false) -> UIImage { + func imageOfSecureIndicator(background: Bool = false, open: Bool = false, button: Bool = false) -> UIImage { switch self { case .letter: + if button { + return IconsStyleKit.imageOfLetterButton + } if open { return IconsStyleKit.imageOfLetterOpen } @@ -73,6 +76,9 @@ enum SecurityIndicator: Int, StudyParameterProtocol { } return IconsStyleKit.imageOfLetter case .padlock: + if button { + return IconsStyleKit.imageOfPadlockSecureButton + } if background { return IconsStyleKit.imageOfPadlockSecureBG } @@ -90,14 +96,20 @@ enum SecurityIndicator: Int, StudyParameterProtocol { } } - func imageOfInsecureIndicator(background: Bool = false) -> UIImage { + func imageOfInsecureIndicator(background: Bool = false, button: Bool = false) -> UIImage { switch self { case .letter: + if button { + return IconsStyleKit.imageOfPostcardButton + } if background { return IconsStyleKit.imageOfPostcardBG } return IconsStyleKit.imageOfPostcard case .padlock: + if button { + return IconsStyleKit.imageOfPadlockInsecureButton + } if background { return IconsStyleKit.imageOfPadlockInsecureBG }