Skip to content

Commit

Permalink
[SSDK-503] Rename Discover to Category (#172)
Browse files Browse the repository at this point in the history
### Description
**Ticket**: [SSDK-503](https://mapbox.atlassian.net/browse/SSDK-503)

- Rename MapboxSearch/PublicAPI/Use Cases/Discover API/ → Category
- Rename Discover.Query.Category → Category.Item
- Remove SearchUI.SearchCategory 
    - replace it with `typealias SearchCategory = MapboxSearch.Category.Item`
    - This consolidates both the MapboxSearch and MapboxSearchUI `Category` structs into 1 representation that has additional extension in the SearchUI module.
    - Replace the old SearchUI.SearchCategory predefined category instances with MapboxSearch.Category.Item predefined instances that support all of geocoding (legacyName), and SBS and search-box (canonicalId)

### Checklist
- [x] Update `CHANGELOG`

[SSDK-503]: https://mapbox.atlassian.net/browse/SSDK-503
  • Loading branch information
aokj4ck authored Mar 1, 2024
1 parent f72f8f8 commit 4e5603e
Show file tree
Hide file tree
Showing 22 changed files with 558 additions and 589 deletions.
3 changes: 1 addition & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@
--xcodeindentation enabled
--yodaswap always

--disable redundantReturn,hoistAwait
--swiftversion 5.7
--disable redundantReturn,hoistAwait
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Guide: https://keepachangelog.com/en/1.0.0/

<!-- Add changes for active work here -->

- [Discover, Category] Rename Discover to Category and update tests.
- [Category] Rename Discover.Query.Category to Category.Item
- [Category] Move Category.Item "Hot" suggested categories to MapboxSearch out of MapboxSearchUI.
- This adds legacyName (use with Geocoding API engine) and icon fields to the MapboxSearch suggested categories.
- Image assets for these categories remain in MapboxSearchUI.
- This Category.Item replaces MapboxSearchUI.SearchCategory.
- Add an alias for MapboxSearchUI.SearchCategory = MapboxSearch.Category.Item
- [Core] Default API engine is now search-box replacing SBS.

- [License] Update license to reflect 2024 usage

Expand Down
92 changes: 49 additions & 43 deletions MapboxSearch.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Sources/Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@
</objects>
<point key="canvasLocation" x="729" y="1529"/>
</scene>
<!--Discover-->
<!--Category-->
<scene sceneID="Cbv-pg-ufB">
<objects>
<navigationController navigationBarHidden="YES" id="kQh-we-4TL" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Discover" image="tag" catalog="system" id="FHv-mk-0xk"/>
<tabBarItem key="tabBarItem" title="Category" image="tag" catalog="system" id="FHv-mk-0xk"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="XUy-LY-TcY">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
Expand All @@ -245,10 +245,10 @@
</objects>
<point key="canvasLocation" x="-1023" y="2400"/>
</scene>
<!--Discover-->
<!--Category-->
<scene sceneID="cow-iZ-A5n">
<objects>
<viewController title="Discover" id="ggU-4h-Z4i" customClass="DiscoverViewController" customModule="MapboxSearch" sceneMemberID="viewController">
<viewController title="Category" id="ggU-4h-Z4i" customClass="CategoryViewController" customModule="MapboxSearch" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="H51-Up-D8x">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import MapKit
import UIKit

final class DiscoverViewController: UIViewController {
final class CategoryViewController: UIViewController {
@IBOutlet private var mapView: MKMapView!
@IBOutlet private var segmentedControl: UISegmentedControl!

private let discover = Discover(apiType: .searchBox)
private let category = Category()

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -16,25 +16,25 @@ final class DiscoverViewController: UIViewController {

// MARK: - Actions

extension DiscoverViewController {
extension CategoryViewController {
@IBAction
private func handleSearchInRegionAction() {
let regionResultsLimit: Int
switch discover.apiType {
switch category.apiType {
case .geocoding:
regionResultsLimit = 10
default:
regionResultsLimit = 100
}

discover.search(
category.search(
for: currentSelectedCategory,
in: currentBoundingBox,
options: .init(limit: regionResultsLimit)
) { result in
switch result {
case .success(let results):
self.showDiscoverResults(results)
self.showCategoryResults(results)

case .failure(let error):
debugPrint(error)
Expand All @@ -45,7 +45,7 @@ extension DiscoverViewController {

// MARK: - Private

extension DiscoverViewController {
extension CategoryViewController {
private var currentBoundingBox: BoundingBox {
let rect = mapView.visibleMapRect
let neMapPoint = MKMapPoint(x: rect.maxX, y: rect.origin.y)
Expand All @@ -57,14 +57,14 @@ extension DiscoverViewController {
return .init(swCoordinate, neCoordinate)
}

private var currentSelectedCategory: Discover.Query {
let allCategories: [Discover.Query] = [
.Category.parking,
.Category.restaurants,
.Category.museums,
private var currentSelectedCategory: Category.Item {
let allDemoCategories: [Category.Item] = [
.parking,
.restaurant,
.museum,
]

return allCategories[segmentedControl.selectedSegmentIndex]
return allDemoCategories[segmentedControl.selectedSegmentIndex]
}

private func configureDefaultMapRegion() {
Expand All @@ -78,7 +78,7 @@ extension DiscoverViewController {
mapView.setRegion(region, animated: false)
}

private func showDiscoverResults(_ results: [Discover.Result]) {
private func showCategoryResults(_ results: [Category.Result]) {
mapView.removeAnnotations(mapView.annotations)

let annotations: [MKPointAnnotation] = results.map {
Expand Down
20 changes: 20 additions & 0 deletions Sources/MapboxSearch/PublicAPI/Common/Bundle+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation

extension Bundle {
/// Access to MapboxSearch resource bundle
///
/// Resource bundle may be located:
/// - inside dynamic framework
///
/// `MapboxSearch.framework/MapboxSearch.bundle`
/// - as a plain bundle in the application root (for static lib distribution)
///
/// `Demo.app/MapboxSearch.bundle`
///
/// We use `CoreSearchResultResponse` class as an anchor to detect the bundle
#if SWIFT_PACKAGE
static let mapboxSearch = module
#else
static let mapboxSearch = Bundle(for: CoreSearchResultResponse.self)
#endif
}
158 changes: 158 additions & 0 deletions Sources/MapboxSearch/PublicAPI/Strings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright © 2024 Mapbox. All rights reserved.

import Foundation

enum Strings {
enum Categories {
static let gas = NSLocalizedString(
"gas_station.short",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Gas title"
)
static let parking = NSLocalizedString(
"parking_lot",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Parking title"
)
static let food = NSLocalizedString(
"restaurant.alias.food",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Food title"
)
static let cafe = NSLocalizedString(
"cafe",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Cafe title"
)
static let restaurant = NSLocalizedString(
"restaurants",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Restaurants title"
)
static let bar = NSLocalizedString(
"bar",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Bars title"
)
static let coffeeShop = NSLocalizedString(
"cafe.long",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Coffee Shop title"
)
static let hotel = NSLocalizedString(
"hotel",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Hotel title"
)
static let gasStation = NSLocalizedString(
"gas_station",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Gas Station title"
)
static let chargingStation = NSLocalizedString(
"charging_station",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category EV Charging Station title"
)
static let busStation = NSLocalizedString(
"bus_station",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Bus station title"
)
static let railwayStation = NSLocalizedString(
"railway_station",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Train station title"
)
static let shoppingMall = NSLocalizedString(
"shopping_mall",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Shopping malls title"
)
static let grocery = NSLocalizedString(
"grocery",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Supermarket / Grocery title"
)
static let clothingStore = NSLocalizedString(
"clothing_store",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Clothing / shoes title"
)
static let pharmacy = NSLocalizedString(
"pharmacy",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Pharmacy title"
)
static let museum = NSLocalizedString(
"museum",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Museums title"
)
static let park = NSLocalizedString(
"park",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Parks title"
)
static let cinema = NSLocalizedString(
"cinema",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Movie Theaters title"
)
static let fitnessCentre = NSLocalizedString(
"fitness_center",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Gym / Fitness title"
)
static let nightclub = NSLocalizedString(
"nightclub",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Night clubs title"
)
static let autoRepair = NSLocalizedString(
"auto_repair",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Auto repair / mechanic title"
)
static let atm = NSLocalizedString(
"atm",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category ATM title"
)
static let hospital = NSLocalizedString(
"hospital",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category Hospital title"
)
static let emergencyRoom = NSLocalizedString(
"emergency_room",
tableName: "Categories",
bundle: .mapboxSearch,
comment: "Category ER title"
)
}
}
Loading

0 comments on commit 4e5603e

Please sign in to comment.