forked from organicmaps/organicmaps-tmp
[ios] replace usage of cpp search::Result
with objc SearchResult
in UI
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
parent
69953c2b12
commit
5ffd95a491
19 changed files with 229 additions and 150 deletions
|
@ -52,7 +52,6 @@
|
|||
#import "MWMRouterTransitStepInfo.h"
|
||||
#import "MWMRoutingManager.h"
|
||||
#import "MWMRoutingOptions.h"
|
||||
#import "MWMSearchItemType.h"
|
||||
#import "MWMSearchNoResults.h"
|
||||
#import "MWMSettings.h"
|
||||
#import "MWMSideButtons.h"
|
||||
|
@ -76,3 +75,7 @@
|
|||
#import "UIViewController+Navigation.h"
|
||||
#import "WebViewController.h"
|
||||
#import "MWMMapViewControlsCommon.h"
|
||||
#import "MWMSearchCommonCell.h"
|
||||
#import "MWMSearchSuggestionCell.h"
|
||||
#import "MWMSearch.h"
|
||||
#import "SearchResult.h"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#import "MWMCarPlaySearchResultObject.h"
|
||||
#import "MWMSearch.h"
|
||||
#import "SearchResult.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
#include "search/result.hpp"
|
||||
|
||||
|
@ -24,16 +26,14 @@
|
|||
if (self) {
|
||||
self.originalRow = row;
|
||||
NSInteger containerIndex = [MWMSearch containerIndexWithRow:row];
|
||||
MWMSearchItemType type = [MWMSearch resultTypeWithRow:row];
|
||||
if (type == MWMSearchItemTypeRegular) {
|
||||
SearchItemType type = [MWMSearch resultTypeWithRow:row];
|
||||
if (type == SearchItemTypeRegular) {
|
||||
auto const & result = [MWMSearch resultWithContainerIndex:containerIndex];
|
||||
NSString *localizedTypeName = @(result.GetLocalizedFeatureType().c_str());
|
||||
self.title = result.GetString().empty() ? localizedTypeName : @(result.GetString().c_str());
|
||||
self.address = @(result.GetAddress().c_str());
|
||||
auto const pivot = result.GetFeatureCenter();
|
||||
self.title = result.titleText;
|
||||
self.address = result.addressText;
|
||||
self.coordinate = result.coordinate;
|
||||
auto const pivot = mercator::FromLatLon(result.coordinate.latitude, result.coordinate.longitude);
|
||||
self.mercatorPoint = CGPointMake(pivot.x, pivot.y);
|
||||
auto const location = mercator::ToLatLon(pivot);
|
||||
self.coordinate = CLLocationCoordinate2DMake(location.m_lat, location.m_lon);
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#import <CoreApi/MWMTypes.h>
|
||||
|
||||
#import "MWMSearchItemType.h"
|
||||
#import "MWMSearchObserver.h"
|
||||
#import "SearchItemType.h"
|
||||
|
||||
namespace search {
|
||||
class Result;
|
||||
} // namespace search
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SearchResult;
|
||||
|
||||
NS_SWIFT_NAME(Search)
|
||||
@interface MWMSearch : NSObject
|
||||
|
||||
+ (void)addObserver:(id<MWMSearchObserver>)observer;
|
||||
|
@ -15,11 +14,11 @@ class Result;
|
|||
+ (void)saveQuery:(NSString *)query forInputLocale:(NSString *)inputLocale;
|
||||
+ (void)searchQuery:(NSString *)query forInputLocale:(NSString *)inputLocale withCategory:(BOOL)isCategory;
|
||||
|
||||
+ (void)showResult:(search::Result const &)result;
|
||||
+ (void)showResultAtIndex:(NSUInteger)index;
|
||||
|
||||
+ (MWMSearchItemType)resultTypeWithRow:(NSUInteger)row;
|
||||
+ (SearchItemType)resultTypeWithRow:(NSUInteger)row;
|
||||
+ (NSUInteger)containerIndexWithRow:(NSUInteger)row;
|
||||
+ (search::Result const &)resultWithContainerIndex:(NSUInteger)index;
|
||||
+ (SearchResult *)resultWithContainerIndex:(NSUInteger)index;
|
||||
|
||||
+ (void)clear;
|
||||
|
||||
|
@ -35,3 +34,5 @@ class Result;
|
|||
+ (instancetype)new __attribute__((unavailable("call +manager instead")));
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#import "MWMSearch.h"
|
||||
#import "MWMFrameworkListener.h"
|
||||
#import "MWMFrameworkObservers.h"
|
||||
#import "SearchResult+Core.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
#include <CoreApi/MWMTypes.h>
|
||||
#include <CoreApi/Framework.h>
|
||||
|
||||
#include "platform/network_policy.hpp"
|
||||
|
@ -23,7 +25,7 @@ using Observers = NSHashTable<Observer>;
|
|||
|
||||
@property(nonatomic) NSUInteger lastSearchTimestamp;
|
||||
|
||||
@property(nonatomic) MWMSearchIndex *itemsIndex;
|
||||
@property(nonatomic) SearchIndex *itemsIndex;
|
||||
|
||||
@property(nonatomic) NSInteger searchCount;
|
||||
|
||||
|
@ -161,14 +163,19 @@ using Observers = NSHashTable<Observer>;
|
|||
[manager update];
|
||||
}
|
||||
|
||||
+ (void)showResult:(search::Result const &)result {
|
||||
+ (void)showResultAtIndex:(NSUInteger)index {
|
||||
auto const & result = [MWMSearch manager]->m_everywhereResults[index];
|
||||
GetFramework().ShowSearchResult(result);
|
||||
}
|
||||
+ (search::Result const &)resultWithContainerIndex:(NSUInteger)index {
|
||||
return [MWMSearch manager]->m_everywhereResults[index];
|
||||
|
||||
+ (SearchResult *)resultWithContainerIndex:(NSUInteger)index {
|
||||
SearchResult * result = [[SearchResult alloc]
|
||||
initWithResult:[MWMSearch manager]->m_everywhereResults[index]
|
||||
itemType:[MWMSearch resultTypeWithRow:index]];
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (MWMSearchItemType)resultTypeWithRow:(NSUInteger)row {
|
||||
+ (SearchItemType)resultTypeWithRow:(NSUInteger)row {
|
||||
auto itemsIndex = [MWMSearch manager].itemsIndex;
|
||||
return [itemsIndex resultTypeWithRow:row];
|
||||
}
|
||||
|
@ -216,7 +223,7 @@ using Observers = NSHashTable<Observer>;
|
|||
|
||||
- (void)updateItemsIndexWithBannerReload:(BOOL)reloadBanner {
|
||||
auto const resultsCount = self->m_everywhereResults.GetCount();
|
||||
auto const itemsIndex = [[MWMSearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount
|
||||
auto const itemsIndex = [[SearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount
|
||||
resultsCount:resultsCount];
|
||||
[itemsIndex build];
|
||||
self.itemsIndex = itemsIndex;
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
typedef NS_ENUM(NSUInteger, MWMSearchItemType) {
|
||||
// Order == priority.
|
||||
MWMSearchItemTypeRegular,
|
||||
MWMSearchItemTypeSuggestion
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
@objc(MWMSearchIndex)
|
||||
@objc
|
||||
final class SearchIndex: NSObject {
|
||||
fileprivate struct Item {
|
||||
let type: MWMSearchItemType
|
||||
let type: SearchItemType
|
||||
let containerIndex: Int
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,14 @@ final class SearchIndex: NSObject {
|
|||
|
||||
@objc init(suggestionsCount: Int, resultsCount: Int) {
|
||||
for index in 0 ..< resultsCount {
|
||||
let type: MWMSearchItemType = index < suggestionsCount ? .suggestion : .regular
|
||||
let type: SearchItemType = index < suggestionsCount ? .suggestion : .regular
|
||||
let item = Item(type: type, containerIndex: index)
|
||||
positionItems.append(PositionItem(item: item, position: index))
|
||||
}
|
||||
super.init()
|
||||
}
|
||||
|
||||
func addItem(type: MWMSearchItemType, prefferedPosition: Int, containerIndex: Int) {
|
||||
func addItem(type: SearchItemType, prefferedPosition: Int, containerIndex: Int) {
|
||||
assert(type != .suggestion && type != .regular)
|
||||
let item = Item(type: type, containerIndex: containerIndex)
|
||||
positionItems.append(PositionItem(item: item, position: prefferedPosition))
|
||||
|
@ -53,7 +53,7 @@ final class SearchIndex: NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
@objc func resultType(row: Int) -> MWMSearchItemType {
|
||||
@objc func resultType(row: Int) -> SearchItemType {
|
||||
return items[row].type
|
||||
}
|
||||
|
||||
|
|
4
iphone/Maps/Core/Search/SearchItemType.h
Normal file
4
iphone/Maps/Core/Search/SearchItemType.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
typedef NS_ENUM(NSInteger, SearchItemType) {
|
||||
SearchItemTypeRegular,
|
||||
SearchItemTypeSuggestion
|
||||
};
|
13
iphone/Maps/Core/Search/SearchResult+Core.h
Normal file
13
iphone/Maps/Core/Search/SearchResult+Core.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#import "SearchResult.h"
|
||||
|
||||
#import "search/result.hpp"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SearchResult (Core)
|
||||
|
||||
- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
26
iphone/Maps/Core/Search/SearchResult.h
Normal file
26
iphone/Maps/Core/Search/SearchResult.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#import "SearchItemType.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SearchResult : NSObject
|
||||
|
||||
@property (nonatomic, readonly) NSString * titleText;
|
||||
@property (nonatomic, readonly) NSString * addressText;
|
||||
@property (nonatomic, readonly) NSString * infoText;
|
||||
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
|
||||
@property (nonatomic, readonly) CGPoint point;
|
||||
@property (nonatomic, readonly, nullable) NSString * distanceText;
|
||||
@property (nonatomic, readonly, nullable) NSString * openStatusText;
|
||||
@property (nonatomic, readonly) UIColor * openStatusColor;
|
||||
@property (nonatomic, readonly) BOOL isPopularHidden;
|
||||
@property (nonatomic, readonly) NSString * suggestion;
|
||||
@property (nonatomic, readonly) BOOL isPureSuggest;
|
||||
@property (nonatomic, readonly) NSArray<NSValue *> * highlightRanges;
|
||||
@property (nonatomic, readonly) SearchItemType itemType;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
87
iphone/Maps/Core/Search/SearchResult.mm
Normal file
87
iphone/Maps/Core/Search/SearchResult.mm
Normal file
|
@ -0,0 +1,87 @@
|
|||
#import "SearchResult+Core.h"
|
||||
#import "CLLocation+Mercator.h"
|
||||
#import "MWMLocationManager.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
#import "platform/localization.hpp"
|
||||
#import "platform/distance.hpp"
|
||||
|
||||
#import "geometry/mercator.hpp"
|
||||
|
||||
@implementation SearchResult
|
||||
@end
|
||||
|
||||
@implementation SearchResult(Core)
|
||||
|
||||
- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_titleText = result.GetString().empty() ? @(result.GetLocalizedFeatureType().c_str()) : @(result.GetString().c_str());
|
||||
_addressText = @(result.GetAddress().c_str());
|
||||
_infoText = @(result.GetFeatureDescription().c_str());
|
||||
if (result.IsSuggest())
|
||||
_suggestion = @(result.GetSuggestionString().c_str());
|
||||
|
||||
CLLocation * lastLocation = [MWMLocationManager lastLocation];
|
||||
if (lastLocation && result.HasPoint()) {
|
||||
double distanceInMeters = mercator::DistanceOnEarth(lastLocation.mercator, result.GetFeatureCenter());
|
||||
std::string distanceStr = platform::Distance::CreateFormatted(distanceInMeters).ToString();
|
||||
_distanceText = @(distanceStr.c_str());
|
||||
|
||||
auto const & pivot = result.GetFeatureCenter();
|
||||
_point = CGPointMake(pivot.x, pivot.y);
|
||||
auto const location = mercator::ToLatLon(pivot);
|
||||
_coordinate = CLLocationCoordinate2DMake(location.m_lat, location.m_lon);
|
||||
} else {
|
||||
_distanceText = nil;
|
||||
}
|
||||
|
||||
switch (result.IsOpenNow()) {
|
||||
case osm::Yes: {
|
||||
const int minutes = result.GetMinutesUntilClosed();
|
||||
if (minutes < 60) { // less than 1 hour
|
||||
_openStatusColor = UIColor.systemYellowColor;
|
||||
NSString * time = [NSString stringWithFormat:@"%d %@", minutes, L(@"minute")];
|
||||
_openStatusText = [NSString stringWithFormat:L(@"closes_in"), time];
|
||||
} else {
|
||||
_openStatusColor = UIColor.systemGreenColor;
|
||||
_openStatusText = L(@"editor_time_open");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case osm::No: {
|
||||
const int minutes = result.GetMinutesUntilOpen();
|
||||
if (minutes < 60) { // less than 1 hour
|
||||
NSString * time = [NSString stringWithFormat:@"%d %@", minutes, L(@"minute")];
|
||||
_openStatusText = [NSString stringWithFormat:L(@"opens_in"), time];
|
||||
} else {
|
||||
_openStatusText = L(@"closed");
|
||||
}
|
||||
_openStatusColor = UIColor.systemRedColor;
|
||||
break;
|
||||
}
|
||||
case osm::Unknown: {
|
||||
_openStatusText = nil;
|
||||
_openStatusColor = UIColor.clearColor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_isPopularHidden = YES; // Restore logic in the future when popularity is available.
|
||||
_isPureSuggest = result.GetResultType() == search::Result::Type::PureSuggest;
|
||||
|
||||
NSMutableArray<NSValue *> * ranges = [NSMutableArray array];
|
||||
size_t const rangesCount = result.GetHighlightRangesCount();
|
||||
for (size_t i = 0; i < rangesCount; ++i) {
|
||||
auto const &range = result.GetHighlightRange(i);
|
||||
NSRange nsRange = NSMakeRange(range.first, range.second);
|
||||
[ranges addObject:[NSValue valueWithRange:nsRange]];
|
||||
}
|
||||
_highlightRanges = [ranges copy];
|
||||
|
||||
_itemType = itemType;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -495,6 +495,7 @@
|
|||
ED4DC7782CAEDECC0029B338 /* ProductButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED4DC7732CAEDECC0029B338 /* ProductButton.swift */; };
|
||||
ED4DC7792CAEDECC0029B338 /* ProductsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED4DC7742CAEDECC0029B338 /* ProductsViewController.swift */; };
|
||||
ED63CEB92BDF8F9D006155C4 /* SettingsTableViewiCloudSwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED63CEB62BDF8F9C006155C4 /* SettingsTableViewiCloudSwitchCell.swift */; };
|
||||
ED70D55C2D5396F300738C1E /* SearchResult.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED70D55A2D5396F300738C1E /* SearchResult.mm */; };
|
||||
ED77556E2C2C490B0051E656 /* UIAlertController+openInAppActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED77556D2C2C490B0051E656 /* UIAlertController+openInAppActionSheet.swift */; };
|
||||
ED79A5AB2BD7AA9C00952D1F /* LoadingOverlayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED79A5AA2BD7AA9C00952D1F /* LoadingOverlayViewController.swift */; };
|
||||
ED79A5AD2BD7BA0F00952D1F /* UIApplication+LoadingOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED79A5AC2BD7BA0F00952D1F /* UIApplication+LoadingOverlay.swift */; };
|
||||
|
@ -855,7 +856,6 @@
|
|||
340E1EE81E2F614400CE49BF /* Settings.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Settings.storyboard; sourceTree = "<group>"; };
|
||||
340E1EE91E2F614400CE49BF /* Storyboard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Storyboard.swift; sourceTree = "<group>"; };
|
||||
340E1EEA1E2F614400CE49BF /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Welcome.storyboard; sourceTree = "<group>"; };
|
||||
342639461EA0FDB30025EB89 /* MWMSearchItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMSearchItemType.h; sourceTree = "<group>"; };
|
||||
3426DEB11F45AE2800D1C43C /* MWMRouterType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMRouterType.h; sourceTree = "<group>"; };
|
||||
3426DEB21F45AE5100D1C43C /* MWMRouterRecommendation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMRouterRecommendation.h; sourceTree = "<group>"; };
|
||||
3427AF0B1E49E3A500D466DB /* MWMConsts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMConsts.h; sourceTree = "<group>"; };
|
||||
|
@ -1459,6 +1459,10 @@
|
|||
ED4DC7742CAEDECC0029B338 /* ProductsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsViewController.swift; sourceTree = "<group>"; };
|
||||
ED4DC7752CAEDECC0029B338 /* ProductsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsViewModel.swift; sourceTree = "<group>"; };
|
||||
ED63CEB62BDF8F9C006155C4 /* SettingsTableViewiCloudSwitchCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewiCloudSwitchCell.swift; sourceTree = "<group>"; };
|
||||
ED70D5582D5396F300738C1E /* SearchItemType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SearchItemType.h; sourceTree = "<group>"; };
|
||||
ED70D5592D5396F300738C1E /* SearchResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SearchResult.h; sourceTree = "<group>"; };
|
||||
ED70D55A2D5396F300738C1E /* SearchResult.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SearchResult.mm; sourceTree = "<group>"; };
|
||||
ED70D55B2D5396F300738C1E /* SearchResult+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SearchResult+Core.h"; sourceTree = "<group>"; };
|
||||
ED77556D2C2C490B0051E656 /* UIAlertController+openInAppActionSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+openInAppActionSheet.swift"; sourceTree = "<group>"; };
|
||||
ED79A5AA2BD7AA9C00952D1F /* LoadingOverlayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingOverlayViewController.swift; sourceTree = "<group>"; };
|
||||
ED79A5AC2BD7BA0F00952D1F /* UIApplication+LoadingOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+LoadingOverlay.swift"; sourceTree = "<group>"; };
|
||||
|
@ -2119,13 +2123,16 @@
|
|||
340475391E081A4600C92850 /* Search */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
ED70D5582D5396F300738C1E /* SearchItemType.h */,
|
||||
ED70D5592D5396F300738C1E /* SearchResult.h */,
|
||||
ED70D55A2D5396F300738C1E /* SearchResult.mm */,
|
||||
ED70D55B2D5396F300738C1E /* SearchResult+Core.h */,
|
||||
3404753A1E081A4600C92850 /* MWMSearch+CoreSpotlight.h */,
|
||||
3404753B1E081A4600C92850 /* MWMSearch+CoreSpotlight.mm */,
|
||||
3404753C1E081A4600C92850 /* MWMSearch.h */,
|
||||
3404753D1E081A4600C92850 /* MWMSearch.mm */,
|
||||
3404753E1E081A4600C92850 /* MWMSearchObserver.h */,
|
||||
3430643F1E9FDC7300DC7665 /* SearchIndex.swift */,
|
||||
342639461EA0FDB30025EB89 /* MWMSearchItemType.h */,
|
||||
);
|
||||
path = Search;
|
||||
sourceTree = "<group>";
|
||||
|
@ -4656,6 +4663,7 @@
|
|||
FA85D43D27958BF500B858E9 /* FaqController.swift in Sources */,
|
||||
99A906ED23F6F7030005872B /* PlacePagePreviewViewController.swift in Sources */,
|
||||
993DF10223F6BDB100AC231A /* Colors.swift in Sources */,
|
||||
ED70D55C2D5396F300738C1E /* SearchResult.mm in Sources */,
|
||||
34AB66201FC5AA330078E451 /* RouteStartButton.swift in Sources */,
|
||||
AC79C8922A65AB9500594C24 /* UIColor+hexString.swift in Sources */,
|
||||
99DEF9D723E420F6006BFD21 /* ElevationProfileDescriptionCell.swift in Sources */,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#import "MWMSearchManager+Layout.h"
|
||||
#import "MWMSearchTableViewController.h"
|
||||
#import "MapViewController.h"
|
||||
#import "SearchResult.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
namespace {
|
||||
|
@ -149,16 +150,17 @@ const CGFloat kWidthForiPad = 320;
|
|||
- (void)dismissKeyboard {
|
||||
[self.searchTextField resignFirstResponder];
|
||||
}
|
||||
- (void)processSearchWithResult:(search::Result const &)result {
|
||||
- (void)processSearchResultAtIndex:(NSInteger)index {
|
||||
if (self.routingTooltipSearch == MWMSearchManagerRoutingTooltipSearchNone) {
|
||||
[MWMSearch showResult:result];
|
||||
[MWMSearch showResultAtIndex:index];
|
||||
} else {
|
||||
BOOL const isStart = self.routingTooltipSearch == MWMSearchManagerRoutingTooltipSearchStart;
|
||||
auto point = [[MWMRoutePoint alloc] initWithPoint:result.GetFeatureCenter()
|
||||
title:@(result.GetString().c_str())
|
||||
subtitle:@(result.GetAddress().c_str())
|
||||
type:isStart ? MWMRoutePointTypeStart : MWMRoutePointTypeFinish
|
||||
intermediateIndex:0];
|
||||
SearchResult * result = [MWMSearch resultWithContainerIndex:index];
|
||||
auto point = [[MWMRoutePoint alloc] initWithCGPoint:result.point
|
||||
title:result.titleText
|
||||
subtitle:result.addressText
|
||||
type:isStart ? MWMRoutePointTypeStart : MWMRoutePointTypeFinish
|
||||
intermediateIndex:0];
|
||||
if (isStart)
|
||||
[MWMRouter buildFromPoint:point bestRouter:NO];
|
||||
else
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#import "MWMTableViewCell.h"
|
||||
|
||||
namespace search { class Result; }
|
||||
@class SearchResult;
|
||||
|
||||
@interface MWMSearchCell : MWMTableViewCell
|
||||
|
||||
- (void)config:(search::Result const &)result
|
||||
localizedTypeName:(NSString *)localizedTypeName;
|
||||
- (void)configureWith:(SearchResult * _Nonnull)result;
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#import "MWMSearchCell.h"
|
||||
|
||||
#include "search/result.hpp"
|
||||
#import "SearchResult.h"
|
||||
|
||||
@interface MWMSearchCell ()
|
||||
|
||||
|
@ -10,11 +9,9 @@
|
|||
|
||||
@implementation MWMSearchCell
|
||||
|
||||
- (void)config:(search::Result const &)result
|
||||
localizedTypeName:(NSString *)localizedTypeName
|
||||
{
|
||||
NSString * title = result.GetString().empty() ? localizedTypeName : @(result.GetString().c_str());
|
||||
|
||||
- (void)configureWith:(SearchResult * _Nonnull)result {
|
||||
NSString * title = result.titleText;
|
||||
|
||||
if (title.length == 0)
|
||||
{
|
||||
self.titleLabel.text = @"";
|
||||
|
@ -31,18 +28,15 @@
|
|||
NSMutableAttributedString * attributedTitle =
|
||||
[[NSMutableAttributedString alloc] initWithString:title];
|
||||
[attributedTitle addAttributes:unselectedTitleAttributes range:NSMakeRange(0, title.length)];
|
||||
size_t const rangesCount = result.GetHighlightRangesCount();
|
||||
for (size_t i = 0; i < rangesCount; ++i)
|
||||
{
|
||||
std::pair<uint16_t, uint16_t> const & range = result.GetHighlightRange(i);
|
||||
|
||||
if (range.first + range.second <= title.length)
|
||||
{
|
||||
[attributedTitle addAttributes:selectedTitleAttributes range:NSMakeRange(range.first, range.second)];
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LERROR, ("Incorrect range: ", range, " for string: ", result.GetString()));
|
||||
NSArray<NSValue *> *highlightRanges = result.highlightRanges;
|
||||
|
||||
for (NSValue *rangeValue in highlightRanges) {
|
||||
NSRange range = [rangeValue rangeValue];
|
||||
if (NSMaxRange(range) <= result.titleText.length) {
|
||||
[attributedTitle addAttributes:selectedTitleAttributes range:range];
|
||||
} else {
|
||||
NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), result.titleText);
|
||||
}
|
||||
}
|
||||
self.titleLabel.attributedText = attributedTitle;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#import "MWMSearchCell.h"
|
||||
|
||||
#include "map/everywhere_search_callback.hpp"
|
||||
|
||||
#include "search/result.hpp"
|
||||
@class SearchResult;
|
||||
|
||||
NS_SWIFT_NAME(SearchCommonCell)
|
||||
@interface MWMSearchCommonCell : MWMSearchCell
|
||||
|
||||
- (void)config:(search::Result const &)result localizedTypeName:(NSString *)localizedTypeName;
|
||||
- (void)configureWith:(SearchResult * _Nonnull)result;
|
||||
|
||||
@end
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#import "CLLocation+Mercator.h"
|
||||
#import "MWMLocationManager.h"
|
||||
#import "SwiftBridge.h"
|
||||
#import "SearchResult.h"
|
||||
|
||||
#include "map/place_page_info.hpp"
|
||||
|
||||
|
@ -10,7 +11,6 @@
|
|||
#include "platform/localization.hpp"
|
||||
#include "platform/distance.hpp"
|
||||
|
||||
|
||||
@interface MWMSearchCommonCell ()
|
||||
|
||||
@property(weak, nonatomic) IBOutlet UILabel * distanceLabel;
|
||||
|
@ -23,76 +23,17 @@
|
|||
|
||||
@implementation MWMSearchCommonCell
|
||||
|
||||
- (void)config:(search::Result const &)result localizedTypeName:(NSString *)localizedTypeName
|
||||
{
|
||||
[super config:result localizedTypeName:localizedTypeName];
|
||||
|
||||
self.locationLabel.text = @(result.GetAddress().c_str());
|
||||
- (void)configureWith:(SearchResult * _Nonnull)result {
|
||||
[super configureWith:result];
|
||||
self.locationLabel.text = result.addressText;
|
||||
[self.locationLabel sizeToFit];
|
||||
|
||||
self.infoLabel.text = @(result.GetFeatureDescription().c_str());
|
||||
|
||||
CLLocation * lastLocation = [MWMLocationManager lastLocation];
|
||||
double distanceInMeters = 0.0;
|
||||
if (lastLocation)
|
||||
{
|
||||
if (result.HasPoint())
|
||||
{
|
||||
distanceInMeters =
|
||||
mercator::DistanceOnEarth(lastLocation.mercator, result.GetFeatureCenter());
|
||||
std::string distanceStr = platform::Distance::CreateFormatted(distanceInMeters).ToString();
|
||||
self.distanceLabel.text = @(distanceStr.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo Restore "TOP" badge in future, when popularity will be available.
|
||||
//self.popularView.hidden = result.GetRankingInfo().m_popularity == 0;
|
||||
self.infoLabel.text = result.infoText;
|
||||
self.distanceLabel.text = result.distanceText;
|
||||
self.popularView.hidden = YES;
|
||||
|
||||
switch (result.IsOpenNow())
|
||||
{
|
||||
case osm::Yes:
|
||||
{
|
||||
int const minutes = result.GetMinutesUntilClosed();
|
||||
if (minutes < 60) // less than 1 hour
|
||||
{
|
||||
self.openLabel.textColor = UIColor.systemYellowColor;
|
||||
NSString *time = [NSString stringWithFormat: @"%d %@", minutes, L(@"minute")];
|
||||
self.openLabel.text = [NSString stringWithFormat: L(@"closes_in"), time];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.openLabel.textColor = UIColor.systemGreenColor;
|
||||
self.openLabel.text = L(@"editor_time_open");
|
||||
}
|
||||
self.openLabel.hidden = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case osm::No:
|
||||
{
|
||||
self.openLabel.textColor = UIColor.systemRedColor;
|
||||
int const minutes = result.GetMinutesUntilOpen();
|
||||
if (minutes < 60) // less than 1 hour
|
||||
{
|
||||
NSString *time = [NSString stringWithFormat: @"%d %@", minutes, L(@"minute")];
|
||||
self.openLabel.text = [NSString stringWithFormat: L(@"opens_in"), time];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.openLabel.text = L(@"closed");
|
||||
}
|
||||
self.openLabel.hidden = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case osm::Unknown:
|
||||
{
|
||||
self.openLabel.hidden = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
self.openLabel.text = result.openStatusText;
|
||||
self.openLabel.textColor = result.openStatusColor;
|
||||
[self.openLabel setHidden:result.openStatusText.length == 0];
|
||||
[self setStyleNameAndApply: @"Background"];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import "MWMSearchCell.h"
|
||||
|
||||
NS_SWIFT_NAME(SearchSuggestionCell)
|
||||
@interface MWMSearchSuggestionCell : MWMSearchCell
|
||||
|
||||
@property (nonatomic) BOOL isLastCell;
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include <CoreApi/Framework.h>
|
||||
|
||||
@class SearchTextField;
|
||||
namespace search
|
||||
{
|
||||
class Result;
|
||||
} // search
|
||||
|
||||
@protocol MWMSearchTableViewProtocol<MWMSearchTabbedViewProtocol>
|
||||
|
||||
|
@ -17,7 +13,7 @@ class Result;
|
|||
|
||||
@property(nonatomic) MWMSearchManagerState state;
|
||||
|
||||
- (void)processSearchWithResult:(search::Result const &)result;
|
||||
- (void)processSearchResultAtIndex:(NSInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#import "MWMSearchCommonCell.h"
|
||||
#import "MWMSearchSuggestionCell.h"
|
||||
#import "MWMSearchTableView.h"
|
||||
#import "SearchResult.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
#include "platform/localization.hpp"
|
||||
|
@ -85,18 +86,18 @@ NSString *GetLocalizedTypeName(search::Result const &result) {
|
|||
|
||||
switch ([MWMSearch resultTypeWithRow:row])
|
||||
{
|
||||
case MWMSearchItemTypeRegular:
|
||||
case SearchItemTypeRegular:
|
||||
{
|
||||
auto cell = static_cast<MWMSearchCommonCell *>(
|
||||
[tableView dequeueReusableCellWithCellClass:[MWMSearchCommonCell class] indexPath:indexPath]);
|
||||
[cell config:result localizedTypeName:GetLocalizedTypeName(result)];
|
||||
[cell configureWith:result];
|
||||
return cell;
|
||||
}
|
||||
case MWMSearchItemTypeSuggestion:
|
||||
case SearchItemTypeSuggestion:
|
||||
{
|
||||
auto cell = static_cast<MWMSearchSuggestionCell *>(
|
||||
[tableView dequeueReusableCellWithCellClass:[MWMSearchSuggestionCell class] indexPath:indexPath]);
|
||||
[cell config:result localizedTypeName:@""];
|
||||
[cell configureWith:result];
|
||||
cell.isLastCell = row == [MWMSearch suggestionsCount] - 1;
|
||||
return cell;
|
||||
}
|
||||
|
@ -113,17 +114,18 @@ NSString *GetLocalizedTypeName(search::Result const &result) {
|
|||
|
||||
switch ([MWMSearch resultTypeWithRow:row])
|
||||
{
|
||||
case MWMSearchItemTypeRegular:
|
||||
case SearchItemTypeRegular:
|
||||
{
|
||||
SearchTextField const * textField = delegate.searchTextField;
|
||||
[MWMSearch saveQuery:textField.text forInputLocale:textField.textInputMode.primaryLanguage];
|
||||
[delegate processSearchWithResult:result];
|
||||
[delegate processSearchResultAtIndex:indexPath.row];
|
||||
break;
|
||||
}
|
||||
case MWMSearchItemTypeSuggestion:
|
||||
case SearchItemTypeSuggestion:
|
||||
{
|
||||
[delegate searchText:@(result.GetSuggestionString().c_str()) forInputLocale:nil
|
||||
withCategory:result.GetResultType() == search::Result::Type::PureSuggest];
|
||||
[delegate searchText:result.suggestion
|
||||
forInputLocale:nil
|
||||
withCategory:result.isPureSuggest];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue