Skip to content

Commit e8891ac

Browse files
committed
Many bug fixes and improvements
1 parent 5d4bc3f commit e8891ac

File tree

11 files changed

+1325
-734
lines changed

11 files changed

+1325
-734
lines changed

HackFSU/AppDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import AlamofireNetworkActivityIndicator
1011

1112
@UIApplicationMain
1213
class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -17,6 +18,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1718
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1819
// Override point for customization after application launch.
1920

21+
NetworkActivityIndicatorManager.sharedManager.isEnabled = true
22+
2023
// change navigation item title color
2124
let navigationBarAppearace = UINavigationBar.appearance()
2225
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

HackFSU/HFCountdownManager.swift

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
//
88

99
import Foundation
10-
import Alamofire
11-
import SwiftyJSON
12-
import UIKit
1310

1411
class HFCountdownManager {
1512

@@ -33,48 +30,8 @@ class HFCountdownManager {
3330
arrayOfCountdownTimes.append(endingCountdownItem)
3431

3532
self.updateCurentInformationWithCurrentArray()
36-
37-
//callAlamo(NSURL(string: "https://hackfsu.com/api/hackathon/get/countdowns")!)
3833
}
3934

40-
func callAlamo(url : NSURL) {
41-
Alamofire.request(.GET, url, encoding: .JSON).validate().responseJSON(completionHandler: {
42-
response in
43-
self.parseResults(JSON(response.result.value!), url: url)
44-
45-
})
46-
}
47-
//
48-
func parseResults(theJSON : JSON, url: NSURL) {
49-
for result in theJSON["countdowns"].arrayValue {
50-
let startTime = result["start"].stringValue
51-
let endTime = result["end"].stringValue
52-
53-
arrayOfCountdownTimes.removeAll()
54-
55-
let dateFormatterPrint = NSDateFormatter()
56-
dateFormatterPrint.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
57-
58-
let date: NSDate? = dateFormatterPrint.dateFromString(startTime)
59-
let dateTwo: NSDate? = dateFormatterPrint.dateFromString(endTime)
60-
61-
// print(dateFormatterPrint.stringFromDate(date!))
62-
// print(dateFormatterPrint.stringFromDate(dateTwo!))
63-
64-
let startingCountdownItem = HFCountdownItem(time: date!, name: "Until Hacking Starts")
65-
let endingCountdownItem = HFCountdownItem(time: dateTwo!, name: "Until Hacking Ends")
66-
67-
arrayOfCountdownTimes.append(startingCountdownItem)
68-
arrayOfCountdownTimes.append(endingCountdownItem)
69-
70-
self.updateCurentInformationWithCurrentArray()
71-
newItemsAvailble = true
72-
let login = HFCountdownViewController()
73-
login.checkForNewTimes()
74-
75-
}
76-
}
77-
7835
func getHackingStartTime() -> NSDate {
7936
return self.arrayOfCountdownTimes[0].getCountdownTime()
8037
}

HackFSU/HFFeedViewController.swift

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Glyptodon
1111
import FlatUIKit
1212
import Alamofire
1313
import SwiftyJSON
14+
import ReachabilitySwift
1415

1516
class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
1617

@@ -32,8 +33,11 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
3233
var refreshControl: UIRefreshControl!
3334
var alamoCalled = false;
3435
var didFinishFetching = false;
36+
var wasntAbleToConnectFirst = false
3537

38+
var reachability: Reachability?
3639

40+
var thursdayFeedArray:[HFScheduleItem] = [HFScheduleItem]()
3741
var fridayFeedArray:[HFScheduleItem] = [HFScheduleItem]()
3842
var saturdayFeedArray:[HFScheduleItem] = [HFScheduleItem]()
3943
var sundayFeedArray:[HFScheduleItem] = [HFScheduleItem]()
@@ -78,38 +82,40 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
7882

7983
callAlamo(apiURL)
8084
callAlamo(scheduleapiURL);
81-
82-
83-
84-
8585
}
8686

87-
8887
func checkForContent() {
8988
if didFinishFetching == false {
9089
feedTableView.alpha = 0.0
9190
tableViewContainerView.glyptodon.show("Loading Feed.\nPlease Wait.")
92-
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
9391
} else {
9492
tableViewContainerView.glyptodon.hide()
95-
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
9693
feedTableView.alpha = 1.0
9794
}
9895
}
9996

