diff --git a/OBAKitCore/Collections/EmptyDataSetView.swift b/OBAKitCore/Collections/EmptyDataSetView.swift index 5f9f256e5..a644eb596 100644 --- a/OBAKitCore/Collections/EmptyDataSetView.swift +++ b/OBAKitCore/Collections/EmptyDataSetView.swift @@ -137,6 +137,12 @@ public class EmptyDataSetView: UIView { NSLayoutConstraint.activate([topConstraint, leadingConstraint, trailingConstraint, bottomConstraint, centerYConstraint]) layoutView() + + let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self] + registerForTraitChanges(sizeTraits) { (self: Self, _) in + self.layoutView() + } + } required init?(coder: NSCoder) { @@ -155,11 +161,6 @@ public class EmptyDataSetView: UIView { layoutIfNeeded() } - public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - self.layoutView() - } - // MARK: - Configure with error public func configure(with error: Error, icon: UIImage? = nil, buttonConfig: ActivityIndicatedButton.Configuration? = nil) { self.bodyLabel.text = error.localizedDescription diff --git a/OBAKitCore/DataMigration/DataMigrator.swift b/OBAKitCore/DataMigration/DataMigrator.swift index 0fa332bb7..0c47bf882 100644 --- a/OBAKitCore/DataMigration/DataMigrator.swift +++ b/OBAKitCore/DataMigration/DataMigrator.swift @@ -145,7 +145,7 @@ public class DataMigrator { // ╚═══════════════╝ // The API service must be configured to the same region as parameters.regionIdentifier. - guard let apiServiceRegionIdentifier = apiService.configuration.regionIdentifier, + guard let apiServiceRegionIdentifier = await apiService.configuration.regionIdentifier, apiServiceRegionIdentifier == parameters.regionIdentifier else { throw DataMigrationError.invalidAPIService("The API must be configured to the same region as parameters.regionIdentifier") } diff --git a/OBAKitCore/Extensions/UIKitExtensions.swift b/OBAKitCore/Extensions/UIKitExtensions.swift index 27e9dfb9e..1cbbf551f 100644 --- a/OBAKitCore/Extensions/UIKitExtensions.swift +++ b/OBAKitCore/Extensions/UIKitExtensions.swift @@ -521,7 +521,6 @@ public extension UIViewController { func removeChildController(_ controller: UIViewController) { controller.willMove(toParent: nil) controller.view.removeFromSuperview() - setOverrideTraitCollection(nil, forChild: controller) controller.removeFromParent() } diff --git a/OBAKitCore/Network/ObacoAPIService.swift b/OBAKitCore/Network/ObacoAPIService.swift index ddbf6e592..ab18bb407 100644 --- a/OBAKitCore/Network/ObacoAPIService.swift +++ b/OBAKitCore/Network/ObacoAPIService.swift @@ -53,17 +53,18 @@ public actor ObacoAPIService: @preconcurrency APIService { self.dataLoader = dataLoader } - private nonisolated func buildURL(path: String, queryItems: [URLQueryItem] = []) -> URL { - var components = URLComponents(url: configuration.baseURL, resolvingAgainstBaseURL: false)! + private nonisolated func buildURL(path: String, queryItems: [URLQueryItem] = []) async -> URL { + let baseURL = await configuration.baseURL + var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)! components.appendPath(path) - components.queryItems = configuration.defaultQueryItems + queryItems + components.queryItems = await configuration.defaultQueryItems + queryItems return components.url! } public nonisolated func getWeather() async throws -> WeatherForecast { let path = String(format: "/api/v1/regions/%d/weather.json", regionID) - let url = buildURL(path: path) + let url = await buildURL(path: path) return try await getData(for: url, decodeAs: WeatherForecast.self, using: JSONDecoder.obacoServiceDecoder) } @@ -87,7 +88,7 @@ public actor ObacoAPIService: @preconcurrency APIService { email: String, testMode: Bool ) async throws -> PaymentIntentResponse { - let url = buildURL(path: "/api/v1/payment_intents") + let url = await buildURL(path: "/api/v1/payment_intents") let urlRequest = NSMutableURLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10) urlRequest.httpMethod = "POST" @@ -115,7 +116,7 @@ public actor ObacoAPIService: @preconcurrency APIService { stopSequence: Int, userPushID: String ) async throws -> Alarm { - let url = buildURL(path: String(format: "/api/v1/regions/%d/alarms", regionID)) + let url = await buildURL(path: String(format: "/api/v1/regions/%d/alarms", regionID)) let urlRequest = NSMutableURLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10) urlRequest.httpMethod = "POST" @@ -147,7 +148,7 @@ public actor ObacoAPIService: @preconcurrency APIService { // MARK: - Vehicles public nonisolated func getVehicles(matching query: String) async throws -> [AgencyVehicle] { let apiPath = String(format: "/api/v1/regions/%d/vehicles", regionID) - let url = buildURL(path: apiPath, queryItems: [URLQueryItem(name: "query", value: query)]) + let url = await buildURL(path: apiPath, queryItems: [URLQueryItem(name: "query", value: query)]) return try await getData(for: url, decodeAs: [AgencyVehicle].self, using: JSONDecoder.obacoServiceDecoder) } @@ -156,10 +157,10 @@ public actor ObacoAPIService: @preconcurrency APIService { public func getAlerts(agencies: [AgencyWithCoverage]) async throws -> [AgencyAlert] { let queryItems = self.shouldDisplayRegionTestAlerts ? [URLQueryItem(name: "test", value: "1")] : [] let apiPath = String(format: "/api/v1/regions/%d/alerts.pb", regionID) - let url = buildURL(path: apiPath, queryItems: queryItems) + let url = await buildURL(path: apiPath, queryItems: queryItems) let (data, _) = try await getData(for: url) - let message = try TransitRealtime_FeedMessage(serializedData: data) + let message = try TransitRealtime_FeedMessage(serializedBytes: data) let entities = message.entity var qualifiedEntities: [TransitRealtime_FeedEntity] = [] diff --git a/OBAKitCore/UI/PaddingLabel.swift b/OBAKitCore/UI/PaddingLabel.swift index aeeda63fa..b4d6a179f 100644 --- a/OBAKitCore/UI/PaddingLabel.swift +++ b/OBAKitCore/UI/PaddingLabel.swift @@ -30,11 +30,15 @@ public class PaddingLabel: UILabel { public init(insets: UIEdgeInsets) { self.insets = insets super.init(frame: .zero) + + registerForTraitChanges() } override public init(frame: CGRect) { self.insets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8) super.init(frame: frame) + + registerForTraitChanges() } required init?(coder: NSCoder) { @@ -53,9 +57,10 @@ public class PaddingLabel: UILabel { height: size.height + insets.top + insets.bottom) } - override public func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - configure() + func registerForTraitChanges() { + registerForTraitChanges([UITraitAccessibilityContrast.self]) { (self: Self, _) in + self.configure() + } } func configure() { diff --git a/OBAKitCore/Utilities/Logger.swift b/OBAKitCore/Utilities/Logger.swift index 0339f0537..b5e9ee738 100644 --- a/OBAKitCore/Utilities/Logger.swift +++ b/OBAKitCore/Utilities/Logger.swift @@ -32,7 +32,7 @@ import CocoaLumberjackSwift } func info(_ message: String) { - DDLogInfo(message) + DDLogInfo("\(message)") } // MARK: - Warn @@ -42,7 +42,7 @@ import CocoaLumberjackSwift } func warn(_ message: String) { - DDLogWarn(message) + DDLogWarn("\(message)") } // MARK: - Error @@ -52,6 +52,6 @@ import CocoaLumberjackSwift } func error(_ message: String) { - DDLogError(message) + DDLogError("\(message)") } }