Skip to content

Commit d66e95a

Browse files
authored
Merge pull request #203 from pennlabs/development
Development
2 parents c3caeac + a1f0a0d commit d66e95a

8 files changed

Lines changed: 41 additions & 19 deletions

File tree

PennMobile/GSR-Booking/Controllers/GSRWebviewLoginController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ class GSRWebviewLoginController: UIViewController, WKUIDelegate, WKNavigationDel
4848
if url.absoluteString == "https://apps.wharton.upenn.edu/gsr/" {
4949
let cookieStore = webView.configuration.websiteDataStore.httpCookieStore
5050
cookieStore.getAllCookies { (cookies) in
51-
for cookie in cookies {
52-
if cookie.name == "sessionid" {
53-
DispatchQueue.main.async {
51+
DispatchQueue.main.async {
52+
for cookie in cookies {
53+
if cookie.name == "sessionid" {
5454
UserDefaults.standard.set(sessionID: cookie.value)
5555
decisionHandler(.cancel)
5656
self.dismiss(animated: true, completion: nil)
5757
self.completion?()
5858
return
5959
}
6060
}
61+
decisionHandler(.allow)
6162
}
62-
decisionHandler(.allow)
6363
}
6464
} else {
6565
decisionHandler(.allow)

PennMobile/GSR-Booking/Networking/WhartonGSRNetworkManager.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@ class WhartonGSRNetworkManager: NSObject, Requestable {
4141
//data recieved and parsed successfully
4242
if let dict = json {
4343
let json = JSON(dict)
44-
if json["error"].string != nil {
44+
do {
45+
let rooms = try self.parseAvailabilityJSON(json)
46+
if !rooms.isEmpty {
47+
callback(rooms)
48+
return
49+
}
50+
} catch NetworkingError.authenticationError {
51+
// Clear session ID if no longer valid
4552
UserDefaults.standard.clearSessionID()
46-
self.getAvailabilityWithoutSessionID(date: date, callback: callback)
47-
} else {
48-
let rooms = try? self.parseAvailabilityJSON(json)
49-
callback(rooms)
53+
} catch {
5054
}
5155
}
52-
return
5356
}
5457
}
5558
}
56-
callback(nil)
59+
// Unless a valid set of rooms is returns, ping the server
60+
self.getAvailabilityWithoutSessionID(date: date, callback: callback)
5761
}
5862

5963
})
@@ -179,6 +183,9 @@ class WhartonGSRNetworkManager: NSObject, Requestable {
179183

180184
extension WhartonGSRNetworkManager {
181185
func parseAvailabilityJSON(_ json: JSON) throws -> [GSRRoom] {
186+
guard json["error"].string == nil else {
187+
throw NetworkingError.authenticationError
188+
}
182189
let timesJSONArray = json["times"].arrayValue.flatMap { $0.arrayValue }
183190
let timesArray = try timesJSONArray.map { (json) -> GSRTimeSlot in
184191
return try GSRTimeSlot(json: json)

PennMobile/General/Generics/StatusBar.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class StatusBar: UIView {
1818
enum statusBarText : String {
1919
case noInternet = "No Internet Connection"
2020
case apiError = "Penn servers are temporarily down.\nPlease try again later."
21+
case laundryDown = "Penn's laundry servers are currently not updating.\nWe hope this will be fixed shortly."
2122
}
2223

2324
public required init?(coder aDecoder: NSCoder) {

PennMobile/General/Networking + Analytics/Networking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum Method {
2121

2222
enum NetworkingError: String, LocalizedError {
2323
case jsonError = "JSON error"
24+
case authenticationError = "Unable to authenticate"
2425
case other
2526
var localizedDescription: String { return NSLocalizedString(self.rawValue, comment: "") }
2627
}

PennMobile/Laundry/Controllers/LaundryTableViewController.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class LaundryTableViewController: GenericTableViewController, IndicatorEnabled,
2626
tableView.allowsSelection = false
2727

2828
tableView.tableFooterView = getFooterViewForTable()
29+
// header view to make space for the error bar
30+
tableView.tableHeaderView = getHeaderViewForTable()
2931

3032
rooms = LaundryRoom.getPreferences()
3133

@@ -34,8 +36,6 @@ class LaundryTableViewController: GenericTableViewController, IndicatorEnabled,
3436

3537
// initialize navigation bar
3638

37-
38-
3939
// Start indicator if there are cells that need to be loaded
4040
if !rooms.isEmpty {
4141
showActivity()
@@ -52,6 +52,7 @@ class LaundryTableViewController: GenericTableViewController, IndicatorEnabled,
5252

5353
override func viewDidAppear(_ animated: Bool) {
5454
setupNavBar()
55+
self.navigationVC?.addPermanentStatusBar(text: .laundryDown)
5556
super.viewDidAppear(animated)
5657
}
5758

@@ -66,6 +67,12 @@ class LaundryTableViewController: GenericTableViewController, IndicatorEnabled,
6667
return v
6768
}
6869

70+
fileprivate func getHeaderViewForTable() -> UIView {
71+
let v = UIView(frame: CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: 70.0))
72+
v.backgroundColor = UIColor.clear
73+
return v
74+
}
75+
6976
private func setupNavBar() {
7077
self.tabBarController?.title = "Laundry"
7178
tabBarController?.navigationItem.leftBarButtonItem = nil

PennMobile/Setup + Navigation/AppDelegate.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2424

2525
if UserDefaults.standard.isNewAppVersion() {
2626
UserDefaults.standard.setAppVersion()
27-
LaundryAPIService.instance.clearDirectory()
28-
if let ids = UserDefaults.standard.getLaundryPreferences() {
29-
UserDBManager.shared.saveLaundryPreferences(for: ids)
30-
}
3127
}
3228

3329
DatabaseManager.shared.dryRun = true

PennMobile/Setup + Navigation/HomeNavigationController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class HomeNavigationController: UINavigationController {
2525
animateBarDown()
2626
}
2727

28+
func addPermanentStatusBar(text: StatusBar.statusBarText) {
29+
bar?.removeFromSuperview()
30+
bar = StatusBar(text: text)
31+
setupBar(text: text)
32+
guard bar != nil else { return }
33+
UIView.animate(withDuration: 0.4) {
34+
self.bar!.transform = CGAffineTransform(translationX: 0, y: CGFloat(self.bar!.height))
35+
}
36+
}
37+
2838
fileprivate func animateBarDown() {
2939
guard bar != nil else { return }
3040
bar!.isHidden = false

PennMobile/Supporting_Files/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>3.5</string>
20+
<string>3.5.1</string>
2121
<key>CFBundleVersion</key>
22-
<string>4651</string>
22+
<string>4653</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>NSAppTransportSecurity</key>

0 commit comments

Comments
 (0)