forked from asuc-octo/berkeley-mobile-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceTile.swift
More file actions
138 lines (124 loc) · 5.3 KB
/
ResourceTile.swift
File metadata and controls
138 lines (124 loc) · 5.3 KB
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
import UIKit
fileprivate let kColorRed = UIColor.red
fileprivate let kColorGray = UIColor(white: 189/255.0, alpha: 1)
fileprivate let kColorNavy = UIColor(red: 0, green: 51/255.0, blue: 102/255.0, alpha: 1)
fileprivate let kColorGreen = UIColor(red: 16/255.0, green: 161/255.0, blue: 0, alpha:1)
/**
* LocationTile represents a single DiningHall.
* It shows a thumbnail image, name, open status, and a save/favorite button.
*/
class ResourceTile: UICollectionViewCell, RequiresData, ToggleButtonDelegate
{
// Data
private var resource: Resource!
// UI
@IBOutlet private weak var imageView: UIImageView!
@IBOutlet private weak var nameLabel: UILabel!
@IBOutlet private weak var statusLabel: UILabel!
@IBOutlet private weak var favoriteButton: ToggleButton!
/// Configure any visual elements that does not require data.
override func awakeFromNib()
{
let layer = self.layer
layer.borderWidth = 1
layer.borderColor = kColorGray.cgColor
layer.shadowRadius = 2.0
layer.shadowOpacity = 0.2
layer.shadowOffset = CGSize(width: 1.0, height: 1.0)
}
// ========================================
// MARK: - RequiresData
// ========================================
typealias DataType = Resource
/// Receive DiningHall to represent, and connect all data.
public func setData(_ resource: DataType)
{
self.resource = resource
self.nameLabel.text = resource.name
if (type(of: resource) == CampusResource.self || type(of: resource) == GymClass.self) {
self.statusLabel.text = ""
} else {
let status = self.resource.isOpen ? ("OPEN", kColorGreen) : ("CLOSED", kColorRed)
self.statusLabel.text = status.0
self.statusLabel.textColor = status.1
}
// if (type(of: resource) == GymClass.self) {
if let im = resource.image {
self.imageView.image = im
} else {
switch resource.name {
case "ALL-AROUND WORKOUT": do {
self.imageView.image = #imageLiteral(resourceName: "ALL-AROUND WORKOUT")
resource.image = #imageLiteral(resourceName: "ALL-AROUND WORKOUT")
}
case "CARDIO": do {
self.imageView.image = #imageLiteral(resourceName: "CARDIO")
resource.image = #imageLiteral(resourceName: "CARDIO")
}
case "MIND/BODY": do {
self.imageView.image = #imageLiteral(resourceName: "MIND:BODY")
resource.image = #imageLiteral(resourceName: "MIND:BODY")
}
case "DANCE": do {
self.imageView.image = #imageLiteral(resourceName: "DANCE")
resource.image = #imageLiteral(resourceName: "DANCE")
}
case "STRENGTH": do {
self.imageView.image = #imageLiteral(resourceName: "STRENGTH")
resource.image = #imageLiteral(resourceName: "STRENGTH")
}
case "AQUA": do {
self.imageView.image = #imageLiteral(resourceName: "AQUA")
resource.image = #imageLiteral(resourceName: "AQUA")
}
case "CORE": do {
self.imageView.image = #imageLiteral(resourceName: "CORE")
resource.image = #imageLiteral(resourceName: "CORE")
}
case "Recreational Sports Facility (RSF)": do {
self.imageView.image = #imageLiteral(resourceName: "rsf")
resource.image = #imageLiteral(resourceName: "rsf")
}
case "Stadium Fitness Center": do {
self.imageView.image = #imageLiteral(resourceName: "stadium")
resource.image = #imageLiteral(resourceName: "stadium")
}
case "Browns Cafe" : do {
self.imageView.image = #imageLiteral(resourceName: "browns_cafe")
resource.image = #imageLiteral(resourceName: "browns_cafe")
}
case "Golden Bear Cafe" : do {
self.imageView.image = #imageLiteral(resourceName: "golden_bear_cafe")
resource.image = #imageLiteral(resourceName: "golden_bear_cafe")
}
case "The Den" : do {
self.imageView.image = #imageLiteral(resourceName: "the_den")
resource.image = #imageLiteral(resourceName: "the_den")
}
case "Clark Kerr": do {
self.imageView.image = #imageLiteral(resourceName: "ckc")
resource.image = #imageLiteral(resourceName: "ckc")
}
default: do {
self.imageView.load(resource: resource)
}
}
}
// } else {
// self.imageView.load(url: resource.imageURL)
// }
// self.favoriteButton.isSelected = resource.isFavorited
}
// ========================================
// MARK: - ToggleButtonDelegate
// ========================================
/**
* Called when the favoriteButton on the tile is toggled.
* Pass the event through the FavoriteCallback.
*/
func buttonDidToggle(_ button: ToggleButton)
{
resource.isFavorited = button.isSelected
FavoriteStore.shared.update(resource)
}
}