10097
func refresh(sender:AnyObject) {
10198
// Code to refresh table view
102-
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
10399
self.titles.removeAll()
104100
self.contents.removeAll()
105101
self.updatesDates.removeAll()
102+
103+
self.thursdayFeedArray.removeAll()
104+
self.fridayFeedArray.removeAll()
105+
self.saturdayFeedArray.removeAll()
106+
self.sundayFeedArray.removeAll()
107+
self.scheduleNames.removeAll()
108+
109+
self.feedTableView.reloadData()
110+
106111
callAlamo(apiURL)
112+
callAlamo(scheduleapiURL)
113+
107114
if (alamoCalled == true) {
108115
let delay = 0.75 * Double(NSEC_PER_SEC)
109116
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
110117
dispatch_after(time, dispatch_get_main_queue()) {
111118
self.refreshControl.endRefreshing()
112-
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
113119
self.feedTableView.reloadData()
114120
}
115121
self.alamoCalled = false
@@ -124,16 +130,53 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
124130
override func viewDidAppear(animated: Bool) {
125131
//getUpdatesFromParse()
126132
//callAlamo(apiURL)
127-
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
133+
do {
134+
reachability = try Reachability.reachabilityForInternetConnection()
135+
} catch {
136+
print("Unable to create Reachability")
137+
return
138+
}
139+
140+
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:",name: ReachabilityChangedNotification,object: reachability)
141+
do{
142+
try reachability?.startNotifier()
143+
}catch{
144+
print("could not start reachability notifier")
145+
}
146+
147+
}
148+
149+
func reachabilityChanged(note: NSNotification) {
150+
151+
let reachability = note.object as! Reachability
152+
153+
if reachability.isReachable() && wasntAbleToConnectFirst == true {
154+
checkForContent()
155+
refresh(self)
156+
} else {
157+
print("Network not reachable")
158+
}
128159
}
129160

130161
func callAlamo(url : NSURL) {
131162
Alamofire.request(.GET, url, encoding: .JSON).validate().responseJSON(completionHandler: {
132-
133163
response in
134-
self.parseResults(JSON(response.result.value!), url: url)
135-
self.alamoCalled = true
136-
164+
165+
switch response.result {
166+
case .Success(let json):
167+
self.parseResults(JSON(response.result.value!), url: url)
168+
self.alamoCalled = true
169+
case .Failure(let error):
170+
if let err = error as? NSURLError where err == .NotConnectedToInternet {
171+
// no internet connection
172+
self.feedTableView.alpha = 0.0
173+
self.tableViewContainerView.glyptodon.show("No Internet Connection")
174+
} else {
175+
// other failures
176+
print("fuck")
177+
}
178+
self.wasntAbleToConnectFirst = true
179+
}
137180
})
138181
}
139182

@@ -163,7 +206,16 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
163206

164207
let thaTime = theTIMEBIH(startTime, formatIn: formatInput, formatOut: "yyyy-MM-dd");
165208

166-
if thaTime.rangeOfString("2017-02-17") != nil{
209+
if thaTime.rangeOfString("2017-02-16") != nil {
210+
let finalStartTime = theTIMEBIH(startTime, formatIn: formatInput, formatOut: "h:mm a");
211+
212+
let newScheduleItem = HFScheduleItem(title: name,
213+
subtitle: description,
214+
start: finalStartTime)
215+
self.thursdayFeedArray.append(newScheduleItem)
216+
}
217+
218+
else if thaTime.rangeOfString("2017-02-17") != nil{
167219
let finalStartTime = theTIMEBIH(startTime, formatIn: formatInput, formatOut: "h:mm a");
168220

169221
let newScheduleItem = HFScheduleItem(title: name,
@@ -186,12 +238,12 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
186238
let newScheduleItem = HFScheduleItem(title: name,
187239
subtitle: description,
188240
start: finalStartTime)
241+
self.didFinishFetching = true
189242
self.sundayFeedArray.append(newScheduleItem)
190243
}
191244
}
192245

193246
}
194-
self.didFinishFetching = true
195247
checkForContent()
196248
self.feedTableView.reloadData()
197249
}
@@ -206,7 +258,7 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
206258
case update:
207259
return titles.count
208260
case scheudle:
209-
return 3
261+
return 4
210262
default: return 0
211263
}
212264
}
@@ -217,12 +269,14 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
217269
return 1
218270
} else {
219271
if section == 0 {
220-
return fridayFeedArray.count
272+
return thursdayFeedArray.count
221273
} else if section == 1 {
222-
return saturdayFeedArray.count
274+
return fridayFeedArray.count
223275
} else if section == 2 {
276+
return saturdayFeedArray.count
277+
} else if section == 3 {
224278
return sundayFeedArray.count
225-
} else {
279+
}else {
226280
return 0
227281
}
228282
}
@@ -260,13 +314,16 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
260314
let scheduleItem:HFScheduleItem!
261315

262316
if indexPath.section == 0 {
263-
scheduleItem = fridayFeedArray[indexPath.row]
317+
scheduleItem = thursdayFeedArray[indexPath.row]
264318
} else if indexPath.section == 1 {
265-
scheduleItem = saturdayFeedArray[indexPath.row]
319+
scheduleItem = fridayFeedArray[indexPath.row]
266320
} else if indexPath.section == 2 {
321+
scheduleItem = saturdayFeedArray[indexPath.row]
322+
} else if indexPath.section == 3 {
267323
scheduleItem = sundayFeedArray[indexPath.row]
268-
} else {
269-
scheduleItem = fridayFeedArray[indexPath.row]
324+
}
325+
else {
326+
scheduleItem = thursdayFeedArray[indexPath.row]
270327
// SWITCH TO A DEFAULT ITEM
271328
}
272329

@@ -277,19 +334,25 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
277334
if indexPath.row == 0 {
278335
cell.configureFlatCellWithColor(tempCellColor, selectedColor: tempCellColor, roundingCorners: [.TopLeft, .TopRight])
279336
cell.cornerRadius = 3.5
280-
} else if indexPath.section == 0 && indexPath.row == fridayFeedArray.count - 1 {
337+
} else if indexPath.section == 0 && indexPath.row == thursdayFeedArray.count - 1 {
338+
cell.configureFlatCellWithColor(tempCellColor, selectedColor: tempCellColor, roundingCorners: [.BottomLeft,
339+
.BottomRight])
340+
cell.cornerRadius = 3.5
341+
} else if indexPath.section == 1 && indexPath.row == fridayFeedArray.count - 1 {
281342
cell.configureFlatCellWithColor(tempCellColor, selectedColor: tempCellColor, roundingCorners: [.BottomLeft,
282343
.BottomRight])
283344
cell.cornerRadius = 3.5
284-
} else if indexPath.section == 1 && indexPath.row == saturdayFeedArray.count - 1 {
345+
} else if indexPath.section == 2 && indexPath.row == saturdayFeedArray.count - 1 {
285346
cell.configureFlatCellWithColor(tempCellColor, selectedColor: tempCellColor, roundingCorners: [.BottomLeft,
286347
.BottomRight])
287348
cell.cornerRadius = 3.5
288-
} else if indexPath.section == 2 && indexPath.row == sundayFeedArray.count - 1 {
349+
} else if indexPath.section == 3 && indexPath.row == sundayFeedArray.count - 1 {
289350
cell.configureFlatCellWithColor(tempCellColor, selectedColor: tempCellColor, roundingCorners: [.BottomLeft,
290351
.BottomRight])
291352
cell.cornerRadius = 3.5
292-
} else {
353+
}
354+
355+
else {
293356
cell.configureFlatCellWithColor(tempCellColor, selectedColor: tempCellColor, roundingCorners: .AllCorners)
294357
cell.cornerRadius = 0
295358
}
@@ -320,10 +383,12 @@ class HFFeedViewController: UIViewController, UITableViewDelegate, UITableViewDa
320383
cell.backgroundColor = UIColor.colorFromHex(0xEDECF3) // CLEAR
321384

322385
if section == 0 {
323-
cell.headerLabel.text = "Friday"
386+
cell.headerLabel.text = "Thursday"
324387
} else if section == 1 {
325-
cell.headerLabel.text = "Saturday"
388+
cell.headerLabel.text = "Friday"
326389
} else if section == 2 {
390+
cell.headerLabel.text = "Saturday"
391+
} else if section == 3 {
327392
cell.headerLabel.text = "Sunday"
328393
}
329394
return cell

0 commit comments

Comments
 (0)