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

Fix some warnings #775

Merged
merged 4 commits into from
Nov 30, 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
10 changes: 5 additions & 5 deletions OBAKit/Bookmarks/TripBookmarkCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ final class TripBookmarkTableCell: OBAListViewCell {

isAccessibilityElement = true
accessibilityTraits = [.button, .updatesFrequently]

let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self]
registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in
self.layoutView()
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -245,11 +250,6 @@ final class TripBookmarkTableCell: OBAListViewCell {
accessibilityValue = nil
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
layoutView()
}

override var isHighlighted: Bool {
didSet {
contentView.backgroundColor = isHighlighted ? ThemeColors.shared.highlightedBackgroundColor : nil
Expand Down
28 changes: 11 additions & 17 deletions OBAKit/Controls/VisualEffectsShadow/HoverBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,18 @@ class HoverBarPassThroughView: UIView {
shadowView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: blurRadius),
shadowView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: -blurRadius)
])
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
transition(to: traitCollection.userInterfaceStyle)
}
}

private func transition(to style: UIUserInterfaceStyle) {
switch style {
case .light, .unspecified:
showShadow = true
case .dark:
showShadow = false
@unknown default:
fatalError()
registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection: UITraitCollection) in
if self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
switch self.traitCollection.userInterfaceStyle {
case .light, .unspecified:
self.showShadow = true
case .dark:
self.showShadow = false
@unknown default:
fatalError()
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion OBAKit/Mapping/MapRegionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public class MapRegionManager: NSObject,
}
}

var mapRegion = await mapView.region
var mapRegion = mapView.region
mapRegion.span.latitudeDelta *= preferredLoadDataRegionFudgeFactor
mapRegion.span.longitudeDelta *= preferredLoadDataRegionFudgeFactor

Expand Down
1 change: 0 additions & 1 deletion OBAKit/Mapping/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ class MapViewController: UIViewController,
}
}

@MainActor
public func mapRegionManager(_ manager: MapRegionManager, showSearchResult response: SearchResponse) {
Task { @MainActor [weak self] in
guard let self, let result = response.results.first else { return }
Expand Down
14 changes: 6 additions & 8 deletions OBAKit/Mapping/PulsingAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ class PulsingAnnotationView: MKAnnotationView {
layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
calloutOffset = CGPoint(x: 0, y: 4)
self.bounds = bounds

registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection: UITraitCollection) in
if self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle {
self.rebuildLayers()
}
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -162,14 +168,6 @@ class PulsingAnnotationView: MKAnnotationView {
}
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle {
rebuildLayers()
}
}

override func willMove(toSuperview newSuperview: UIView?) {
if newSuperview != nil {
rebuildLayers()
Expand Down
26 changes: 15 additions & 11 deletions OBAKit/Mapping/StopAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class StopAnnotationView: MKAnnotationView {
updateAccessibility()

NotificationCenter.default.addObserver(self, selector: #selector(voiceoverStatusDidChange), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)

registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection: UITraitCollection) in
if self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle {
self.rebuildIcon()
}
}
}

required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
Expand Down Expand Up @@ -105,17 +111,6 @@ class StopAnnotationView: MKAnnotationView {
}
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

guard
let stop = annotation as? Stop,
let delegate = delegate
else { return }

image = delegate.iconFactory.buildIcon(for: stop, isBookmarked: delegate.isStopBookmarked(stop), traits: traitCollection)
}

// MARK: - Annotation Rendering

private func prepareForDisplay(bookmark: Bookmark, delegate: StopAnnotationDelegate) {
Expand Down Expand Up @@ -179,4 +174,13 @@ class StopAnnotationView: MKAnnotationView {
// we should skip the callout and push directly to the annotation's destination view.
canShowCallout = !UIAccessibility.isVoiceOverRunning
}

private func rebuildIcon() {
guard
let stop = annotation as? Stop,
let delegate = delegate
else { return }

image = delegate.iconFactory.buildIcon(for: stop, isBookmarked: delegate.isStopBookmarked(stop), traits: traitCollection)
}
}
2 changes: 1 addition & 1 deletion OBAKit/Onboarding/DataMigration/DataMigrationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public struct DataMigrationView: View, OnboardingView {

private func handleReportDismiss() {
Task {
await self.dismiss()
self.dismiss()
}
}

Expand Down
4 changes: 2 additions & 2 deletions OBAKit/Orchestration/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class Application: CoreApplication, PushServiceDelegate {
}

Task(priority: .userInitiated) {
await ProgressHUD.show()
ProgressHUD.show()

do {
let arrDep = try await apiService.getTripArrivalDepartureAtStop(stopID: deepLink.stopID, tripID: deepLink.tripID, serviceDate: deepLink.serviceDate, vehicleID: deepLink.vehicleID, stopSequence: deepLink.stopSequence).entry
Expand All @@ -126,7 +126,7 @@ public class Application: CoreApplication, PushServiceDelegate {
await self.displayError(error)
}

await ProgressHUD.dismiss()
ProgressHUD.dismiss()
}
}

Expand Down
10 changes: 5 additions & 5 deletions OBAKit/Stops/StopHeaderController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class StopHeaderView: UIView {
])

addGestureRecognizer(toggleRouteDetailsGestureRecognizer)

let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self]
registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in
self.configureView()
}
}

