Commit e8599065 authored by Oliver Wiese's avatar Oliver Wiese

new SenderView in ReadView

parent af53453b
......@@ -9,6 +9,16 @@
import Foundation
import SwiftUI
let alice = PseudoContact(name: "Alice", addr: "alice@example.com", myImage: PseudoContact.makeImg("Alice", color: .blue))
let bob = PseudoContact(name: "Bob", addr: "Bob.lord.of.kingsbridge.and.king.of.england@huge.subdomain.with. a.long.long.long.domain.example.com", myImage: PseudoContact.makeImg("Bob", color: .red))
let charlie = PseudoContact(name: "Charlie", addr: "charlie@example.com", myImage: PseudoContact.makeImg("Charlie", color: .green))
let landmarks = [
Landmark(name: "Berlin", domain: "exampledomain.de", location: .init(latitude: 52.520008, longitude: 13.404954)),
Landmark(name: "New York", domain: "secondexampledomain.de", location: .init(latitude: 40.730610, longitude: -73.935242)),
Landmark(name: "Sydney", domain: "thirdexampledomain.de", location: .init(latitude: -33.865143, longitude: 151.209900))
]
let mail = PseuoMail(sender: alice, tos: [bob,charlie], ccs: [bob, charlie,bob, charlie,bob], bccs: [], routingStops: landmarks, signedState: .ValidSignature, encState: .ValidedEncryptedWithCurrentKey)
protocol DisplayContact {
// General
var name: String { get }
......@@ -69,3 +79,104 @@ class ReadViewModel: ObservableObject {
}
struct PseudoContact: DisplayContact {
var previousMails: Int = 10
var previousResponses: Int = 2
var name: String
var addr: String
var myImage: Image
var isInContactBook: Bool = false
var otherAddresses: [String] = []
var keys: [String] = []
var hasPreviousMails: Bool = false
var hasSimilarContacts: Bool = false
var similarContacts: [String] = []
public static func makeImg(_ name: String, color: UIColor) -> Image {
var text: NSAttributedString
var tag = String()
if name.count > 0 {
let seperated = name.components(separatedBy: " ")
tag = seperated.map({ if let a = $0.first { return "\(a)" }; return "" }).joined()
}
text = NSAttributedString(string: tag.uppercased(), attributes: [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 32.2)])
var myBounds = CGRect()
myBounds.size.width = 70
myBounds.size.height = 70
UIGraphicsBeginImageContextWithOptions(myBounds.size, false, 2) //try 200 here
let context = UIGraphicsGetCurrentContext()
//
// Clip context to a circle
//
let path = CGPath(ellipseIn: myBounds, transform: nil);
context!.addPath(path);
context!.clip();
//
// Fill background of context
//
context!.setFillColor(color.cgColor)
context!.fill(CGRect(x: 0, y: 0, width: myBounds.size.width, height: myBounds.size.height));
//
// Draw text in the context
//
let textSize = text.size()
text.draw(in: CGRect(x: myBounds.size.width / 2 - textSize.width / 2, y: myBounds.size.height / 2 - textSize.height / 2, width: textSize.width, height: textSize.height))
let snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return Image(uiImage: snapshot!)
}
var keyRecord: KeyRecord? {
return nil
}
}
struct PseuoMail: DisplayMail {
typealias U = PseudoContact
var subject: String? = "Hello World"
var body: String? = "This is my message."
var sender: U
var tos: [U]
var ccs: [U]
var bccs: [U]
var routingStops: [Landmark]
var signedState: SignatureState
var encState: EncryptionState
var persistentMail: PersistentMail? {
return nil
}
}
......@@ -83,21 +83,30 @@ struct SenderViewMain <M: DisplayMail, C: DisplayContact>: View {
private var sender: some View {
VStack (alignment: .leading, spacing: 10) {
Button(action: {self.goToContact(contact: self.mail.sender)}) {
HStack {
VStack (alignment: .leading) {
Text(NSLocalizedString("Sender", comment: "Sender"))
.font(.headline)
.font(.headline)
.padding(.bottom, 10)
Text(mail.sender.name)
.font(.subheadline)
.font(.subheadline)
Text(mail.sender.addr)
// .foregroundColor(.gray)
//TODO: Add last mail date
.foregroundColor(.gray)
}
Spacer()
Button(action: {self.goToContact(contact: self.mail.sender)}){
Image(systemName: "chevron.right")
}
}
.onTapGesture {
self.goToContact(contact: self.mail.sender)
}
HStack{
Text(String(format: NSLocalizedString("ReadView.Sender.Previous", comment: "100 previous received mails"), mail.sender.previousMails))
Spacer()
Text(String(format: NSLocalizedString("ReadView.Sender.Responses", comment: "5 previous sent mails"), mail.sender.previousResponses))
// TODO: Add last mail date
// TODO: Go to mailinglists?
}
}
.padding(10)
......@@ -154,8 +163,6 @@ struct SenderViewMain <M: DisplayMail, C: DisplayContact>: View {
}
struct SenderView_Previews: PreviewProvider {
static var previews: some View {
let deviceNames: [String] = [
"iPhone SE",
......@@ -163,15 +170,6 @@ struct SenderView_Previews: PreviewProvider {
// "iPad Pro (11-inch)"
]
let sender = PseudoContact(name: "Alice", addr: "alice@example.com", myImage: PseudoContact.makeImg("Alice", color: .blue))
let bob = PseudoContact(name: "Bob", addr: "Bob.lord.of.kingsbridge.and.king.of.england@huge.subdomain.with. a.long.long.long.domain.example.com", myImage: PseudoContact.makeImg("Bob", color: .red))
let charlie = PseudoContact(name: "Charlie", addr: "charlie@example.com", myImage: PseudoContact.makeImg("Charlie", color: .green))
let landmarks = [
Landmark(name: "Berlin", domain: "exampledomain.de", location: .init(latitude: 52.520008, longitude: 13.404954)),
Landmark(name: "New York", domain: "secondexampledomain.de", location: .init(latitude: 40.730610, longitude: -73.935242)),
Landmark(name: "Sydney", domain: "thirdexampledomain.de", location: .init(latitude: -33.865143, longitude: 151.209900))
]
let mail = PseuoMail(sender: sender, tos: [bob,charlie], ccs: [bob, charlie,bob, charlie,bob], bccs: [], routingStops: landmarks, signedState: .ValidSignature, encState: .ValidedEncryptedWithCurrentKey)
return ForEach(deviceNames, id: \.self) {deviceName in
SenderViewMain<PseuoMail, PseudoContact>(mail: mail)
.previewDisplayName(deviceName)
......@@ -181,104 +179,3 @@ struct SenderView_Previews: PreviewProvider {
}
}
struct PseudoContact: DisplayContact {
var previousMails: Int = 10
var previousResponses: Int = 2
var name: String
var addr: String
var myImage: Image
var isInContactBook: Bool = false
var otherAddresses: [String] = []
var keys: [String] = []
var hasPreviousMails: Bool = false
var hasSimilarContacts: Bool = false
var similarContacts: [String] = []
public static func makeImg(_ name: String, color: UIColor) -> Image {
var text: NSAttributedString
var tag = String()
if name.count > 0 {
let seperated = name.components(separatedBy: " ")
tag = seperated.map({ if let a = $0.first { return "\(a)" }; return "" }).joined()
}
text = NSAttributedString(string: tag.uppercased(), attributes: [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 32.2)])
var myBounds = CGRect()
myBounds.size.width = 70
myBounds.size.height = 70
UIGraphicsBeginImageContextWithOptions(myBounds.size, false, 2) //try 200 here
let context = UIGraphicsGetCurrentContext()
//
// Clip context to a circle
//
let path = CGPath(ellipseIn: myBounds, transform: nil);
context!.addPath(path);
context!.clip();
//
// Fill background of context
//
context!.setFillColor(color.cgColor)
context!.fill(CGRect(x: 0, y: 0, width: myBounds.size.width, height: myBounds.size.height));
//
// Draw text in the context
//
let textSize = text.size()
text.draw(in: CGRect(x: myBounds.size.width / 2 - textSize.width / 2, y: myBounds.size.height / 2 - textSize.height / 2, width: textSize.width, height: textSize.height))
let snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return Image(uiImage: snapshot!)
}
var keyRecord: KeyRecord? {
return nil
}
}
struct PseuoMail: DisplayMail {
typealias U = PseudoContact
var subject: String? = "Hello World"
var body: String? = "This is my message."
var sender: U
var tos: [U]
var ccs: [U]
var bccs: [U]
var routingStops: [Landmark]
var signedState: SignatureState
var encState: EncryptionState
var persistentMail: PersistentMail? {
return nil
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment