diff --git a/enzevalos_iphone/SwiftUI/Compose/ComposeHeaderView.swift b/enzevalos_iphone/SwiftUI/Compose/ComposeHeaderView.swift index 1927a048194bbb60be8d831c04ec7abe6f2ff536..816644928343d48cc144bb14f1250a05ea95395f 100644 --- a/enzevalos_iphone/SwiftUI/Compose/ComposeHeaderView.swift +++ b/enzevalos_iphone/SwiftUI/Compose/ComposeHeaderView.swift @@ -31,53 +31,50 @@ struct ComposeViewHeader: View { .disabled(model.recipientsModel.hasNoRecipients) } - // Encryption toggle - Toggle("", isOn: $model.encryptionOn) - .toggleStyle(EncryptionToggleStyle()) - .labelsHidden() + // Encryption button + encryptionButton } } - /// Custom styling for the encryption toggle in ComposeViewHeader. - struct EncryptionToggleStyle: ToggleStyle { - func makeBody(configuration: Configuration) -> some View { - Button { - configuration.isOn.toggle() - } label: { - // Separate labels required for desired scaling transition between states - if configuration.isOn { - encryptedButtonLabel - } else { - unencryptedButtonLabel - } + + /// Encryption state button view + private var encryptionButton: some View { + Button { + model.toogleEncryption() + } label: { + // Separate labels required for desired scaling transition between states + if model.encryptionOn { + encryptedButtonLabel + } else { + unencryptedButtonLabel } - .frame(width: 40, height: 40) } - - /// Label style for encryption button when encryption is activated. - private var encryptedButtonLabel: some View { - ZStack { - Circle() - .stroke(Color.blue, lineWidth: 2) - - Image(systemName: "lock.fill") - .font(Font.system(size: 24, weight: Font.Weight.light)) - .foregroundColor(.blue) - } - .transition(AnyTransition.opacity.combined(with: .scale)) + .frame(width: 40, height: 40) + } + + /// Label style for encryption button when encryption is activated. + private var encryptedButtonLabel: some View { + ZStack { + Circle() + .stroke(Color.blue, lineWidth: 2) + + Image(systemName: "lock.fill") + .font(Font.system(size: 24, weight: Font.Weight.light)) + .foregroundColor(.blue) } - - /// Label style for encryption button when encryption is deactivated. - private var unencryptedButtonLabel: some View { - ZStack { - Circle() - .fill(Color(UIColor.tertiaryLabel)) - - Image(systemName: "lock.slash.fill") - .font(Font.system(size: 24, weight: Font.Weight.light)) - .foregroundColor(.white) - } - .transition(AnyTransition.opacity.combined(with: .scale)) + .transition(AnyTransition.opacity.combined(with: .scale)) + } + + /// Label style for encryption button when encryption is deactivated. + private var unencryptedButtonLabel: some View { + ZStack { + Circle() + .fill(Color(UIColor.tertiaryLabel)) + + Image(systemName: "lock.slash.fill") + .font(Font.system(size: 24, weight: Font.Weight.light)) + .foregroundColor(.white) } + .transition(AnyTransition.opacity.combined(with: .scale)) } } diff --git a/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift b/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift index 2de6237a3d94070a5218040b814af58a884a7171..4818189dd7c39185371147ff1810777b5794a90a 100644 --- a/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift +++ b/enzevalos_iphone/SwiftUI/Compose/ComposeModel.swift @@ -32,6 +32,15 @@ class ComposeModel: ObservableObject { generateMail().send() } + /// Checks if encryption state can be toggled. + func toogleEncryption() { + if encryptionOn { + encryptionOn = false + } else { + recipientsModel.checkEncryption() + } + } + /// Adds email addresses to given RecipientFieldModel. /// /// - Parameters: diff --git a/enzevalos_iphone/SwiftUI/Compose/RecipientsModel.swift b/enzevalos_iphone/SwiftUI/Compose/RecipientsModel.swift index ea16a816c1e42ef135b194bbbf8eade47040e8c3..e98463dab071dce87dc721aa371d811bab5b8d8c 100644 --- a/enzevalos_iphone/SwiftUI/Compose/RecipientsModel.swift +++ b/enzevalos_iphone/SwiftUI/Compose/RecipientsModel.swift @@ -78,6 +78,7 @@ class RecipientsModel: ObservableObject { ccModel.type = showBccField ? .cc : .ccBcc } + /// Turnes encryption on if all recipients have a key. func checkEncryption() { for addr in toModel.selectedContacts { if !addr.hasPublicKey {