Commit 6d073fb5 authored by Oliver Wiese's avatar Oliver Wiese

Add SenderView

parent 8b5f556c
This diff is collapsed.
This diff is collapsed.
//
// MapView.swift
// enzevalos_iphone
//
// Created by Sabina on 16.03.20.
// Copyright © 2020 fu-berlin. All rights reserved.
//
import SwiftUI
import MapKit
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
MKMapView(frame: .zero)
}
func updateUIView(_ uiView: MKMapView, context: Context) {
let coordinate = CLLocationCoordinate2D(
latitude: 52.5065116, longitude: 13.1438676)
let span = MKCoordinateSpan(latitudeDelta: 2.0, longitudeDelta: 2.0)
let region = MKCoordinateRegion(center: coordinate, span: span)
uiView.setRegion(region, animated: true)
}
}
struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
}
}
//
// ContentView.swift
// enzevalos_iphone
//
// Created by Fatima on 19/03/2020.
// Copyright © 2020 fu-berlin. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
import SwiftUI
/**
The view displays Phishing information in a VStack and uses a list to present details.
*/
struct AllPhishingContent: Identifiable {
let id: Int
let name: String
let message: String
}
//not
struct PhishingView : View {
/// This content stores the phishing information in a list
var PhishingList = [
AllPhishingContent(id: 0, name: "no declaration", message: "content empty"),
AllPhishingContent(id: 1, name: "no declaration", message: "content empty"),
AllPhishingContent(id: 2, name: "no declaration", message: "content empty"),
AllPhishingContent(id: 3, name: "no declaration", message: "content empty"),
]
var body: some View {
List(PhishingList) { AllPhishingContent in
VStack {
Text("Identification").bold()
Text(AllPhishingContent.name)
Text(AllPhishingContent.message).italic()
}
}
}
}
struct PhishingList_Previews: PreviewProvider {
static var previews: some View {
PhishingView()
}
}
//
// SwiftUIView.swift
// enzevalos_iphone
//
// Created by Fatima on 16/03/2020.
// Copyright © 2020 fu-berlin. All rights reserved.
//
import SwiftUI
/*
struct ProfileEmoji: View {
var body: some View {
Image("profileEmoji")
.resizable()
.frame(width: 130.0, height: 110.0)
.clipShape(Circle())
.overlay(
Circle().stroke(Color.white, lineWidth: 2))
.shadow(radius: 8)
}
}
struct ProfileEmoji_Previews: PreviewProvider {
static var previews: some View {
ProfileEmoji()
}
}
*/
//
// SenderDetails.swift
// enzevalos_iphone
//
// Created by Sabina on 22.03.20.
// Copyright © 2020 fu-berlin. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>./
import SwiftUI
/**
SenderDetails contains information about the sender.
They are wrapped in a VStack that has also HStack for showing textes below
Those more details are message information. They can be displayed in a drop down window.
Click on the arrow to see all details.
*/
struct SenderDetails: View {
@State private var moreDetails = false
var body: some View {
VStack (alignment: .leading, spacing: 20) {
Text("Sender:")
.font(.subheadline)
.padding(.bottom, 5)
HStack(alignment: .top) {
Text("More Details")
.foregroundColor(.blue)
.font(.system(size: 10))
Button (action: {
self.moreDetails.toggle()
}) {
Image(systemName: moreDetails ? "chevron.up" : "chevron.down")
.resizable()
.frame(width: 12.0, height: 7.0)
}
}
if moreDetails {
HStack {
Spacer()
.frame(width: 40)
VStack(alignment: .leading){
Text("Last message received on:")
Text("Last message sent on:")
Text("Total number of messages sent:")
} .font(.system(size: 10))
}
}
}
}
}
struct SenderDetails_Previews: PreviewProvider {
static var previews: some View {
SenderDetails()
}
}
//
// SenderViewMain.swift
// enzevalos_iphone
//
// Created by fatimaaa96 on 12.03.20.
// Copyright © 2020 fu-berlin. All rights reserved.
//
import SwiftUI
//map, Memoji picture, sender information and phishing detail
struct SenderViewMain: View {
let mail:PersistentMail
var body: some View {
VStack {
ZStack {
MapView()
.frame(height: 250)
HStack (spacing: -5) {
Spacer()
.frame(width: 60)
// ProfileEmoji()
//.offset(y: 105)
.padding(.bottom, -270)
Button (action: {
print ("Edit activated")
}) {
Text("Edit")
.font(.system(size: 9))
}.padding(.top, 190)
}.offset(y: 60)
}
Spacer()
VStack(alignment: .leading) {
Spacer()
.frame(height: 70)
// TODO: add reference about sender information (additionally to be done: link update to data base ?!)
Text("Sender:")
.font(.subheadline)
.padding(.bottom, 5)
MoreDetailsSender()
Divider()
VStack (alignment: .leading){
Text("CC:")
.font(.subheadline)
.padding(.bottom, 8)
HStack (spacing: 20){
Text("Email 1")
Text("Email 2")
Text("Email 3")
}.font(.system(size: 12))
}.padding([.top, .bottom], 5)
Divider()
VStack (alignment: .leading){
Text("BCC:")
.font(.subheadline)
.padding(.bottom, 8)
HStack (spacing: 20){
Text("Email 1")
Text("Email 2")
Text("Email 3")
}.font(.system(size: 12))
}.padding([.top, .bottom], 5)
Divider()
DropDown()
Spacer()
}.padding()
Spacer()
}
}
}
/*
struct SenderViewMain_Previews: PreviewProvider {
static var previews: some View {
SenderViewMain()
}
}
*/
struct MoreDetailsSender: View {
@State private var moreDetails = false
var body: some View {
VStack (alignment: .leading, spacing: 20) {
HStack(alignment: .top) {
Text("Details")
.foregroundColor(.blue)
.font(.system(size: 10))
Button (action: {
self.moreDetails.toggle()
}) {
Image(systemName: moreDetails ? "chevron.up" : "chevron.down")
.resizable()
.frame(width: 12.0, height: 7.0)
}
}
if moreDetails {
HStack {
Spacer()
.frame(width: 40)
VStack(alignment: .leading){
Text("Last message received on:")
Text("Last message sent on:")
Text("Total number of messages sent:")
} .font(.system(size: 10))
}
}
}
}
}
// important TODO: add phishing elements
struct DropDown: View {
@State private var clicked = false
var body: some View {
VStack (alignment: .leading, spacing: 20) {
HStack(alignment: .top) {
Text("Phishing:")
.font(.subheadline)
Button (action: {
self.clicked.toggle()
}) {
Image(systemName: clicked ? "chevron.up" : "chevron.down")
}
}
if clicked {
HStack {
Spacer()
.frame(width: 70)
Text ("Here comes the text with phishing details.") //TODO: Add content for phishing details
.font(.system(size: 12))
}
}
}.padding([.top, .bottom], 5)
}
}
//
// MapView.swift
// enzevalos_iphone
//
// Created by Sabina on 16.03.20.
// Copyright © 2020 fu-berlin. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
import SwiftUI
import MapKit
/**
This file handles the configuration of the MapView from the SenderViewMain.
*/
final class LandmarkAnnotation: NSObject, MKAnnotation {
let id: String
let title: String?
let domainName: String?
let coordinate: CLLocationCoordinate2D
init(landmark: Landmark) {
self.id = landmark.id
self.title = landmark.name
self.domainName = landmark.domain
self.coordinate = landmark.location
}
}
struct MapView: UIViewRepresentable {
@Binding 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
func makeUIView(context: Context) -> MKMapView {
/// configuration of the UIView
let map = MKMapView()
map.delegate = context.coordinator
return map
}
func updateUIView(_ uiView: MKMapView, context: Context) {
/**
This function gets calles whenever the values being sent into the UIViewReprensentable have changed.
When a new landmark is selected the updateAnnotation and the addPolyline functions are called again in order to update the annotations in the MapView and add a polyline between them.
*/
updateAnnotations(from: uiView)
addPolyline(from: uiView)
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
final class Coordinator: NSObject, MKMapViewDelegate {
var parent: MapView
init(_ parent: MapView) {
self.parent = parent
}
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 }
let span = mapView.region.span
let region = MKCoordinateRegion(center: coordinates, span: span)
mapView.setRegion(region, animated: true)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
/**
This method uses a custom view to representan annotation, reuses views for performance and has a button that can be tapped for more information.
*/
guard let annotation = annotation as? LandmarkAnnotation else { return nil }
let identifier = "Annotation"
var annotationView: MKMarkerAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView
if annotationView == nil {
annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
} else {
annotationView?.annotation = annotation
}
return annotationView
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
/**
This method gets called when the button for more details is tapped.
It checks if there is a selected landmark and if so, it uses it to set the selected landmark porperty to the parent MapView with the help of the getLandMarkByCoordinates method.
Also the showingLandmarkDetails is set to true, which will trigger the alert in the SenderViewMain.
*/
print(view.annotation)
guard let placemark = view.annotation as? LandmarkAnnotation?/*MKPointAnnotation?*/ else { print("failed conversion") ;return }
parent.selectedLandmark = getLandMarkByCoordinates(placemark!.coordinate)
parent.showingLandmarkDetails = true
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
/// This function creates and configures a polyline
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.strokeColor = UIColor.orange
renderer.lineWidth = 3
return renderer
}
func getLandMarkByCoordinates(_ coords:CLLocationCoordinate2D)->Landmark{
func equals(_ lm1:CLLocationCoordinate2D,_ lm2:CLLocationCoordinate2D)->Bool{
return lm1.latitude==lm2.latitude&&lm1.longitude==lm2.longitude
}
let marks:[Landmark]=parent.landmarks
var i:Int=0
while !equals(marks[i].location,coords) {
i+=1
}
return marks[i]
}
}
private func updateAnnotations(from mapView: MKMapView) {
/// this method updates the displayed annotations in the MapView according to the selected landmark
mapView.removeAnnotations(mapView.annotations)
let newAnnotations = landmarks.map { LandmarkAnnotation(landmark: $0) }
mapView.addAnnotations(newAnnotations)
if let selectedAnnotation = newAnnotations.filter({ $0.id == selectedLandmark?.id }).first {
mapView.selectAnnotation(selectedAnnotation, animated: true)
}
}
private func addPolyline(from mapView: MKMapView){
/// this method adds a polyline between the landmarks in the MapView
var locations = landmarks.map { $0.location }
let polyline = MKPolyline (coordinates: &locations, count: locations.count)
mapView.addOverlay(polyline)
}
}
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