forked from asuc-octo/berkeley-mobile-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCampusResourceViewController.swift
150 lines (120 loc) · 5.18 KB
/
CampusResourceViewController.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// CampusResourceViewController.swift
//
//
// Created by Marisa Wong on 3/5/18.
//
import UIKit
import Material
import GoogleMaps
class CampusResourceViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
@IBOutlet weak var campResTitle: UILabel!
@IBOutlet weak var campResImage: UIImageView!
@IBOutlet weak var campResTableView: UITableView!
@IBOutlet var campResMap: GMSMapView!
var campusResource:CampusResource!
var locationManager = CLLocationManager()
var iconImages: [UIImage] = [
UIImage(named:"hours_2.0.png")!,
UIImage(named:"phone_2.0.png")!,
UIImage(named:"location_2.0.png")!,
UIImage(named:"info_2.0.png")!
]
var campResInfo = [String]()
override func viewDidLoad() {
super.viewDidLoad()
campResTitle.text = campusResource.name
if let data = try? Data(contentsOf: campusResource.imageURL!)
{
let image: UIImage = UIImage(data: data)!
campResImage.image = image
}
campResInfo.append((self.campusResource?.hours)!)
campResInfo.append((self.campusResource?.phoneNumber)!)
if let loc = campusResource.campusLocation {
campResInfo.append(loc)
} else {
campResInfo.append("Call for location")
}
campResInfo.append((self.campusResource?.description)!)
campResTableView.delegate = self
campResTableView.dataSource = self
setUpMap()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setUpMap() {
//Setting up map view
campResMap.delegate = self
campResMap.isMyLocationEnabled = true
let camera = GMSCameraPosition.camera(withLatitude: 37.871853, longitude: -122.258423, zoom: 15)
self.campResMap.camera = camera
self.campResMap.frame = self.view.frame
self.campResMap.isMyLocationEnabled = true
self.campResMap.isUserInteractionEnabled = false
self.campResMap.delegate = self
self.locationManager.startUpdatingLocation()
let kMapStyle =
"[" +
"{ \"featureType\": \"administrative\", \"elementType\": \"geometry\", \"stylers\": [ { \"visibility\": \"off\" } ] }, " +
"{ \"featureType\": \"poi\", \"stylers\": [ { \"visibility\": \"off\" } ] }, " +
"{ \"featureType\": \"road\", \"elementType\": \"labels.icon\", \"stylers\": [ { \"visibility\": \"off\" } ] }, " +
"{ \"featureType\": \"transit\", \"stylers\": [ { \"visibility\": \"off\" } ] } " +
"]"
do {
// Set the map style by passing a valid JSON string.
self.campResMap.mapStyle = try GMSMapStyle(jsonString: kMapStyle)
} catch {
NSLog("The style definition could not be loaded: \(error)")
// print(error)
}
let lat = campusResource.latitude!
let lon = campusResource.longitude!
let marker = GMSMarker()
marker.icon = #imageLiteral(resourceName: "blueStop")
marker.position = CLLocationCoordinate2D(latitude: lat, longitude: lon)
marker.title = campusResource?.name
marker.map = self.campResMap
}
/*
// 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.
}
*/
}
extension CampusResourceViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 3 {
print("hello i am 4th row bih")
return UITableViewAutomaticDimension
} else {
return 55
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let campResInfoCell = campResTableView.dequeueReusableCell(withIdentifier: "campusResourceDetail", for: indexPath) as! CampusResourceDetailCell
campResInfoCell.campResIconImage.image = iconImages[indexPath.row]
campResInfoCell.campResIconInfo.text = campResInfo[indexPath.row]
campResInfoCell.campResIconInfo.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightMedium)
return campResInfoCell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.selectionStyle = .none
if indexPath.row == 1 {
//callCampRes()
}
}
}