This repository has been archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivityViewController.swift
110 lines (88 loc) · 4.46 KB
/
ActivityViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// ThirdViewController.swift
// ConfluencePrototype
//
// Created by Gabriel D'Luca Souza Viana on 22/09/17.
// Copyright © 2017 Gabriel D'Luca Souza Viana. All rights reserved.
//
import UIKit
import MapKit
class ActivityViewController: UIViewController {
var event:EventUnit = EventUnit(eventTitle: "Evento1", eventCreator: "1", id: "1", locationName: "Casa da Mãe Joana", motivation: "Queremos saber o que é Caviar", date: "10-28-1995 20:00", coordinate: CLLocationCoordinate2D(latitude: -8.055668, longitude: -34.951578), image: UIImage(named: "profile-header.png")!)
@IBOutlet weak var btnEngage: UIButton!
@IBOutlet weak var btnGoThere: UIButton!
@IBOutlet weak var eventPhoto: UIImageView!
@IBOutlet weak var activityDate: UILabel!
@IBAction func dismissView(_ sender: Any) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)
self.dismiss(animated: true, completion: nil)
}
@IBAction func engageEvent(_ sender: Any) {
if !Manager.sharedInstance.usuario.eventEngaged.eventExists(event.id) {
let index = Manager.sharedInstance.repositorio.index(of: event.id)
Manager.sharedInstance.repositorio.eventItems[index].peopleEngaged += 1
Manager.sharedInstance.usuario.eventEngaged.registerEvent(event: event)
btnEngage.setTitle("Engaged", for: .normal)
btnEngage.setTitleColor(UIColor(red: 1.0, green: 0.7, blue: 0.28, alpha: 1.0), for: .normal)
} else {
let index = Manager.sharedInstance.repositorio.index(of: event.id)
Manager.sharedInstance.repositorio.eventItems[index].peopleEngaged -= 1
Manager.sharedInstance.usuario.eventEngaged.remove(event: event)
btnEngage.setTitle("Engage", for: .normal)
btnEngage.setTitleColor(UIColor(red: 0.15, green: 0.64, blue: 0.65, alpha: 1.0), for: .normal)
}
engagedNumber.text = String(event.peopleEngaged)
}
var idActualEvent = ""
override func viewDidLoad() {
super.viewDidLoad()
let userName = Manager.sharedInstance.usuario.username
if !idActualEvent.isEmpty {
event = Manager.sharedInstance.repositorio.filterById(id: idActualEvent)!
eventName.text = event.eventTitle.uppercased()
//Should receive the name of who has the event.eventCreator id
creatorName.text = event.eventCreator
motivation.text = event.motivation
motivation.sizeToFit()
address.text = event.locationName
eventPhoto.image = event.image
engagedNumber.text = String(event.peopleEngaged)
activityDate.text = event.date
}
if (Manager.sharedInstance.usuario.eventCreated.eventExists(event.id)) {
btnEngage.isEnabled = false
btnEngage.isHidden = true
} else if (Manager.sharedInstance.usuario.eventEngaged.eventExists(event.id)){
btnEngage.setTitle("Engaged", for: .normal)
btnEngage.setTitleColor(UIColor(red: 1.0, green: 0.7, blue: 0.28, alpha: 1.0), for: .normal)
}
// Do any additional setup after loading the view.
eventPhoto.layer.cornerRadius = eventPhoto.frame.height/2
eventPhoto.clipsToBounds = true
}
@IBAction func goThere(_ sender: Any) {
let location = EventAnnotation(event: event)
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
location.mapItem().openInMaps(launchOptions: launchOptions)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
@IBOutlet weak var eventName: UILabel!
@IBOutlet weak var motivation: UILabel!
@IBOutlet weak var days: UILabel!
@IBOutlet weak var hours: UILabel!
@IBOutlet weak var minutes: UILabel!
@IBOutlet weak var creatorName: UILabel!
@IBOutlet weak var address: UILabel!
@IBOutlet weak var engagedNumber: UILabel!
}