From a241767c8643ad5286b6f646bab0eafa0ba490de Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 00:32:25 +0200 Subject: [PATCH 1/6] Implemented the "wikipediaPlacesURL" property in the Location+URLs extension. --- .../Sources/Extensions/Location+URLs.swift | 46 +++++++++++++++++++ DeepLinking.xcodeproj/project.pbxproj | 12 +++-- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 Apps/Locations/Sources/Extensions/Location+URLs.swift diff --git a/Apps/Locations/Sources/Extensions/Location+URLs.swift b/Apps/Locations/Sources/Extensions/Location+URLs.swift new file mode 100644 index 0000000..a0b3123 --- /dev/null +++ b/Apps/Locations/Sources/Extensions/Location+URLs.swift @@ -0,0 +1,46 @@ +// +// Location+URLs.swift +// Locations +// +// Created by Javier Cicchelli on 13/04/2023. +// Copyright © 2023 Röck+Cöde. All rights reserved. +// + +import Foundation +import Persistence + +extension Location { + + var wikipediaPlacesURL: URL? { + var urlComponents = URLComponents() + + urlComponents.scheme = .Scheme.wikipedia + urlComponents.host = .Host.places + urlComponents.queryItems = [ + .init( + name: .Query.key, + value: .init(format: .Query.value, latitude, longitude) + ) + ] + + return urlComponents.url + } + +} + +// MARK: - String+Constants + +private extension String { + enum Scheme { + static let wikipedia = "wikipedia" + } + + enum Host { + static let places = "places" + } + + enum Query { + static let key = "coordinates" + static let value = "%f,%f" + } +} diff --git a/DeepLinking.xcodeproj/project.pbxproj b/DeepLinking.xcodeproj/project.pbxproj index 00cc327..22e7f75 100644 --- a/DeepLinking.xcodeproj/project.pbxproj +++ b/DeepLinking.xcodeproj/project.pbxproj @@ -12,9 +12,10 @@ 02031EC929E60B29003C108C /* DependencyService+Keys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031EC829E60B29003C108C /* DependencyService+Keys.swift */; }; 02031EE829E68D9B003C108C /* LoadingSpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031EE729E68D9B003C108C /* LoadingSpinnerView.swift */; }; 02031EEA29E6B495003C108C /* ErrorMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031EE929E6B495003C108C /* ErrorMessageView.swift */; }; + 02031F0829E75EF0003C108C /* SaveLocalLocationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F0729E75EED003C108C /* SaveLocalLocationUseCase.swift */; }; + 02031F0A29E7645F003C108C /* Location+URLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F0929E7645F003C108C /* Location+URLs.swift */; }; 4656CBC229E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4656CBC129E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift */; }; 4656CBC829E6F2E400600EE6 /* LocationViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4656CBC729E6F2E400600EE6 /* LocationViewCell.swift */; }; - 4656CBE629E7360B00600EE6 /* SaveLocalLocationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4656CBE529E7360B00600EE6 /* SaveLocalLocationUseCase.swift */; }; 46C3B7C629E5BF1500F8F57C /* LocationsListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7C529E5BF1500F8F57C /* LocationsListCoordinator.swift */; }; 46C3B7CB29E5CD3200F8F57C /* LocationsListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7CA29E5CD3200F8F57C /* LocationsListViewModel.swift */; }; 46C3B7CF29E5D00E00F8F57C /* LocationsAddViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7CE29E5D00E00F8F57C /* LocationsAddViewModel.swift */; }; @@ -131,9 +132,10 @@ 02031EC829E60B29003C108C /* DependencyService+Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DependencyService+Keys.swift"; sourceTree = ""; }; 02031EE729E68D9B003C108C /* LoadingSpinnerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingSpinnerView.swift; sourceTree = ""; }; 02031EE929E6B495003C108C /* ErrorMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorMessageView.swift; sourceTree = ""; }; + 02031F0729E75EED003C108C /* SaveLocalLocationUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SaveLocalLocationUseCase.swift; sourceTree = ""; }; + 02031F0929E7645F003C108C /* Location+URLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Location+URLs.swift"; sourceTree = ""; }; 4656CBC129E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadRemoteLocationsUseCase.swift; sourceTree = ""; }; 4656CBC729E6F2E400600EE6 /* LocationViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationViewCell.swift; sourceTree = ""; }; - 4656CBE529E7360B00600EE6 /* SaveLocalLocationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveLocalLocationUseCase.swift; sourceTree = ""; }; 46C3B7C529E5BF1500F8F57C /* LocationsListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsListCoordinator.swift; sourceTree = ""; }; 46C3B7CA29E5CD3200F8F57C /* LocationsListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsListViewModel.swift; sourceTree = ""; }; 46C3B7CE29E5D00E00F8F57C /* LocationsAddViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsAddViewModel.swift; sourceTree = ""; }; @@ -180,6 +182,7 @@ isa = PBXGroup; children = ( 02031EC829E60B29003C108C /* DependencyService+Keys.swift */, + 02031F0929E7645F003C108C /* Location+URLs.swift */, ); path = Extensions; sourceTree = ""; @@ -225,7 +228,7 @@ isa = PBXGroup; children = ( 4656CBC129E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift */, - 4656CBE529E7360B00600EE6 /* SaveLocalLocationUseCase.swift */, + 02031F0729E75EED003C108C /* SaveLocalLocationUseCase.swift */, ); path = "Use Cases"; sourceTree = ""; @@ -547,7 +550,8 @@ 02031EBF29E5F949003C108C /* LocationsAddViewModeling.swift in Sources */, 4656CBC829E6F2E400600EE6 /* LocationViewCell.swift in Sources */, 46C3B7DE29E5ED2E00F8F57C /* LocationsAddCoordinator.swift in Sources */, - 4656CBE629E7360B00600EE6 /* SaveLocalLocationUseCase.swift in Sources */, + 02031F0A29E7645F003C108C /* Location+URLs.swift in Sources */, + 02031F0829E75EF0003C108C /* SaveLocalLocationUseCase.swift in Sources */, 02031EEA29E6B495003C108C /* ErrorMessageView.swift in Sources */, 46C3B7DC29E5ED2300F8F57C /* LocationsAddCoordination.swift in Sources */, 46C3B7D829E5E55000F8F57C /* LocationsListCoordination.swift in Sources */, -- 2.47.1 From dc7dbfb61aa21be4460003b3347f7e3f135e8c8a Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 00:38:43 +0200 Subject: [PATCH 2/6] Improved the naming of some properties and functions in the LocationsAddCoordination, LocationsListCoordination, and LocationsListViewModeling protocols. --- .../LocationsAddCoordinator.swift | 2 +- .../LocationsListCoordinator.swift | 2 +- .../LocationsAddCoordination.swift | 2 +- .../LocationsListCoordination.swift | 2 +- .../LocationsListViewModeling.swift | 12 ++++++------ .../LocationsAdd/LocationsAddViewModel.swift | 2 +- .../LocationsListViewController.swift | 10 +++++----- .../LocationsListViewModel.swift | 19 +++++++++++-------- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Apps/Locations/Sources/Coordinators/LocationsAddCoordinator.swift b/Apps/Locations/Sources/Coordinators/LocationsAddCoordinator.swift index 7d8891d..7666f15 100644 --- a/Apps/Locations/Sources/Coordinators/LocationsAddCoordinator.swift +++ b/Apps/Locations/Sources/Coordinators/LocationsAddCoordinator.swift @@ -42,7 +42,7 @@ extension LocationsAddCoordinator: LocationsAddCoordination { // MARK: Functions - func closeAddLocation() { + func closeLocationsAddScreen() { router.dismiss(animated: true) } diff --git a/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift b/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift index a7d2592..32e4988 100644 --- a/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift +++ b/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift @@ -48,7 +48,7 @@ extension LocationsListCoordinator: LocationsListCoordination { // MARK: Functions - func openAddLocation() { + func openLocationsAddScreen() { guard let viewController else { return } diff --git a/Apps/Locations/Sources/Protocols/Coordination/LocationsAddCoordination.swift b/Apps/Locations/Sources/Protocols/Coordination/LocationsAddCoordination.swift index 9819245..52354a3 100644 --- a/Apps/Locations/Sources/Protocols/Coordination/LocationsAddCoordination.swift +++ b/Apps/Locations/Sources/Protocols/Coordination/LocationsAddCoordination.swift @@ -10,6 +10,6 @@ protocol LocationsAddCoordination: AnyObject { // MARK: Functions - func closeAddLocation() + func closeLocationsAddScreen() } diff --git a/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift b/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift index bafe329..f47b443 100644 --- a/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift +++ b/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift @@ -10,6 +10,6 @@ protocol LocationsListCoordination: AnyObject { // MARK: Functions - func openAddLocation() + func openLocationsAddScreen() } diff --git a/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift b/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift index 385b599..324278d 100644 --- a/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift +++ b/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift @@ -17,14 +17,14 @@ protocol LocationsListViewModeling: AnyObject { var coordinator: LocationsListCoordination? { get set } var locationsDidChangePublisher: PassthroughSubject<[Change], Never> { get } + var numberOfLocationSections: Int { get } var viewStatusPublisher: Published.Publisher { get } - var numberOfSectionsInData: Int { get } - + // MARK: Functions - - func openAddLocation() + func loadLocations() - func numberOfDataItems(in section: Int) -> Int - func dataItem(at indexPath: IndexPath) -> Location + func location(at indexPath: IndexPath) -> Location + func numberOfLocations(in section: Int) -> Int + func openLocationsAdd() } diff --git a/Apps/Locations/Sources/Screens/LocationsAdd/LocationsAddViewModel.swift b/Apps/Locations/Sources/Screens/LocationsAdd/LocationsAddViewModel.swift index b447c1c..78e8294 100644 --- a/Apps/Locations/Sources/Screens/LocationsAdd/LocationsAddViewModel.swift +++ b/Apps/Locations/Sources/Screens/LocationsAdd/LocationsAddViewModel.swift @@ -54,7 +54,7 @@ extension LocationsAddViewModel: LocationsAddViewModeling { longitude: location.longitude ) - coordinator?.closeAddLocation() + coordinator?.closeLocationsAddScreen() } func setLocation(latitude: Float, longitude: Float) { diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift index e20b00e..16e17f4 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift @@ -67,14 +67,14 @@ extension LocationsListViewController: UITableViewDataSource { // MARK: Functions func numberOfSections(in tableView: UITableView) -> Int { - viewModel.numberOfSectionsInData + viewModel.numberOfLocationSections } func tableView( _ tableView: UITableView, numberOfRowsInSection section: Int ) -> Int { - viewModel.numberOfDataItems(in: section) + viewModel.numberOfLocations(in: section) } func tableView( @@ -88,7 +88,7 @@ extension LocationsListViewController: UITableViewDataSource { return .init() } - let entity = viewModel.dataItem(at: indexPath) + let entity = viewModel.location(at: indexPath) cell.update( iconName: entity.source == .remote ? "network" : "house", @@ -163,7 +163,7 @@ private extension LocationsListViewController { .store(in: &cancellables) viewModel - .controllerDidChangePublisher + .locationsDidChangePublisher .sink(receiveValue: { [weak self] updates in var movedToIndexPaths = [IndexPath]() @@ -199,7 +199,7 @@ private extension LocationsListViewController { } @objc func addLocationPressed() { - viewModel.openAddLocation() + viewModel.openLocationsAdd() } } diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift index b5e2384..8413775 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift @@ -42,15 +42,11 @@ extension LocationsListViewModel: LocationsListViewModeling { // MARK: Properties var locationsDidChangePublisher: PassthroughSubject<[Persistence.Change], Never> { locationProvider.didChangePublisher } - var numberOfSectionsInData: Int { locationProvider.numberOfSections } + var numberOfLocationSections: Int { locationProvider.numberOfSections } var viewStatusPublisher: Published.Publisher { $viewStatus } // MARK: Functions - func openAddLocation() { - coordinator?.openAddLocation() - } - func loadLocations() { Task { do { @@ -67,12 +63,19 @@ extension LocationsListViewModel: LocationsListViewModeling { } } - func numberOfDataItems(in section: Int) -> Int { + + func location(at indexPath: IndexPath) -> Location { + locationProvider.location(at: indexPath) + } + + func numberOfLocations(in section: Int) -> Int { locationProvider.numberOfLocationsInSection(section) } - func dataItem(at indexPath: IndexPath) -> Location { - locationProvider.location(at: indexPath) + func openLocationsAdd() { + coordinator?.openLocationsAddScreen() + } + } } -- 2.47.1 From 8dd4de175b015c5c5a1e832a02ed0b5615ca869a Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 00:44:40 +0200 Subject: [PATCH 3/6] Defined the "openWikipediaApp(with: )" function in the LocationsListCoordination protocol and implement it in the LocationsListCoordinator coordinator. --- .../Sources/Coordinators/LocationsListCoordinator.swift | 8 ++++++++ .../Coordination/LocationsListCoordination.swift | 3 +++ 2 files changed, 11 insertions(+) diff --git a/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift b/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift index 32e4988..05d5ff5 100644 --- a/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift +++ b/Apps/Locations/Sources/Coordinators/LocationsListCoordinator.swift @@ -61,4 +61,12 @@ extension LocationsListCoordinator: LocationsListCoordination { ) } + func openWikipediaApp(with url: URL) { + guard UIApplication.shared.canOpenURL(url) else { + return + } + + UIApplication.shared.open(url) + } + } diff --git a/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift b/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift index f47b443..96cc545 100644 --- a/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift +++ b/Apps/Locations/Sources/Protocols/Coordination/LocationsListCoordination.swift @@ -6,10 +6,13 @@ // Copyright © 2023 Röck+Cöde. All rights reserved. // +import Foundation + protocol LocationsListCoordination: AnyObject { // MARK: Functions func openLocationsAddScreen() + func openWikipediaApp(with url: URL) } -- 2.47.1 From ac39e943dbe6b9c27dfb9a577aad437275c2e036 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 00:47:56 +0200 Subject: [PATCH 4/6] Defined the "openWikipedia(at: )" function in the LocationsListViewModeling protocol and implement it in the LocationsListViewModel view model. --- .../Protocols/ViewModeling/LocationsListViewModeling.swift | 1 + .../Screens/LocationsList/LocationsListViewModel.swift | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift b/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift index 324278d..4073b1c 100644 --- a/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift +++ b/Apps/Locations/Sources/Protocols/ViewModeling/LocationsListViewModeling.swift @@ -26,5 +26,6 @@ protocol LocationsListViewModeling: AnyObject { func location(at indexPath: IndexPath) -> Location func numberOfLocations(in section: Int) -> Int func openLocationsAdd() + func openWikipedia(at indexPath: IndexPath) } diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift index 8413775..dedcbdc 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift @@ -76,6 +76,12 @@ extension LocationsListViewModel: LocationsListViewModeling { coordinator?.openLocationsAddScreen() } + func openWikipedia(at indexPath: IndexPath) { + guard let url = locationProvider.location(at: indexPath).wikipediaPlacesURL else { + return + } + + coordinator?.openWikipediaApp(with: url) } } -- 2.47.1 From efbce8dda88958f5d675f5bf5d003c739882964f Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 00:49:09 +0200 Subject: [PATCH 5/6] Implemented the "tableView(_: didSelectAt: )" function in the LocationsListViewController view controller. --- .../LocationsListViewController.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift index 16e17f4..5fb6e90 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift @@ -104,7 +104,20 @@ extension LocationsListViewController: UITableViewDataSource { // MARK: - UITableViewDelegate -extension LocationsListViewController: UITableViewDelegate {} +extension LocationsListViewController: UITableViewDelegate { + + // MARK: Functions + + func tableView( + _ tableView: UITableView, + didSelectRowAt indexPath: IndexPath + ) { + viewModel.openWikipedia(at: indexPath) + + tableView.deselectRow(at: indexPath, animated: true) + } + +} // MARK: - Helpers -- 2.47.1 From cdbfc4518c99223215237f70eb4753ccd7e6d1b3 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 00:50:52 +0200 Subject: [PATCH 6/6] Added the "wikipedia" to the Queried URL schemes in the Info.plist file to support querying to the Wikipedia app. --- Apps/Locations/Resources/Info.plist | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Apps/Locations/Resources/Info.plist b/Apps/Locations/Resources/Info.plist index 0c67376..bb76b77 100644 --- a/Apps/Locations/Resources/Info.plist +++ b/Apps/Locations/Resources/Info.plist @@ -1,5 +1,10 @@ - + + LSApplicationQueriesSchemes + + wikipedia + + -- 2.47.1