Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes several deprecation warnings #783

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions OBAKitCore/Collections/EmptyDataSetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OBAKitCore/DataMigration/DataMigrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
1 change: 0 additions & 1 deletion OBAKitCore/Extensions/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ public extension UIViewController {
func removeChildController(_ controller: UIViewController) {
controller.willMove(toParent: nil)
controller.view.removeFromSuperview()
setOverrideTraitCollection(nil, forChild: controller)
controller.removeFromParent()
}

Expand Down
19 changes: 10 additions & 9 deletions OBAKitCore/Network/ObacoAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand All @@ -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] = []
Expand Down
11 changes: 8 additions & 3 deletions OBAKitCore/UI/PaddingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions OBAKitCore/Utilities/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import CocoaLumberjackSwift
}

func info(_ message: String) {
DDLogInfo(message)
DDLogInfo("\(message)")
}

// MARK: - Warn
Expand All @@ -42,7 +42,7 @@ import CocoaLumberjackSwift
}

func warn(_ message: String) {
DDLogWarn(message)
DDLogWarn("\(message)")
}

// MARK: - Error
Expand All @@ -52,6 +52,6 @@ import CocoaLumberjackSwift
}

func error(_ message: String) {
DDLogError(message)
DDLogError("\(message)")
}
}
Loading