[ios] Fixed cuisine editor bugs.

This commit is contained in:
Ilya Grechuhin 2016-01-23 17:11:09 +03:00 committed by Sergey Yershov
parent 5e7de3a35f
commit f74288a0d7
6 changed files with 69 additions and 44 deletions

View file

@ -2,8 +2,7 @@
@protocol MWMCuisineEditorProtocol <NSObject>
- (NSSet<NSString *> *)getCuisines;
- (void)setCuisines:(NSSet<NSString *> *)cuisines;
@property (nonatomic) NSSet<NSString *> * cuisines;
@end

View file

@ -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

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
@ -22,9 +22,9 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="220" translatesAutoresizingMaskIntoConstraints="NO" id="MBe-6r-IsA">
<rect key="frame" x="60" y="0.0" width="220" height="44"/>
<rect key="frame" x="60" y="8" width="220" height="28"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" priority="750" constant="44" id="7cv-Wq-vWC"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" priority="750" constant="28" id="7cv-Wq-vWC"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
@ -62,8 +62,8 @@
<constraint firstAttribute="trailing" secondItem="jLw-GA-z3y" secondAttribute="trailing" constant="6" id="3Bg-20-t7E"/>
<constraint firstAttribute="bottom" secondItem="3QW-i5-g6A" secondAttribute="bottom" id="437-dg-x06"/>
<constraint firstAttribute="trailing" secondItem="nq9-KC-Ujh" secondAttribute="trailing" id="5gd-06-ZOC"/>
<constraint firstItem="MBe-6r-IsA" firstAttribute="top" secondItem="V1p-K9-KlE" secondAttribute="top" id="6FB-in-VCz"/>
<constraint firstAttribute="bottom" secondItem="MBe-6r-IsA" secondAttribute="bottom" id="CG0-ar-vx9"/>
<constraint firstItem="MBe-6r-IsA" firstAttribute="top" secondItem="V1p-K9-KlE" secondAttribute="top" constant="8" id="6FB-in-VCz"/>
<constraint firstAttribute="bottom" secondItem="MBe-6r-IsA" secondAttribute="bottom" constant="8" id="CG0-ar-vx9"/>
<constraint firstItem="xur-tJ-HA9" firstAttribute="leading" secondItem="V1p-K9-KlE" secondAttribute="leading" constant="16" id="DlR-yh-2JK"/>
<constraint firstItem="3QW-i5-g6A" firstAttribute="leading" secondItem="V1p-K9-KlE" secondAttribute="leading" priority="250" id="Ghg-3J-hYK"/>
<constraint firstItem="MBe-6r-IsA" firstAttribute="leading" secondItem="V1p-K9-KlE" secondAttribute="leading" constant="60" id="RGA-XL-gLq"/>
@ -87,6 +87,6 @@
</tableViewCell>
</objects>
<resources>
<image name="ic_arrow_gray" width="8" height="14"/>
<image name="ic_arrow_gray" width="28" height="28"/>
</resources>
</document>

View file

@ -510,20 +510,21 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType)
#pragma mark - MWMCuisineEditorProtocol
- (NSSet<NSString *> *)getCuisines
@synthesize cuisines = _cuisines;
- (NSSet<NSString *> *)cuisines
{
if (_cuisines)
return _cuisines;
return self.entity.cuisines;
}
- (void)setCuisines:(NSSet<NSString *> *)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

View file

@ -45,6 +45,8 @@ using MWMPlacePageCellTypeValueMap = map<MWMPlacePageCellType, string>;
@interface MWMPlacePageEntity : NSObject
+ (NSString *)makeMWMCuisineString:(NSSet<NSString *> *)cuisines;
@property (copy, nonatomic) NSString * title;
@property (copy, nonatomic) NSString * category;
@property (copy, nonatomic) NSString * bookmarkTitle;

View file

@ -13,6 +13,7 @@ namespace
{
NSString * const kOSMCuisineSeparator = @";";
NSString * const kMWMCuisineSeparator = @", ";
array<MWMPlacePageCellType, 10> 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<NSString *> *)cuisines
{
NSString * prefix = @"cuisine_";
NSMutableArray<NSString *> * 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<MWMPlacePageEntityProtocol>)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<MWMPlacePageCellType>(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<Metadata::EType>(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<NSString *> * 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