diff --git a/CHANGELOG.md b/CHANGELOG.md index 895fea231..863458b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Guide: https://keepachangelog.com/en/1.0.0/ +- [Offline] Added OfflineIndexObserver which accepts two blocks for indexChanged or error events. This can be assigned to the offline search engine to receive state updates. + ## 2.0.0-rc.3 - [Core] Add `SearchResultAccuracy.proximate` case which "is a known address point but does not intersect a known rooftop/parcel." diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index 59c762adb..b65450aaf 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -31,6 +31,8 @@ 0477904D2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; 0477904E2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; 0477904F2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; + 0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */; }; + 0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */; }; 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; @@ -540,6 +542,8 @@ 046818E02B87FF5C0082B188 /* search-box-suggestions-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-suggestions-minsk.json"; sourceTree = ""; }; 047790482B890A8500A99528 /* search-box-recursion.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-recursion.json"; sourceTree = ""; }; 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = ""; }; + 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineIndexObserver.swift; sourceTree = ""; }; + 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreOfflineIndexChangeEventType.swift; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = ""; }; @@ -1052,6 +1056,14 @@ path = sbs; sourceTree = ""; }; + 0484BCE02BC49A18003CF408 /* Offline */ = { + isa = PBXGroup; + children = ( + 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */, + ); + path = Offline; + sourceTree = ""; + }; 04970F8B2B7A97C900213763 /* Resources */ = { isa = PBXGroup; children = ( @@ -1554,6 +1566,7 @@ F9274FF127394AE600708F37 /* TileRegionError.swift */, F9274FEA2732BF0E00708F37 /* SearchTileStore.swift */, F9274FF6273AAE7200708F37 /* TileRegionLoadOptions+Search.swift */, + 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */, ); path = Offline; sourceTree = ""; @@ -1731,6 +1744,7 @@ FEEDD2C12508DFE400DC0A98 /* InternalAPI */ = { isa = PBXGroup; children = ( + 0484BCE02BC49A18003CF408 /* Offline */, 04C127562B62FFD000884325 /* Engine */, 148DE66E285777050085684D /* Common */, F98BECBB2577B9150081D3BC /* Telemetry */, @@ -2664,6 +2678,7 @@ F9E8146225418E7D00F6378E /* EventsManager.swift in Sources */, FEEDD3002508DFE400DC0A98 /* CLLocationCoordinate2DCodable.swift in Sources */, FEEDD3042508DFE400DC0A98 /* SearchResultType.swift in Sources */, + 0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */, F91FD66C258CCB41008CB8E1 /* CoreResultType+Extensions.swift in Sources */, FEEDD3152508DFE400DC0A98 /* ServerSearchResult.swift in Sources */, 140E47A2298BC90E00677E30 /* Discover.swift in Sources */, @@ -2671,6 +2686,7 @@ 04C127552B62F6BC00884325 /* ApiType.swift in Sources */, FE059C5A251A0AE6001F7701 /* SearchCategorySuggestionImpl.swift in Sources */, FEEDD2F62508DFE400DC0A98 /* CoreSearchResultResponse.swift in Sources */, + 0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */, FE260A6725C063880037B725 /* ReverseGeocodingOptions.swift in Sources */, FECA461026D3F81800BC7B18 /* MapboxSearchUserAgent.swift in Sources */, FEEDD2F32508DFE400DC0A98 /* CoreBoundingBox.swift in Sources */, diff --git a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme index 80438c09f..fe0ff092e 100644 --- a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme +++ b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme @@ -126,7 +126,7 @@ diff --git a/Sources/MapboxSearch/InternalAPI/CoreAliases.swift b/Sources/MapboxSearch/InternalAPI/CoreAliases.swift index ad1aa541b..1c69bb309 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreAliases.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreAliases.swift @@ -33,6 +33,12 @@ typealias CoreUserActivityReporterOptions = MapboxCoreSearch.UserActivityReporte typealias CoreReverseGeoOptions = MapboxCoreSearch.ReverseGeoOptions +// Offline +typealias CoreOfflineIndexObserver = MapboxCoreSearch.OfflineIndexObserver +typealias CoreOfflineIndexChangeEvent = MapboxCoreSearch.OfflineIndexChangeEvent +typealias CoreOfflineIndexError = MapboxCoreSearch.OfflineIndexError +typealias CoreOfflineIndexChangeEventType = MapboxCoreSearch.OfflineIndexChangeEventType + let mapboxCoreSearchErrorDomain = "MapboxCoreSearchErrorDomain" extension CoreSearchEngine { diff --git a/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift b/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift index 9a398a4c3..198432e1f 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift @@ -81,6 +81,10 @@ protocol CoreSearchEngineProtocol { func setTileStore(_ tileStore: MapboxCommon.TileStore, completion: (() -> Void)?) func setTileStore(_ tileStore: MapboxCommon.TileStore) + + func addOfflineIndexObserver(for observer: CoreOfflineIndexObserver) + + func removeOfflineIndexObserver(for observer: CoreOfflineIndexObserver) } extension CoreSearchEngine: CoreSearchEngineProtocol { diff --git a/Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift b/Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift new file mode 100644 index 000000000..0be3ffce2 --- /dev/null +++ b/Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift @@ -0,0 +1,18 @@ +// Copyright © 2024 Mapbox. All rights reserved. + +import Foundation + +extension CoreOfflineIndexChangeEventType: CustomDebugStringConvertible { + public var debugDescription: String { + switch self { + case .added: + return "Added" + case .removed: + return "Removed" + case .updated: + return "Updated" + @unknown default: + return "Unknown" + } + } +} diff --git a/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift b/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift index 828a9f200..5abc1a0c1 100644 --- a/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift +++ b/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift @@ -5,8 +5,7 @@ import CoreLocation /// Would not trigger Location Permission dialogs but will retrieve permission changes notification. /// Suitable for `SearchEngine` for providing user location by default without additional efforts. public class DefaultLocationProvider { - // not used anywhere as public - /* public */ let locationManager: CLLocationManager + let locationManager: CLLocationManager #if FAST_LOCATION_CHANGES_TRACKING let locationRequestFrequency: TimeInterval = 1 diff --git a/Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift b/Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift new file mode 100644 index 000000000..a2ea14724 --- /dev/null +++ b/Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift @@ -0,0 +1,29 @@ +// Copyright © 2024 Mapbox. All rights reserved. + +import Foundation + +class OfflineIndexObserver: CoreOfflineIndexObserver { + enum Types { + typealias indexChangedBlock = (CoreOfflineIndexChangeEvent) -> Void + typealias errorBlock = (CoreOfflineIndexError) -> Void + } + + private var onIndexChangedBlock: Types.indexChangedBlock + private var onErrorBlock: Types.errorBlock + + init( + onIndexChangedBlock: @escaping Types.indexChangedBlock = { _ in }, + onErrorBlock: @escaping Types.errorBlock = { _ in } + ) { + self.onIndexChangedBlock = onIndexChangedBlock + self.onErrorBlock = onErrorBlock + } + + func onIndexChanged(for event: CoreOfflineIndexChangeEvent) { + onIndexChangedBlock(event) + } + + func onError(forError error: CoreOfflineIndexError) { + onErrorBlock(error) + } +} diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 1ab179677..1f836bf6c 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -57,6 +57,18 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase