Skip to content
Snippets Groups Projects
Commit a9e1582b authored by Oliver Wiese's avatar Oliver Wiese
Browse files

change encryption to toggle (since we can not encrypt every time!)

parent db852c7f
No related branches found
No related tags found
1 merge request!84Resolve "Missing backend features/connections for UI"
......@@ -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))
}
}
......@@ -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:
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment