From e859906565a6a1fac6778c541982da51be37fdec Mon Sep 17 00:00:00 2001
From: Oliver Wiese <oliver.wiese@fu-berlin.de>
Date: Mon, 6 Apr 2020 17:10:17 +0200
Subject: [PATCH] new SenderView in ReadView

---
 .../SwiftUI/Read/ReadViewModel.swift          | 111 +++++++++++++++
 .../SwiftUI/Read/SenderViewMain.swift         | 131 ++----------------
 2 files changed, 125 insertions(+), 117 deletions(-)

diff --git a/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift b/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift
index 70855afa..eaa35486 100644
--- a/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift
+++ b/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift
@@ -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
+    }
+    
+}
diff --git a/enzevalos_iphone/SwiftUI/Read/SenderViewMain.swift b/enzevalos_iphone/SwiftUI/Read/SenderViewMain.swift
index d90a48a0..baa8ab12 100644
--- a/enzevalos_iphone/SwiftUI/Read/SenderViewMain.swift
+++ b/enzevalos_iphone/SwiftUI/Read/SenderViewMain.swift
@@ -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
-    }
-    
-}
-- 
GitLab