Commit de83a1cf authored by Oliver Wiese's avatar Oliver Wiese

add preview to readView (sender)

parent 6d073fb5
......@@ -156,6 +156,7 @@
47C822682438A85C005BCE73 /* SenderDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C822662438A85C005BCE73 /* SenderDetails.swift */; };
47C822692438A85C005BCE73 /* PhishingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C822672438A85C005BCE73 /* PhishingView.swift */; };
47C8226B2438A86B005BCE73 /* SenderViewMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C8226A2438A86A005BCE73 /* SenderViewMain.swift */; };
47C8226D2438C2CF005BCE73 /* ReadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C8226C2438C2CF005BCE73 /* ReadViewModel.swift */; };
47CD5AAA2012368D00E771A1 /* logging_pk.asc in Resources */ = {isa = PBXBuildFile; fileRef = 47CD5AA82012368D00E771A1 /* logging_pk.asc */; };
47CD5AAD2012369400E771A1 /* support_pk2.asc in Resources */ = {isa = PBXBuildFile; fileRef = 47CD5AAC2012369300E771A1 /* support_pk2.asc */; };
47CEAC98222541B40075B7DC /* MailSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47CEAC97222541B40075B7DC /* MailSession.swift */; };
......@@ -601,6 +602,7 @@
47C822662438A85C005BCE73 /* SenderDetails.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SenderDetails.swift; sourceTree = "<group>"; };
47C822672438A85C005BCE73 /* PhishingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhishingView.swift; sourceTree = "<group>"; };
47C8226A2438A86A005BCE73 /* SenderViewMain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SenderViewMain.swift; sourceTree = "<group>"; };
47C8226C2438C2CF005BCE73 /* ReadViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadViewModel.swift; sourceTree = "<group>"; };
47CD5AA82012368D00E771A1 /* logging_pk.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = logging_pk.asc; path = keys/logging_pk.asc; sourceTree = "<group>"; };
47CD5AAC2012369300E771A1 /* support_pk2.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = support_pk2.asc; path = keys/support_pk2.asc; sourceTree = "<group>"; };
47CEAC97222541B40075B7DC /* MailSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailSession.swift; sourceTree = "<group>"; };
......@@ -1258,6 +1260,7 @@
47C8226A2438A86A005BCE73 /* SenderViewMain.swift */,
47C8224324379EAE005BCE73 /* AttachmentsViewMain.swift */,
47C8225224379EAE005BCE73 /* ReadMainView.swift */,
47C8226C2438C2CF005BCE73 /* ReadViewModel.swift */,
);
path = Read;
sourceTree = "<group>";
......@@ -2231,6 +2234,7 @@
4751C7002344D37C006B2A4D /* SecretKey+CoreDataClass.swift in Sources */,
A1AEBA5921E808CB00C84E59 /* IntroYesNoViewController.swift in Sources */,
A1EB05941D956931008659C1 /* InboxCellDelegator.swift in Sources */,
47C8226D2438C2CF005BCE73 /* ReadViewModel.swift in Sources */,
47C822602437A143005BCE73 /* CornerRounder.swift in Sources */,
8428A85D1F436A05007649A5 /* Badges.swift in Sources */,
971D404A2428C87E002FCD31 /* BadgeCaseView.swift in Sources */,
......
......@@ -30,7 +30,7 @@ public protocol Contact {
}
extension Contact {
private func makeImageFromName(_ name: String) -> UIImage {
public static func makeImageFromName(_ name: String, color: UIColor) -> UIImage {
var text: NSAttributedString
var tag = String()
if name.count > 0 {
......@@ -57,7 +57,7 @@ extension Contact {
//
// Fill background of context
//
context!.setFillColor(self.getColor().cgColor)
context!.setFillColor(color.cgColor)
context!.fill(CGRect(x: 0, y: 0, width: myBounds.size.width, height: myBounds.size.height));
......@@ -81,7 +81,7 @@ extension Contact {
return UIImage(data: contact.thumbnailImageData!)!
}
}
return makeImageFromName(self.name)
return Self.makeImageFromName(self.name, color: self.getColor())
}
func getColor() -> UIColor {
......
......@@ -20,6 +20,7 @@
import Foundation
import CoreData
import SwiftUI
extension KeyRecord {
......@@ -110,3 +111,42 @@ extension KeyRecord{
DataHandler.handler.save(during: "Fix first mails")
}
}
extension KeyRecord: DisplayContact {
var addr: String {
return self.addresses.first?.mailAddress ?? "No address"
}
var myImage: Image {
return self.image.img
}
var isInContactBook: Bool {
return self.cnContact != nil
}
var otherAddresses: [String] {
return self.addressNames
}
var keys: [String] {
if let id = self.keyID {
return [id]
}
return []
}
var hasPreviousMails: Bool {
return self.persistentMails?.count ?? 0 > 1
}
var hasSimilarContacts: Bool {
return false // TODO!
}
var similarContacts: [String] {
return [] // TODO!
}
}
......@@ -417,3 +417,29 @@ extension PersistentMail {
@NSManaged public func removeFromReferenceMails(_ values: NSSet)
}
extension PersistentMail: DisplayMail {
var sender: DisplayContact {
return self.record!
}
var ccs: [DisplayContact] {
return [] // TODO
}
var bccs: [DisplayContact] {
return [] // TODO
}
var routingStops: [Landmark] {
return [] // TODO
}
var signedState: SignatureState {
return self.sigState
}
}
//
// ReadViewModel.swift
// enzevalos_iphone
//
// Created by Oliver Wiese on 04.04.20.
// Copyright © 2020 fu-berlin. All rights reserved.
//
import Foundation
import SwiftUI
protocol DisplayContact {
// General
var name: String { get }
var addr: String { get }
var myImage: Image { get }
var isInContactBook: Bool { get }
var otherAddresses: [String] { get }
// Crypto related
var keys: [String] { get }
// Phishing related
var hasPreviousMails: Bool { get }
var hasSimilarContacts: Bool { get }
var similarContacts: [String] { get }
}
protocol DisplayMail {
var subject: String? { get }
var body: String? { get }
var sender: DisplayContact { get }
var ccs: [DisplayContact] { get }
var bccs: [DisplayContact] { get }
var routingStops: [Landmark] { get }
// Crypto
var signedState: SignatureState { get }
var encState: EncryptionState { get }
}
class ReadViewModel: ObservableObject {
// Meta data
let senderName: String
let senderImg: Image
let landmarks: [Landmark]
let ccsNames: [String]
let bccsNames: [String]
init(senderName: String, senderImg: Image, landmarks: [Landmark], ccs: [String], bccs: [String]) {
self.senderName = senderName
self.senderImg = senderImg
self.landmarks = landmarks
self.ccsNames = ccs
self.bccsNames = bccs
}
}
......@@ -42,9 +42,28 @@ final class LandmarkAnnotation: NSObject, MKAnnotation {
}
}
/**
The Landmark struct is defined by three parameters.
id, name, domain and location.
*/
struct Landmark: Equatable {
static func ==(lhs: Landmark, rhs: Landmark) -> Bool {
lhs.id == rhs.id
}
let id = UUID().uuidString
let name: String
let domain: String
let location: CLLocationCoordinate2D
}
struct MapView: UIViewRepresentable {
@Binding var landmarks: [Landmark] /// all displayed landmaeeks are stored in an array of type Landmark
var landmarks: [Landmark] /// all displayed landmaeeks are stored in an array of type Landmark
@Binding var selectedLandmark: Landmark? /// this variable stored the next landmark from the array which is selected/displayed
@Binding var showingLandmarkDetails: Bool /// this Boolean shows more details about the selected landmark
......@@ -81,7 +100,10 @@ struct MapView: UIViewRepresentable {
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
/// this method configures the zoom level when the next landmark/annotation is selcted
guard let coordinates = view.annotation?.coordinate else { return }
guard let coordinates = view.annotation?.coordinate else {
return
}
// https://stackoverflow.com/questions/4189621/setting-the-zoom-level-for-a-mkmapview
let span = mapView.region.span
let region = MKCoordinateRegion(center: coordinates, span: span)
mapView.setRegion(region, animated: true)
......
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