required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
Expand Down Expand Up @@ -200,11 +205,6 @@ class StopHeaderView: UIView {
self.stackPaddingBottomHeight.constant = suggestedHeight
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
self.configureView()
}

@objc private func toggleRouteDetails(_ sender: UITapGestureRecognizer) {
isHidingRoutesLabel.toggle()
routesLabel.alpha = isHidingRoutesLabel ? 1.0 : 0.0
Expand Down
10 changes: 5 additions & 5 deletions OBAKit/Stops/WalkTimeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class WalkTimeView: UIView {
])

NotificationCenter.default.addObserver(self, selector: #selector(deviceOrientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)

let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self]
registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in
self.setNeedsDisplay()
}
}

required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
Expand Down Expand Up @@ -121,11 +126,6 @@ class WalkTimeView: UIView {
return CGSize(width: UIView.noIntrinsicMetric, height: maximumIntrinsicHeight)
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
setNeedsDisplay()
}

@objc fileprivate func deviceOrientationDidChange(_ notification: Notification) {
setNeedsDisplay()
}
Expand Down
9 changes: 4 additions & 5 deletions OBAKit/Trip/TripStopListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ final class TripStopCell: OBAListViewCell {
])

isAccessibilityElement = true

registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, previousTraitCollection: UITraitCollection) in
self.layoutAccessibility()
}
}

required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
Expand Down Expand Up @@ -232,11 +236,6 @@ final class TripStopCell: OBAListViewCell {
layoutAccessibility()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
layoutAccessibility()
}

func layoutAccessibility() {
self.textLabelsStack.axis = isAccessibility ? .vertical : .horizontal
self.textLabelSpacerView.isHidden = isAccessibility
Expand Down
16 changes: 11 additions & 5 deletions OBAKit/Trip/TripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ class TripViewController: UIViewController,
self.tripConvertible = tripConvertible

super.init(nibName: nil, bundle: nil)

registerTraitChangeCallback()
}

init(application: Application, arrivalDeparture: ArrivalDeparture) {
self.application = application
self.tripConvertible = TripConvertible(arrivalDeparture: arrivalDeparture)

super.init(nibName: nil, bundle: nil)

registerTraitChangeCallback()
}

required init?(coder: NSCoder) {
Expand All @@ -46,6 +50,13 @@ class TripViewController: UIViewController,
deinit {
enableIdleTimer()
}

private func registerTraitChangeCallback() {
let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self, UITraitPreferredContentSizeCategory.self]
registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in
self.updateTitleView()
}
}

// MARK: - UIViewController

Expand Down Expand Up @@ -102,11 +113,6 @@ class TripViewController: UIViewController,
enableIdleTimer()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateTitleView()
}

// MARK: - NSUserActivity

/// Creates and assigns an `NSUserActivity` object corresponding to this trip.
Expand Down
Loading