Skip to content

Commit 13ba7ef

Browse files
committed
Various refactors
1 parent 6337050 commit 13ba7ef

5 files changed

+137
-123
lines changed

Sfest-swift/BandDatabase.swift

+16-11
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import Foundation
1010
class BandDatabase {
1111

1212
class var sharedInstance:BandDatabase {
13-
struct Static {
14-
static let instance : BandDatabase = BandDatabase()
13+
14+
struct Static {
15+
static let instance : BandDatabase = BandDatabase()
1516
}
17+
1618
return Static.instance
1719
}
1820

@@ -33,20 +35,23 @@ class BandDatabase {
3335

3436
// Prepare statement
3537
result = sqlite3_prepare_v2(handle, cString!, -1, &statement, nil)
38+
3639
if (result != SQLITE_OK) {
3740
sqlite3_finalize(statement)
3841
print("Error")
3942
}
40-
41-
while (sqlite3_step(statement) == SQLITE_ROW) {
42-
let timeCharacters = UnsafePointer<Int8> (sqlite3_column_text(statement, 2))
43-
let bandCharacters = UnsafePointer<Int8> (sqlite3_column_text(statement, 4))
44-
let time = String.fromCString(timeCharacters)
45-
let band = String.fromCString(bandCharacters)
46-
let tuple = (band:band!, time:time!)
47-
results.append(tuple)
48-
43+
else
44+
{
45+
while (sqlite3_step(statement) == SQLITE_ROW) {
46+
let timeCharacters = UnsafePointer<Int8> (sqlite3_column_text(statement, 2))
47+
let bandCharacters = UnsafePointer<Int8> (sqlite3_column_text(statement, 4))
48+
let time = String.fromCString(timeCharacters)
49+
let band = String.fromCString(bandCharacters)
50+
let tuple = (band:band!, time:time!)
51+
results.append(tuple)
52+
}
4953
}
54+
5055
return results
5156
}
5257
}

Sfest-swift/DailyViewController.swift

+31-39
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,19 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
2626
var selectedIndex: NSIndexPath?
2727
var stageName: String?
2828
var stageColor: UIColor?
29-
var complimentaryColor: UIColor?
3029
var globalDate : NSDate?
3130
var delegate: DateChangedDelegate?
3231
var tableViewController: TableViewController?
3332
var mapView: MapView?
34-
35-
required init(coder aDecoder: NSCoder) {
36-
super.init(coder: aDecoder)
37-
}
38-
33+
3934
override func viewDidLoad() {
4035
super.viewDidLoad()
4136
globalDate = dateTest(NSDate())
4237
setupViews()
4338
gestureRecognizers()
39+
tableViewController = childViewControllers[0] as? TableViewController
40+
self.delegate = tableViewController
41+
delegate?.dateChanged(stageName!, date: convertDateToStrings(globalDate!).queryDateString)
4442
}
4543

4644
override func viewDidAppear(animated: Bool) {
@@ -52,7 +50,7 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
5250
}, completion: {
5351
finished in
5452
animateView.removeFromSuperview()
55-
})
53+
})
5654
}
5755

5856
override func preferredStatusBarStyle() -> UIStatusBarStyle {
@@ -61,21 +59,13 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
6159

6260
func setupViews() {
6361
//Stage
64-
stageView.backgroundColor = stageColor!
65-
stageNameLabel.text = stageName!
66-
if (stageNameLabel.text == "Johnson Controls World Sound Stage") {
67-
stageNameLabel.font = UIFont(name: "Futura", size: 16)
68-
}
62+
stageView.backgroundColor = stageColor
63+
stageNameLabel.text = stageName
64+
6965
//Date
7066
dayOfTheWeekLabel!.text = convertDateToStrings(globalDate!).dayOfTheWeek
7167
dateLabel!.text = convertDateToStrings(globalDate!).longDateString
72-
dateView.backgroundColor = complimentaryColor!
73-
74-
//TableView Subview
75-
tableViewController = TableViewController(stage: stageName!, date: convertDateToStrings(globalDate!).queryDateString, complimentaryColor: complimentaryColor!)
76-
self.addChildViewController(tableViewController!)
77-
self.view.addSubview(tableViewController!.view)
78-
tableViewController!.didMoveToParentViewController(self)
68+
dateView.backgroundColor = NSUserDefaults.standardUserDefaults().colorForKey("complimentaryColor")
7969

8070
//Close Button
8171
view.bringSubviewToFront(closeButton)
@@ -93,26 +83,11 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
9383
}
9484

9585
func close() {
96-
if (mapView?.frame.origin.y == 45){
86+
if (mapView?.frame.origin.y == 45) {
9787
hideMapView(closeButton)
9888
}
9989
else {
100-
let backgroundImageView:UIImageView = UIImageView(image: backgroundImage!)
101-
view.addSubview(backgroundImageView)
102-
let animateView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height))
103-
animateView.backgroundColor = stageColor!
104-
view.addSubview(animateView)
105-
UIView.animateWithDuration(0.5, animations: {
106-
animateView.frame = self.returnRectangle!
107-
animateView.alpha = 0.5
108-
}, completion: {
109-
finished in
110-
animateView.removeFromSuperview()
111-
backgroundImageView.removeFromSuperview()
112-
let stageViewController = self.navigationController!.viewControllers[0] as! StageViewController
113-
stageViewController.savedScrollPosition = self.savedScrollPosition!
114-
self.navigationController!.popToRootViewControllerAnimated(false)
115-
})
90+
popToStageViewController()
11691
}
11792
}
11893

