diff --git a/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.h b/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.h index a4a1318a67..030028eee9 100644 --- a/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.h +++ b/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.h @@ -2,8 +2,7 @@ @protocol MWMCuisineEditorProtocol -- (NSSet *)getCuisines; -- (void)setCuisines:(NSSet *)cuisines; +@property (nonatomic) NSSet * cuisines; @end diff --git a/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.mm b/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.mm index e011dd0e1f..ca04e321a8 100644 --- a/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.mm +++ b/iphone/Maps/Classes/Editor/Cuisine/MWMCuisineEditorViewController.mm @@ -55,8 +55,13 @@ namespace if ([key hasPrefix:prefix]) [cuisineKeys addObject:[key substringFromIndex:prefixLength]]; } - self.cuisineKeys = cuisineKeys.allObjects; - self.selectedCuisines = [[self.delegate getCuisines] mutableCopy]; + self.cuisineKeys = [cuisineKeys.allObjects sortedArrayUsingComparator:^NSComparisonResult(NSString * s1, NSString * s2) + { + NSString * cus1 = L([prefix stringByAppendingString:s1]); + NSString * cus2 = L([prefix stringByAppendingString:s2]); + return [cus1 compare:cus2 options:NSCaseInsensitiveSearch range:{0, cus1.length} locale:[NSLocale currentLocale]]; + }]; + self.selectedCuisines = [self.delegate.cuisines mutableCopy]; } - (void)configTable diff --git a/iphone/Maps/Classes/Editor/MWMEditorSelectTableViewCell.xib b/iphone/Maps/Classes/Editor/MWMEditorSelectTableViewCell.xib index a7e65e4187..4c9eb3e508 100644 --- a/iphone/Maps/Classes/Editor/MWMEditorSelectTableViewCell.xib +++ b/iphone/Maps/Classes/Editor/MWMEditorSelectTableViewCell.xib @@ -1,5 +1,5 @@ - + @@ -22,9 +22,9 @@ diff --git a/iphone/Maps/Classes/Editor/MWMEditorViewController.mm b/iphone/Maps/Classes/Editor/MWMEditorViewController.mm index 9b757dc7ac..35dbbfde6a 100644 --- a/iphone/Maps/Classes/Editor/MWMEditorViewController.mm +++ b/iphone/Maps/Classes/Editor/MWMEditorViewController.mm @@ -510,20 +510,21 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) #pragma mark - MWMCuisineEditorProtocol -- (NSSet *)getCuisines +@synthesize cuisines = _cuisines; +- (NSSet *)cuisines { + if (_cuisines) + return _cuisines; return self.entity.cuisines; } - (void)setCuisines:(NSSet *)cuisines { - if ([[self getCuisines] isEqualToSet:cuisines]) + if ([self.cuisines isEqualToSet:cuisines]) return; + _cuisines = cuisines; self.needsReload = YES; - self.entity.cuisines = cuisines; - // To get updated value we use [self.entity getCellValue:] not [self getCellValue:] - NSString * updatedValue = [self.entity getCellValue:MWMPlacePageCellTypeCuisine]; - [self setCell:MWMPlacePageCellTypeCuisine value:updatedValue]; + [self setCell:MWMPlacePageCellTypeCuisine value:[MWMPlacePageEntity makeMWMCuisineString:cuisines]]; } #pragma mark - MWMStreetEditorProtocol diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.h b/iphone/Maps/Classes/MWMPlacePageEntity.h index 38e0c26e01..4eb949f883 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.h +++ b/iphone/Maps/Classes/MWMPlacePageEntity.h @@ -45,6 +45,8 @@ using MWMPlacePageCellTypeValueMap = map; @interface MWMPlacePageEntity : NSObject ++ (NSString *)makeMWMCuisineString:(NSSet *)cuisines; + @property (copy, nonatomic) NSString * title; @property (copy, nonatomic) NSString * category; @property (copy, nonatomic) NSString * bookmarkTitle; diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index 4b7b5ef579..df231d669d 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -13,6 +13,7 @@ namespace { NSString * const kOSMCuisineSeparator = @";"; +NSString * const kMWMCuisineSeparator = @", "; array const gMetaFieldsMap{ {MWMPlacePageCellTypePostcode, MWMPlacePageCellTypePhoneNumber, MWMPlacePageCellTypeWebsite, @@ -48,6 +49,11 @@ void initFieldsMap() ASSERT_EQUAL(kMetaFieldsMap[MWMPlacePageCellTypeSpacer], 0, ()); ASSERT_EQUAL(kMetaFieldsMap[Metadata::FMD_MAXSPEED], 0, ()); } + +NSString * mwmToOSMCuisineString(NSString * mwmCuisine) +{ + return [mwmCuisine stringByReplacingOccurrencesOfString:kMWMCuisineSeparator withString:kOSMCuisineSeparator]; +} } // namespace @interface MWMPlacePageEntity () @@ -63,6 +69,24 @@ void initFieldsMap() MWMPlacePageCellTypeValueMap m_values; } ++ (NSString *)makeMWMCuisineString:(NSSet *)cuisines +{ + NSString * prefix = @"cuisine_"; + NSMutableArray * localizedCuisines = [NSMutableArray arrayWithCapacity:cuisines.count]; + for (NSString * cus in cuisines) + { + NSString * cuisine = [prefix stringByAppendingString:cus]; + NSString * localizedCuisine = L(cuisine); + BOOL const noLocalization = [localizedCuisine isEqualToString:cuisine]; + [localizedCuisines addObject:noLocalization ? cus : localizedCuisine]; + } + [localizedCuisines sortUsingComparator:^NSComparisonResult(NSString * s1, NSString * s2) + { + return [s1 compare:s2 options:NSCaseInsensitiveSearch range:{0, s1.length} locale:[NSLocale currentLocale]]; + }]; + return [localizedCuisines componentsJoinedByString:kMWMCuisineSeparator]; +} + - (instancetype)initWithDelegate:(id)delegate { NSAssert(delegate, @"delegate can not be nil."); @@ -123,21 +147,28 @@ void initFieldsMap() m_fields.emplace_back(field); } -- (void)removeMetaField:(MWMPlacePageCellType)field +- (void)removeMetaField:(NSUInteger)value { - auto const it = find(m_fields.begin(), m_fields.end(), field); + NSAssert(value >= Metadata::FMD_COUNT, @"Incorrect enum value"); + auto const it = find(m_fields.begin(), m_fields.end(), value); if (it != m_fields.end()) m_fields.erase(it); } -- (void)addMetaField:(NSUInteger)key value:(string const &)value +- (void)setMetaField:(NSUInteger)key value:(string const &)value { - if (value.empty()) - return; - [self addMetaField:key]; NSAssert(key >= Metadata::FMD_COUNT, @"Incorrect enum value"); MWMPlacePageCellType const cellType = static_cast(key); - m_values[cellType] = value; + if (value.empty()) + { + [self removeMetaField:key]; + m_values.erase(cellType); + } + else + { + [self addMetaField:key]; + m_values[cellType] = value; + } } - (void)configureForBookmark:(UserMark const *)bookmark @@ -186,7 +217,7 @@ void initFieldsMap() self.category = @(info.GetPinType().c_str()); if (!info.m_house.empty()) - [self addMetaField:MWMPlacePageCellTypeBuilding value:info.m_house]; + [self setMetaField:MWMPlacePageCellTypeBuilding value:info.m_house]; for (auto const type : metadata.GetPresentTypes()) { @@ -231,10 +262,10 @@ void initFieldsMap() case Metadata::FMD_OPEN_HOURS: case Metadata::FMD_EMAIL: case Metadata::FMD_POSTCODE: - [self addMetaField:kMetaFieldsMap[type] value:metadata.Get(type)]; + [self setMetaField:kMetaFieldsMap[type] value:metadata.Get(type)]; break; case Metadata::FMD_INTERNET: - [self addMetaField:kMetaFieldsMap[type] value:L(@"WiFi_available").UTF8String]; + [self setMetaField:kMetaFieldsMap[type] value:L(@"WiFi_available").UTF8String]; break; default: break; @@ -275,11 +306,6 @@ void initFieldsMap() self.cuisines = [NSSet setWithArray:[cuisine componentsSeparatedByString:kOSMCuisineSeparator]]; } -- (NSString *)serializeCuisine -{ - return [self.cuisines.allObjects componentsJoinedByString:kOSMCuisineSeparator]; -} - - (void)processStreets { FeatureType const * feature = self.delegate.userMark->GetFeature(); @@ -294,7 +320,7 @@ void initFieldsMap() self.nearbyStreets = arr; auto const info = frm.GetFeatureAddressInfo(*feature); - [self addMetaField:MWMPlacePageCellTypeStreet value:info.m_street]; + [self setMetaField:MWMPlacePageCellTypeStreet value:info.m_street]; } #pragma mark - Editing @@ -359,8 +385,8 @@ void initFieldsMap() { Metadata::EType const fmdType = static_cast(kMetaFieldsMap[cell.first]); NSAssert(fmdType > 0 && fmdType < Metadata::FMD_COUNT, @"Incorrect enum value"); - NSString * cuisineStr = [self serializeCuisine]; - metadata.Set(fmdType, cuisineStr.UTF8String); + NSString * osmCuisineStr = mwmToOSMCuisineString(@(cell.second.c_str())); + metadata.Set(fmdType, osmCuisineStr.UTF8String); break; } case MWMPlacePageCellTypeName: @@ -444,16 +470,8 @@ void initFieldsMap() if ([_cuisines isEqualToSet:cuisines]) return; _cuisines = cuisines; - NSMutableArray * localizedCuisines = [NSMutableArray arrayWithCapacity:self.cuisines.count]; - for (NSString * cus in self.cuisines) - { - NSString * cuisine = [NSString stringWithFormat:@"cuisine_%@", cus]; - NSString * localizedCuisine = L(cuisine); - BOOL const noLocalization = [localizedCuisine isEqualToString:cuisine]; - [localizedCuisines addObject:noLocalization ? cus : localizedCuisine]; - } - [self addMetaField:MWMPlacePageCellTypeCuisine - value:[localizedCuisines componentsJoinedByString:@", "].UTF8String]; + [self setMetaField:MWMPlacePageCellTypeCuisine + value:[MWMPlacePageEntity makeMWMCuisineString:cuisines].UTF8String]; } #pragma mark - Bookmark editing