diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderPlaceTableViewCell.mm b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderPlaceTableViewCell.mm index d5d341b6d2..97f77b1cd0 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderPlaceTableViewCell.mm +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderPlaceTableViewCell.mm @@ -1,5 +1,18 @@ #import "Common.h" #import "MWMMapDownloaderPlaceTableViewCell.h" +#import "UIFont+MapsMeFonts.h" + +namespace +{ + NSDictionary * const kSelectedAreaAttrs = @{ NSFontAttributeName : [UIFont bold12] }; + NSDictionary * const kUnselectedAreaAttrs = @{ NSFontAttributeName : [UIFont regular12] }; +} // namespace + +@interface MWMMapDownloaderTableViewCell () + +- (NSAttributedString *)matchedString:(NSString *)str selectedAttrs:(NSDictionary *)selectedAttrs unselectedAttrs:(NSDictionary *)unselectedAttrs; + +@end @interface MWMMapDownloaderPlaceTableViewCell () @@ -32,7 +45,9 @@ [super config:nodeAttrs]; BOOL const isAreaVisible = (self.needDisplayArea && nodeAttrs.m_parentInfo.size() == 1); if (isAreaVisible) - self.area.text = @(nodeAttrs.m_parentInfo[0].m_localName.c_str()); + self.area.attributedText = [self matchedString:@(nodeAttrs.m_parentInfo[0].m_localName.c_str()) + selectedAttrs:kSelectedAreaAttrs + unselectedAttrs:kUnselectedAreaAttrs]; self.area.hidden = !isAreaVisible; self.titleBottomOffset.priority = isAreaVisible ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh; } diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderSubplaceTableViewCell.mm b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderSubplaceTableViewCell.mm index 06fc06f43e..adc95d9537 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderSubplaceTableViewCell.mm +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderSubplaceTableViewCell.mm @@ -1,5 +1,18 @@ #import "Common.h" #import "MWMMapDownloaderSubplaceTableViewCell.h" +#import "UIFont+MapsMeFonts.h" + +namespace +{ + NSDictionary * const kSelectedSubPlaceAttrs = @{ NSFontAttributeName : [UIFont bold14] }; + NSDictionary * const kUnselectedSubPlaceAttrs = @{ NSFontAttributeName : [UIFont regular14] }; +} // namespace + +@interface MWMMapDownloaderTableViewCell () + +- (NSAttributedString *)matchedString:(NSString *)str selectedAttrs:(NSDictionary *)selectedAttrs unselectedAttrs:(NSDictionary *)unselectedAttrs; + +@end @interface MWMMapDownloaderSubplaceTableViewCell () @@ -26,7 +39,9 @@ - (void)setSubplaceText:(NSString *)text { - self.subPlace.text = text; + self.subPlace.attributedText = [self matchedString:text + selectedAttrs:kSelectedSubPlaceAttrs + unselectedAttrs:kUnselectedSubPlaceAttrs]; } @end diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h index 6cf4ab1ead..2bfa8dcde4 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h @@ -16,6 +16,6 @@ @property (weak, nonatomic) id delegate; - (void)config:(storage::NodeAttrs const &)nodeAttrs; -- (void)setCountryId:(NSString *)countryId; +- (void)setCountryId:(NSString *)countryId searchQuery:(NSString *)query; @end diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm index 0782dcb7d1..f01a0d1cf5 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm @@ -1,12 +1,22 @@ #import "Common.h" #import "MWMCircularProgress.h" #import "MWMMapDownloaderTableViewCell.h" +#import "NSString+Categories.h" +#import "UIFont+MapsMeFonts.h" #include "Framework.h" +namespace +{ + NSDictionary * const kSelectedTitleAttrs = @{ NSFontAttributeName : [UIFont bold17] }; + NSDictionary * const kUnselectedTitleAttrs = @{ NSFontAttributeName : [UIFont regular17] }; +} // namespace + @interface MWMMapDownloaderTableViewCell () @property (nonatomic) MWMCircularProgress * progress; +@property (copy, nonatomic) NSString * searchQuery; + @property (weak, nonatomic) IBOutlet UIView * stateWrapper; @property (weak, nonatomic) IBOutlet UILabel * title; @property (weak, nonatomic) IBOutlet UILabel * downloadSize; @@ -46,12 +56,27 @@ } } +#pragma mark - Search matching + +- (NSAttributedString *)matchedString:(NSString *)str selectedAttrs:(NSDictionary *)selectedAttrs unselectedAttrs:(NSDictionary *)unselectedAttrs +{ + NSMutableAttributedString * attrTitle = [[NSMutableAttributedString alloc] initWithString:str]; + [attrTitle addAttributes:unselectedAttrs range:{0, str.length}]; + if (!self.searchQuery) + return [attrTitle copy]; + for (auto const & range : [str rangesOfString:self.searchQuery]) + [attrTitle addAttributes:selectedAttrs range:range]; + return [attrTitle copy]; +} + #pragma mark - Config - (void)config:(storage::NodeAttrs const &)nodeAttrs { [self configProgress:nodeAttrs]; - self.title.text = @(nodeAttrs.m_nodeLocalName.c_str()); + self.title.attributedText = [self matchedString:@(nodeAttrs.m_nodeLocalName.c_str()) + selectedAttrs:kSelectedTitleAttrs + unselectedAttrs:kUnselectedTitleAttrs]; self.downloadSize.text = formattedSize(nodeAttrs.m_mwmSize); } @@ -144,10 +169,11 @@ #pragma mark - Properties -- (void)setCountryId:(NSString *)countryId +- (void)setCountryId:(NSString *)countryId searchQuery:(NSString *)query { - if (m_countryId == countryId.UTF8String) + if (m_countryId == countryId.UTF8String && [query isEqualToString:self.searchQuery]) return; + self.searchQuery = query; m_countryId = countryId.UTF8String; storage::NodeAttrs nodeAttrs; GetFramework().Storage().GetNodeAttrs(m_countryId, nodeAttrs); diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm index 26c29ef230..c1d0a84d32 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm @@ -34,7 +34,7 @@ using namespace storage; - (void)fillCell:(MWMMapDownloaderTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { NSString * countryId = [self countryIdForIndexPath:indexPath]; - [cell setCountryId:countryId]; + [cell setCountryId:countryId searchQuery:[self searchQuery]]; if ([cell isKindOfClass:[MWMMapDownloaderPlaceTableViewCell class]]) { @@ -103,6 +103,11 @@ using namespace storage; return nil; } +- (NSString *)searchQuery +{ + return nil; +} + - (void)setNeedFullReload:(BOOL)needFullReload { _needFullReload = needFullReload; diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm index daa21ea288..8c3d646a08 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm @@ -12,6 +12,7 @@ extern NSString * const kPlaceCellIdentifier; @property (copy, nonatomic) NSArray * searchCountryIds; @property (copy, nonatomic) NSDictionary * searchMatchedResults; +@property (copy, nonatomic) NSString * searchQuery; @end @@ -31,8 +32,9 @@ extern NSString * const kPlaceCellIdentifier; [nsSearchCountryIds addObject:nsCountryId]; nsSearchResults[nsCountryId] = @(result.m_matchedName.c_str()); } - self.searchCountryIds = [nsSearchCountryIds array]; - self.searchMatchedResults = nsSearchResults; + _searchCountryIds = [nsSearchCountryIds array]; + _searchMatchedResults = nsSearchResults; + _searchQuery = @(results.m_query.c_str()); } return self; }