FacilityDetailViewController.swift 3.67 KB
Newer Older
1
2
3
4
5
//
//  LocationDetailViewController.swift
//  WhatsOpen
//
//  Created by Zach Knox on 4/5/17.
Zach Knox's avatar
Zach Knox committed
6
//  Copyright © 2017 SRCT. Some rights reserved.
7
8
9
//

import UIKit
Zach Knox's avatar
Zach Knox committed
10
import StoreKit
Zach Knox's avatar
Zach Knox committed
11
import MapKit
12

13
class FacilityDetailViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
14

Zach Knox's avatar
Zach Knox committed
15
	@IBOutlet var NameLabel: UILabel!
16
	@IBOutlet var PlaceLabel: UILabel!
Zach Knox's avatar
Zach Knox committed
17
	@IBOutlet var OpenLabel: UILabel!
18
    @IBOutlet var CategoryLabel: UILabel!
19
	@IBOutlet var OpenTimesList: UITableView!
20

Zach Knox's avatar
Zach Knox committed
21
	
22
    var facility: Facility!
23
	
24
	override var previewActionItems: [UIPreviewActionItem] {
Zach Knox's avatar
Zach Knox committed
25
26
27
28
29
30
31
32
		var title: String
		if(Utilities.isFavoriteFacility(facility)) {
			title = "Remove from Favorites"
		}
		else {
			title = "Add to Favorites"
		}
		let favoritePreviewItem = UIPreviewAction(title: title, style: UIPreviewActionStyle.default, handler: markAsFavoritePreviewAction)
33
34
	    return [favoritePreviewItem]
	}
35
	
36

37
	
Zach Knox's avatar
Zach Knox committed
38
39
40
41
	override var preferredStatusBarStyle: UIStatusBarStyle {
		return .lightContent
	}
	
42
43
    override func viewDidLoad() {
        super.viewDidLoad()
44
		
45
46
		modalPresentationCapturesStatusBarAppearance = true
		
Zach Knox's avatar
Zach Knox committed
47
48
49
50
51
52
		var name = facility.facilityName
		let separator = name.index(of: "[")
		if separator != nil {
			name = String(name[..<separator!]).replacingOccurrences(of: "\\s+$",with: "", options: .regularExpression)
		}
		NameLabel.text = name
53
54
55
		PlaceLabel.text = facility.facilityLocation!.building
        CategoryLabel.text = facility.category?.categoryName.uppercased()

Zach Knox's avatar
Zach Knox committed
56
		
57
		let open = Utilities.isOpen(facility: facility)
58
59
60
        OpenLabel.text = Utilities.openOrClosedUntil(facility)
        OpenLabel.layer.cornerRadius = 4
        OpenLabel.layer.masksToBounds = true
Zach Knox's avatar
Zach Knox committed
61
62
63
64
		if(open) {
			OpenLabel.backgroundColor = UIColor(red:0.00, green:0.40, blue:0.20, alpha:1.0)
		}
		else {
Eyad Hasan's avatar
Eyad Hasan committed
65
			OpenLabel.backgroundColor = UIColor(red:0.17, green:0.17, blue: 0.17, alpha: 1.0)
Zach Knox's avatar
Zach Knox committed
66
		}
Zach Knox's avatar
Zach Knox committed
67
		
Zac Wood's avatar
Zac Wood committed
68
		OpenTimesList.bounces = false
69
		
Zach Knox's avatar
Zach Knox committed
70
71
72
		if #available(iOS 11.0, *) {
			navigationItem.largeTitleDisplayMode = .never
		}
Zac Wood's avatar
Zac Wood committed
73
74
75
76
77
78
        
//        NameLabel.font = UIFont.preferredFont(forTextStyle: .headline)
//        PlaceLabel.font = UIFont.preferredFont(forTextStyle: .subheadline)
//        OpenLabel.font = UIFont.preferredFont(forTextStyle: .body)
//        favoritesButton.titleLabel?.font = UIFont.preferredFont(forTextStyle: .body)
        
79
80
81
82
83
84
85
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

86
87
88
    func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
89
    }
90

91
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Zach Knox's avatar
Zach Knox committed
92
		return Utilities.getCurrentSchedule(facility)!.openTimes.count
93
    }
94

95
96
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = OpenTimesList.dequeueReusableCell(withIdentifier: "LocationDetailCell", for: indexPath)
97

98
99
		cell.selectionStyle = .none
		
Zach Knox's avatar
Zach Knox committed
100
101
102
103
		let schedule = Utilities.getCurrentSchedule(facility)
		let openTime = schedule!.openTimes[indexPath.row]
		cell.textLabel?.text = Utilities.getDayOfWeek(Day(rawValue: openTime.startDay)!)
		cell.detailTextLabel?.text = Utilities.getFormattedStartandEnd(openTime)
104

Zac Wood's avatar
Zac Wood committed
105
106
        cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .headline)
        cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .body)
107

108
        return cell
109
    }
110
111
			
	func markAsFavoritePreviewAction(_ sendingAction: UIPreviewAction, sender: UIViewController) {
Zach Knox's avatar
Zach Knox committed
112
		if(Utilities.isFavoriteFacility(facility)) {
113
			_ = Utilities.removeFavoriteFacility(facility)
Zach Knox's avatar
Zach Knox committed
114
115
		}
		else {
116
			_ = Utilities.addFavoriteFacility(facility)
Zach Knox's avatar
Zach Knox committed
117
		}
118
	}
119
}