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: issue 625 #716

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion OBAKit/Agencies/AgenciesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ import OBAKitCore
/// Loads and displays a list of agencies in the current region.
class AgenciesViewController: TaskController<[AgencyWithCoverage]>, OBAListViewDataSource {
let listView = OBAListView()

public override func loadView() {
super.loadView()
self.view = listView
}

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = ThemeColors.shared.systemBackground

listView.obaDataSource = self
view.addSubview(listView)
listView.pinToSuperview(.edges)

title = OBALoc("agencies_controller.title", value: "Agencies", comment: "Title of the Agencies controller")
Expand Down
6 changes: 5 additions & 1 deletion OBAKit/Alerts/AgencyAlertsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class AgencyAlertsViewController: UIViewController,
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -58,7 +63,6 @@ class AgencyAlertsViewController: UIViewController,
listView.collapsibleSectionsDelegate = self
listView.contextMenuDelegate = self
listView.refreshControl = refreshControl
view.addSubview(listView)
listView.pinToSuperview(.edges)

view.backgroundColor = ThemeColors.shared.systemBackground
Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Bookmarks/AddBookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ class AddBookmarkViewController: TaskController<[ArrivalDeparture]>, OBAListView
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = ThemeColors.shared.systemBackground
listView.obaDataSource = self
view.addSubview(listView)
listView.pinToSuperview(.edges)
}

Expand Down
6 changes: 5 additions & 1 deletion OBAKit/Bookmarks/BookmarksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public class BookmarksViewController: UIViewController,
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -100,7 +105,6 @@ public class BookmarksViewController: UIViewController,
listView.contextMenuDelegate = self
listView.formatters = application.formatters
listView.register(listViewItem: BookmarkArrivalViewModel.self)
view.addSubview(listView)
listView.pinToSuperview(.edges)

rebuildSortMenu()
Expand Down
31 changes: 31 additions & 0 deletions OBAKit/Orchestration/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ public class Application: CoreApplication, PushServiceDelegate {
reloadRootUserInterface()

reportAnalyticsUserProperties()
UIApplication.shared.delegate?.window??.windowScene?.screenshotService?.delegate = self
}

@objc public func applicationDidBecomeActive(_ application: UIApplication) {
Expand Down Expand Up @@ -589,3 +590,33 @@ public class Application: CoreApplication, PushServiceDelegate {
/// `.running` means that the feature is ready to use.
public lazy var features = FeatureAvailability(config: self.config, application: self)
}

// MARK: UIScreenshotServiceDelegate
extension Application: UIScreenshotServiceDelegate {
public func screenshotService(_ screenshotService: UIScreenshotService, generatePDFRepresentationWithCompletion completionHandler: @escaping (Data?, Int, CGRect) -> Void) {
guard let topVC = UIApplication.shared.keyWindowFromScene?.topViewController,
let scrollerView = topVC.view as? OBAListView,
scrollerView.contentSize.height != .zero else {
completionHandler(nil, 0, .zero)
return
}
let data = NSMutableData()
UIGraphicsBeginPDFContextToData(data, .zero, nil)
UIGraphicsBeginPDFPageWithInfo(.init(origin: .zero, size: scrollerView.contentSize), nil)
if let context = UIGraphicsGetCurrentContext() {
let frame = scrollerView.frame
let contentOffset = scrollerView.contentOffset
let contentInset = scrollerView.contentInset
scrollerView.contentOffset = .zero
scrollerView.contentInset = .zero
scrollerView.frame = .init(origin: .zero, size: scrollerView.contentSize)
scrollerView.layer.render(in: context)
scrollerView.frame = frame
scrollerView.contentOffset = contentOffset
scrollerView.contentInset = contentInset
}
UIGraphicsEndPDFContext()
let y = scrollerView.contentSize.height - scrollerView.contentOffset.y - scrollerView.frame.height
completionHandler(data as Data, 0, .init(origin: CGPoint(x: 0, y: y), size: topVC.view.frame.size))
}
}
5 changes: 4 additions & 1 deletion OBAKit/Recent/RecentStopsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ public class RecentStopsViewController: UIViewController,
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()

navigationItem.rightBarButtonItem = UIBarButtonItem(title: OBALoc("recent_stops.delete_all", value: "Delete All", comment: "A button that deletes all of the recent stops in the app."), style: .plain, target: self, action: #selector(deleteAll))

view.backgroundColor = ThemeColors.shared.systemBackground
view.addSubview(listView)
listView.contextMenuDelegate = self
listView.pinToSuperview(.edges)
}
Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Reporting/ReportProblemViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class ReportProblemViewController: TaskController<StopArrivals>,
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -50,7 +54,6 @@ class ReportProblemViewController: TaskController<StopArrivals>,
listView.formatters = application.formatters
listView.register(listViewItem: ArrivalDepartureItem.self)

view.addSubview(listView)
listView.pinToSuperview(.edges)
}

Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Search/SearchResultsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ public class SearchResultsController: UIViewController, AppContext, OBAListViewD
titleView.subtitleLabel.text = subtitleText(from: searchResponse)

listView.obaDataSource = self
view.addSubview(listView)
listView.pinToSuperview(.edges)
}

required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }

// MARK: - UIViewController Lifecycle
public override func loadView() {
super.loadView()
self.view = listView
}

override public func viewDidLoad() {
super.viewDidLoad()
Expand Down
5 changes: 4 additions & 1 deletion OBAKit/ServiceAlerts/ServiceAlertListController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ final class ServiceAlertListController: UIViewController,
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = ThemeColors.shared.systemBackground

listView.obaDataSource = self
view.addSubview(listView)
listView.pinToSuperview(.edges)
}

Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Settings/CreditsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ class CreditsViewController: UIViewController, AppContext, OBAListViewDataSource
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = ThemeColors.shared.systemBackground

view.addSubview(listView)
listView.pinToSuperview(.edges)
listView.obaDataSource = self
listView.applyData()
Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Settings/MoreViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ public class MoreViewController: UIViewController,
}

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}
public override func viewDidLoad() {
super.viewDidLoad()

listView.obaDataSource = self
view.addSubview(listView)
listView.pinToSuperview(.edges)

view.backgroundColor = ThemeColors.shared.systemBackground
Expand Down
4 changes: 4 additions & 0 deletions OBAKit/Stops/NearbyStopsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class NearbyStopsViewController: UIViewController,
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()
Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Stops/StopViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public class StopViewController: UIViewController,
}

// MARK: - UIViewController Overrides
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -185,7 +189,6 @@ public class StopViewController: UIViewController,
listView.register(listViewItem: StopArrivalWalkItem.self)
listView.register(listViewItem: StopHeaderItem.self)

view.addSubview(listView)
listView.pinToSuperview(.edges)
listView.addSubview(refreshControl)

Expand Down
5 changes: 4 additions & 1 deletion OBAKit/Trip/TripFloatingPanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class TripFloatingPanelController: UIViewController,
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }

// MARK: - UIViewController
public override func loadView() {
super.loadView()
self.view = listView
}

public override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -79,7 +83,6 @@ class TripFloatingPanelController: UIViewController,
listView.register(listViewItem: TripStopViewModel.self)

view.backgroundColor = ThemeColors.shared.systemBackground
view.addSubview(outerStack)
outerStack.pinToSuperview(.edges)
}

Expand Down