@@ -124,6 +99,25 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
12499
close()
125100
}
126101

102+
func popToStageViewController() {
103+
let backgroundImageView:UIImageView = UIImageView(image: backgroundImage!)
104+
view.addSubview(backgroundImageView)
105+
let animateView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height))
106+
animateView.backgroundColor = stageColor
107+
view.addSubview(animateView)
108+
UIView.animateWithDuration(0.5, animations: {
109+
animateView.frame = self.returnRectangle!
110+
animateView.alpha = 0.5
111+
}, completion: {
112+
finished in
113+
animateView.removeFromSuperview()
114+
backgroundImageView.removeFromSuperview()
115+
let stageViewController = self.navigationController!.viewControllers[0] as! StageViewController
116+
stageViewController.savedScrollPosition = self.savedScrollPosition!
117+
self.navigationController!.popToRootViewControllerAnimated(false)
118+
})
119+
}
120+
127121
func dateTest(aDate:NSDate) -> NSDate {
128122
let dateComponents = NSDateComponents()
129123
dateComponents.calendar = NSCalendar.currentCalendar()
@@ -156,7 +150,6 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
156150
globalDate = dateTest(globalDate!.dateByAddingTimeInterval(24*60*60))
157151
dayOfTheWeekLabel!.text = convertDateToStrings(globalDate!).dayOfTheWeek
158152
dateLabel!.text = convertDateToStrings(globalDate!).longDateString
159-
self.delegate = tableViewController
160153
delegate?.dateChanged(stageName!, date: convertDateToStrings(globalDate!).queryDateString)
161154
}
162155

@@ -168,11 +161,10 @@ class DailyViewController: UIViewController, UIGestureRecognizerDelegate {
168161
globalDate = dateTest(globalDate!.dateByAddingTimeInterval(-24*60*60))
169162
dayOfTheWeekLabel!.text = convertDateToStrings(globalDate!).dayOfTheWeek
170163
dateLabel!.text = convertDateToStrings(globalDate!).longDateString
171-
self.delegate = tableViewController
172164
delegate?.dateChanged(stageName!, date: convertDateToStrings(globalDate!).queryDateString)
173165
}
174166

