diff --git a/iphone/Maps/Core/Search/MWMSearch.mm b/iphone/Maps/Core/Search/MWMSearch.mm index 5b39f57d9a..79734734d4 100644 --- a/iphone/Maps/Core/Search/MWMSearch.mm +++ b/iphone/Maps/Core/Search/MWMSearch.mm @@ -160,9 +160,9 @@ using Observers = NSHashTable; } + (SearchResult *)resultWithContainerIndex:(NSUInteger)index { - SearchResult * result = [[SearchResult alloc] - initWithResult:[MWMSearch manager]->m_everywhereResults[index] - itemType:[MWMSearch resultTypeWithRow:index]]; + SearchResult * result = [[SearchResult alloc] initWithResult:[MWMSearch manager]->m_everywhereResults[index] + itemType:[MWMSearch resultTypeWithRow:index] + index:index]; return result; } diff --git a/iphone/Maps/Core/Search/SearchResult+Core.h b/iphone/Maps/Core/Search/SearchResult+Core.h index 0ad4ec4aad..517d27f271 100644 --- a/iphone/Maps/Core/Search/SearchResult+Core.h +++ b/iphone/Maps/Core/Search/SearchResult+Core.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SearchResult (Core) -- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType; +- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType index:(NSUInteger)index; @end diff --git a/iphone/Maps/Core/Search/SearchResult.h b/iphone/Maps/Core/Search/SearchResult.h index c06eaa695a..f3d425b1d3 100644 --- a/iphone/Maps/Core/Search/SearchResult.h +++ b/iphone/Maps/Core/Search/SearchResult.h @@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SearchResult : NSObject +@property (nonatomic, readonly) NSUInteger index; @property (nonatomic, readonly) NSString * titleText; @property (nonatomic, readonly) NSString * iconImageName; @property (nonatomic, readonly) NSString * addressText; diff --git a/iphone/Maps/Core/Search/SearchResult.mm b/iphone/Maps/Core/Search/SearchResult.mm index 0cd9373cc6..ea47d4f186 100644 --- a/iphone/Maps/Core/Search/SearchResult.mm +++ b/iphone/Maps/Core/Search/SearchResult.mm @@ -26,9 +26,10 @@ @implementation SearchResult(Core) -- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType { +- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType index:(NSUInteger)index { self = [super init]; if (self) { + _index = index; _titleText = result.GetString().empty() ? @(result.GetLocalizedFeatureType().c_str()) : @(result.GetString().c_str()); _addressText = @(result.GetAddress().c_str()); _infoText = @(result.GetFeatureDescription().c_str()); diff --git a/iphone/Maps/Tests/UI/SearchOnMapTests/SearchOnMapTests.swift b/iphone/Maps/Tests/UI/SearchOnMapTests/SearchOnMapTests.swift index 1b23176dea..304c3eb952 100644 --- a/iphone/Maps/Tests/UI/SearchOnMapTests/SearchOnMapTests.swift +++ b/iphone/Maps/Tests/UI/SearchOnMapTests/SearchOnMapTests.swift @@ -130,7 +130,7 @@ final class SearchOnMapTests: XCTestCase { let results = SearchResult.stubResults() searchManager.results = results - interactor.handle(.didSelectResult(results[0], atIndex: 0, withSearchText: searchText)) + interactor.handle(.didSelectResult(results[0], withSearchText: searchText)) XCTAssertEqual(currentState, .hidden) XCTAssertEqual(view.viewModel.presentationStep, .hidden) } @@ -158,7 +158,7 @@ final class SearchOnMapTests: XCTestCase { let results = SearchResult.stubResults() searchManager.results = results - interactor.handle(.didSelectResult(results[0], atIndex: 0, withSearchText: searchText)) + interactor.handle(.didSelectResult(results[0], withSearchText: searchText)) XCTAssertEqual(currentState, .hidden) XCTAssertEqual(view.viewModel.presentationStep, .hidden) @@ -207,7 +207,7 @@ final class SearchOnMapTests: XCTestCase { interactor.handle(.didType(searchText)) let suggestion = SearchResult(titleText: "", type: .suggestion, suggestion: "suggestion") - interactor.handle(.didSelectResult(suggestion, atIndex: 0, withSearchText: searchText)) + interactor.handle(.didSelectResult(suggestion, withSearchText: searchText)) XCTAssertEqual(view.viewModel.searchingText, "suggestion") XCTAssertEqual(view.viewModel.contentState, .searching) diff --git a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapInteractor.swift b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapInteractor.swift index 3bbedc1dbc..d56e7f9995 100644 --- a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapInteractor.swift +++ b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapInteractor.swift @@ -45,8 +45,8 @@ final class SearchOnMapInteractor: NSObject { return processSelectedText(searchText, isCategory: isCategory) case .searchButtonDidTap(let searchText): return processSearchButtonDidTap(searchText) - case .didSelectResult(let result, let index, let searchText): - return processSelectedResult(result, index: index, searchText: searchText) + case .didSelectResult(let result, let searchText): + return processSelectedResult(result, searchText: searchText) case .didSelectPlaceOnMap: return isIPad ? .none : .setSearchScreenHidden(true) case .didDeselectPlaceOnMap: @@ -93,14 +93,14 @@ final class SearchOnMapInteractor: NSObject { return .selectText(searchText.text) } - private func processSelectedResult(_ result: SearchResult, index: Int, searchText: SearchOnMap.SearchText) -> SearchOnMap.Response { + private func processSelectedResult(_ result: SearchResult, searchText: SearchOnMap.SearchText) -> SearchOnMap.Response { switch result.itemType { case .regular: searchManager.saveQuery(searchText.text, forInputLocale:searchText.locale) switch routingTooltipSearch { case .none: - searchManager.showResult(at: UInt(index)) + searchManager.showResult(at: result.index) case .start: let point = MWMRoutePoint(cgPoint: result.point, title: result.titleText, diff --git a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapModels.swift b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapModels.swift index 2f9db11c18..8147e534f3 100644 --- a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapModels.swift +++ b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapModels.swift @@ -49,7 +49,7 @@ enum SearchOnMap { case didStartTyping case didType(SearchText) case didSelectText(SearchText, isCategory: Bool) - case didSelectResult(SearchResult, atIndex: Int, withSearchText: SearchText) + case didSelectResult(SearchResult, withSearchText: SearchText) case searchButtonDidTap(SearchText) case clearButtonDidTap case didSelectPlaceOnMap diff --git a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift index 0886e5126d..75d6c827b1 100644 --- a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift +++ b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift @@ -303,7 +303,7 @@ extension SearchOnMapViewController: UITableViewDataSource { extension SearchOnMapViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let result = searchResults[indexPath.row] - interactor.handle(.didSelectResult(result, atIndex: indexPath.row, withSearchText: headerView.searchText)) + interactor.handle(.didSelectResult(result, withSearchText: headerView.searchText)) tableView.deselectRow(at: indexPath, animated: true) }