Skip to content

Commit

Permalink
Merge pull request #582 from pennlabs/laundry-fixes
Browse files Browse the repository at this point in the history
Finish temporary laundry fixes
  • Loading branch information
anli5005 authored Dec 15, 2024
2 parents f466ac3 + 64f61b4 commit b14ca62
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
8 changes: 4 additions & 4 deletions PennMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = navigation;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.8;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.9;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = PennMobile/PennMobile.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
Expand Down Expand Up @@ -2895,7 +2895,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = navigation;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.8;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.9;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = PennMobile/PennMobile.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
Expand Down Expand Up @@ -3027,7 +3027,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = navigation;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.8;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.9;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
Expand Down Expand Up @@ -3070,7 +3070,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = navigation;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.8;
CF_BUNDLE_SHORT_VERSION_STRING = 8.0.9;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/Laundry/Cells/LaundryMachineCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LaundryMachineCell: UICollectionViewCell {
} else {
timerLabel.text = ""
}
idLabel.text = "#\(machine.id)"
// idLabel.text = "#\(machine.id)"

bellView.isHidden = !machine.isUnderNotification()
}
Expand Down
47 changes: 33 additions & 14 deletions PennMobile/Laundry/Networking/LaundryAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ class LaundryAPIService: Requestable {
fileprivate let statusURL = "https://pennmobile.org/api/laundry/status"

public var idToRooms: [Int: LaundryRoom]?

private func getCachedLaundryRooms() -> [Int: LaundryRoom]? {
let key = "laundryDataUpgraded"
if !UserDefaults.standard.bool(forKey: key) {
Storage.remove(LaundryRoom.directory, from: .caches)
UserDefaults.standard.set(true, forKey: key)
} else if Storage.fileExists(LaundryRoom.directory, in: .caches) {
return try? Storage.retrieveThrowing(LaundryRoom.directory, from: .caches, as: Dictionary<Int, LaundryRoom>.self)
}

return nil
}

// Prepare the service
func prepare(_ completion: @escaping () -> Void) {
if Storage.fileExists(LaundryRoom.directory, in: .caches) {
self.idToRooms = Storage.retrieve(LaundryRoom.directory, from: .caches, as: Dictionary<Int, LaundryRoom>.self)
if let cached = getCachedLaundryRooms() {
self.idToRooms = cached
completion()
} else {
loadIds { (_) in
Expand Down Expand Up @@ -61,20 +73,27 @@ class LaundryAPIService: Requestable {
// MARK: - Fetch API
extension LaundryAPIService {
func fetchLaundryData(for ids: [Int], _ callback: @escaping (_ rooms: [LaundryRoom]?) -> Void) {
let ids: String = ids.map { String($0) }.joined(separator: ",")
let url = "\(laundryUrl)/\(ids)"
getRequest(url: url) { (dict, _, _) in
var rooms: [LaundryRoom]?
if let dict = dict {
let json = JSON(dict)
let jsonArray = json["rooms"].arrayValue
rooms = [LaundryRoom]()
for json in jsonArray {
let room = LaundryRoom(json: json)
rooms?.append(room)
var rooms = [LaundryRoom]()
var requestsCompleted = 0

for id in ids {
getRequest(url: "\(laundryUrl)/\(id)") { (dict, _, _) in
DispatchQueue.main.async {
if let dict = dict {
let json = JSON(dict)
let jsonArray = json["rooms"].arrayValue
for json in jsonArray {
let room = LaundryRoom(json: json)
rooms.append(room)
}
}

requestsCompleted += 1
if requestsCompleted == ids.count {
callback(rooms)
}
}
}
callback(rooms)
}
}

Expand Down
10 changes: 5 additions & 5 deletions PennMobileShared/Laundry/LaundryMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class LaundryMachine: Hashable, Codable {
case outOfOrder = "out_of_order"

static func parseStatus(for status: String) -> Status {
if status == "Not online" {
return .offline
} else if status == "Almost done" || status == "In use" {
if status == "AVAILABLE" || status == "COMPLETE" {
return .open
} else if status == "IN_USE" {
return .running
} else if status == "Out of order" {
} else if status == "OUT_OF_ORDER" {
return .outOfOrder
} else {
return .open
return .offline
}
}
}
Expand Down

0 comments on commit b14ca62

Please sign in to comment.