175-
func convertDateToStrings(date:NSDate)-> (queryDateString:String, longDateString:String, dayOfTheWeek:String) {
167+
func convertDateToStrings(date:NSDate) -> (queryDateString:String, longDateString:String, dayOfTheWeek:String) {
176168
let dateFormatter = NSDateFormatter()
177169
dateFormatter.dateFormat = "M/d/yyyy"
178170
let queryString = dateFormatter.stringFromDate(date)

Sfest-swift/MapView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import UIKit
99
import MapKit
1010
import CoreLocation
11-
import AddressBook
11+
import Contacts
1212

1313
class MapView: MKMapView, CLLocationManagerDelegate {
1414

@@ -85,7 +85,7 @@ class MapPoint: NSObject, MKAnnotation {
8585
}
8686

8787
func mapItem() -> MKMapItem {
88-
let addressDictionary = [kABPersonAddressStreetKey as String : ""]
88+
let addressDictionary = [CNContactPostalAddressesKey as String : ""]
8989
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
9090
let mapItem = MKMapItem(placemark: placemark)
9191
mapItem.name = title

Sfest-swift/StageViewController.swift

+71-45
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,35 @@
77

88
import UIKit
99

10+
extension NSUserDefaults {
11+
12+
func colorForKey(key: String) -> UIColor? {
13+
var color: UIColor?
14+
if let colorData = dataForKey(key) {
15+
color = NSKeyedUnarchiver.unarchiveObjectWithData(colorData) as? UIColor
16+
}
17+
return color
18+
}
19+
20+
func setColor(color: UIColor?, forKey key: String) {
21+
var colorData: NSData?
22+
if let color = color {
23+
colorData = NSKeyedArchiver.archivedDataWithRootObject(color)
24+
}
25+
setObject(colorData, forKey: key)
26+
}
27+
28+
}
29+
30+
class StageCollectionViewCell: UICollectionViewCell {
31+
@IBOutlet var stageNameLabel: UILabel!
32+
}
33+
1034
class StageViewController: UICollectionViewController {
1135

12-
var savedScrollPosition: CGPoint = CGPoint(x: 0, y: 0)
36+
var savedScrollPosition = CGPoint(x: 0, y: 0)
37+
let stagesArray = ["BMO Harris Pavilion", "Briggs & Stratton Big Backyard", "Harley-Davidson Roadhouse", "Johnson Controls World Sound Stage", "Marcus Amphitheater", "Miller Lite Oasis", "U.S. Cellular Connection Stage", "Uline Warehouse"]
38+
let colorsArray = [UIColor(red: 255.00/255.00, green: 85.00/255.00, blue: 55.00/255.00, alpha: 1.0), UIColor(red: 255.00/255.00, green: 103.00/255.00, blue: 77.00/255.00, alpha: 1.0), UIColor(red: 255.00/255.00, green: 200.00/255.00, blue: 5.00/255.00, alpha: 1.0), UIColor(red: 255.00/255.00, green: 217.00/255.00, blue: 1.00/255.00, alpha: 1.0), UIColor(red: 0.00/255.00, green: 212.00/255.00, blue: 251.00/255.00, alpha: 1.0), UIColor(red: 0.00/255.00, green: 189.00/255.00, blue: 235.00/255.00, alpha: 1.0), UIColor(red: 3.00/255.00, green: 237.00/255.00, blue: 152.00/255.00, alpha: 1.0), UIColor(red: 0.00/255.00, green: 251.00/255.00, blue: 174.00/255.00, alpha: 1.0)]
1339

1440
override func viewDidLoad() {
1541
super.viewDidLoad()
@@ -29,76 +55,77 @@ class StageViewController: UICollectionViewController {
2955
}
3056

3157
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
32-
return 8
58+
return stagesArray.count
59+
}
60+
61+
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
62+
let halfWidth = UIScreen.mainScreen().bounds.size.width / 2
63+
return CGSize(width: halfWidth, height: halfWidth)
3364
}
3465

3566
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
36-
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("stage", forIndexPath: indexPath) as UICollectionViewCell
37-
let stageLabel = cell.viewWithTag(1) as! UILabel
38-
stageLabel.text = stageTupleAtIndex(indexPath).stageName
39-
cell.backgroundColor = stageTupleAtIndex(indexPath).color
40-
cell.addSubview(stageLabel)
67+
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("stage", forIndexPath: indexPath) as! StageCollectionViewCell
68+
cell.backgroundColor = colorsArray[indexPath.row]
69+
cell.stageNameLabel.text = stagesArray[indexPath.row]
4170
return cell
4271
}
4372

4473
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
45-
let rect = collectionView.cellForItemAtIndexPath(indexPath)!.frame
74+
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! StageCollectionViewCell
75+
let rect = cell.frame
4676
let animateView = UIView(frame: CGRect(x: rect.origin.x, y: rect.origin.y - collectionView.contentOffset.y, width: rect.size.width, height: rect.size.height))
47-
animateView.backgroundColor = stageTupleAtIndex(indexPath).color
48-
let animateLabel = UILabel(frame: CGRect(x: 0.0, y:0.0, width: 320, height:160))
49-
animateLabel.text = stageTupleAtIndex(indexPath).stageName
50-
animateLabel.font = UIFont(name: "Futura", size: 19)
51-
if (animateLabel.text == "Johnson Controls World Sound Stage") {
52-
animateLabel.font = UIFont(name: "Futura", size: 16)
53-
}
54-
animateLabel.textColor = UIColor.whiteColor()
55-
animateLabel.textAlignment = NSTextAlignment.Center
77+
animateView.backgroundColor = colorsArray[indexPath.row]
78+
79+
let animateLabel = configureAnimateLabelWithFrame(cell.stageNameLabel.frame)
80+
animateLabel.text = stagesArray[indexPath.row]
5681
animateView.addSubview(animateLabel)
5782
self.view.addSubview(animateView)
58-
83+
5984
UIView.animateWithDuration(0.5, animations: {
6085
animateView.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height)
61-
animateLabel.frame = CGRect(x: 20, y: 15, width: 280, height: 26)
86+
animateView.subviews[0].frame = CGRect(x: 0.0, y: 5.0, width: UIScreen.mainScreen().bounds.size.width, height:45.0)
6287
}, completion: {
6388
finished in
6489
animateView.removeFromSuperview()
65-
let storyboard = UIStoryboard(name: "Main", bundle: nil)
66-
let dailyViewController = storyboard.instantiateViewControllerWithIdentifier("dvc") as! DailyViewController
67-
dailyViewController.backgroundImage = self.backgroundImage()
68-
dailyViewController.selectedIndex = indexPath
69-
dailyViewController.savedScrollPosition = collectionView.contentOffset
70-
let rect = collectionView.cellForItemAtIndexPath(indexPath)!.frame
71-
dailyViewController.returnRectangle = CGRect(x: rect.origin.x, y: rect.origin.y - collectionView.contentOffset.y, width: rect.size.width, height: rect.size.height)
72-
dailyViewController.stageName = animateLabel.text
73-
dailyViewController.stageColor = animateView.backgroundColor
74-
dailyViewController.complimentaryColor = self.complimentaryColor(indexPath)
75-
self.navigationController!.pushViewController(dailyViewController, animated: false)
90+
self.dailyViewTransitionWithStageIndex(indexPath)
7691
})
7792
}
7893

79-
func stageTupleAtIndex(index:NSIndexPath) -> (stageName:String, color:UIColor) {
80-
let stage1 = ("BMO Harris Pavilion", UIColor(red: 255.00/255.00, green: 85.00/255.00, blue: 55.00/255.00, alpha: 1.0))
81-
let stage2 = ("Briggs & Stratton Big Backyard", UIColor(red: 255.00/255.00, green: 103.00/255.00, blue: 77.00/255.00, alpha: 1.0))
82-
let stage3 = ("Harley-Davidson Roadhouse", UIColor(red: 255.00/255.00, green: 200.00/255.00, blue: 5.00/255.00, alpha: 1.0))
83-
let stage4 = ("Johnson Controls World Sound Stage", UIColor(red: 255.00/255.00, green: 217.00/255.00, blue: 1.00/255.00, alpha: 1.0))
84-
let stage5 = ("Marcus Amphitheater", UIColor(red: 0.00/255.00, green: 212.00/255.00, blue: 251.00/255.00, alpha: 1.0))
85-
let stage6 = ("Miller Lite Oasis", UIColor(red: 0.00/255.00, green: 189.00/255.00, blue: 235.00/255.00, alpha: 1.0))
86-
let stage7 = ("U.S. Cellular Connection Stage", UIColor(red: 3.00/255.00, green: 237.00/255.00, blue: 152.00/255.00, alpha: 1.0))
87-
let stage8 = ("Uline Warehouse", UIColor(red: 0.00/255.00, green: 251.00/255.00, blue: 174.00/255.00, alpha: 1.0))
88-
let stageArray = [stage1, stage2, stage3, stage4, stage5, stage6, stage7, stage8]
89-
return stageArray[index.row]
94+
func dailyViewTransitionWithStageIndex(index: NSIndexPath) {
95+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
96+
let dailyViewController = storyboard.instantiateViewControllerWithIdentifier("dvc") as! DailyViewController
97+
98+
dailyViewController.backgroundImage = self.backgroundImage()
99+
dailyViewController.selectedIndex = index
100+
dailyViewController.savedScrollPosition = collectionView!.contentOffset
101+
dailyViewController.stageName = stagesArray[index.row]
102+
dailyViewController.stageColor = colorsArray[index.row]
103+
104+
let rect = collectionView!.cellForItemAtIndexPath(index)!.frame
105+
dailyViewController.returnRectangle = CGRect(x: rect.origin.x, y: rect.origin.y - collectionView!.contentOffset.y, width: rect.size.width, height: rect.size.height)
106+
complimentaryColor(index)
107+
self.navigationController!.pushViewController(dailyViewController, animated: false)
90108
}
91109

92-
func complimentaryColor(index:NSIndexPath) -> UIColor {
110+
func configureAnimateLabelWithFrame(frame: CGRect) -> UILabel {
111+
let animateLabel = UILabel(frame: frame)
112+
animateLabel.font = UIFont(name: "Futura", size: 19)
113+
animateLabel.textColor = UIColor.whiteColor()
114+
animateLabel.textAlignment = NSTextAlignment.Center
115+
return animateLabel
116+
}
117+
118+
func complimentaryColor(index:NSIndexPath) {
93119
var i = 0
94120
switch(index.row){
95121
case 0, 2, 4, 6:
96122
i = 1
97123
default:
98124
i = -1
99125
}
100-
let complimentaryIndex = NSIndexPath(forRow: index.row+i, inSection: index.section)
101-
return stageTupleAtIndex(complimentaryIndex).color
126+
127+
NSUserDefaults.standardUserDefaults().setColor(colorsArray[index.row+i], forKey: "complimentaryColor")
128+
NSUserDefaults.standardUserDefaults().synchronize()
102129
}
103130

104131
func backgroundImage() -> UIImage {
@@ -114,4 +141,3 @@ class StageViewController: UICollectionViewController {
114141
}
115142

116143
}
117-

0 commit comments

Comments
 (0)