[ios] Review fixes.

This commit is contained in:
Ilya Grechuhin 2016-01-08 19:12:06 +03:00 committed by Sergey Yershov
parent 6bbc5b015e
commit 7ccb384d1a
5 changed files with 34 additions and 32 deletions

View file

@ -17,6 +17,8 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
MWMFieldCorrectAll = MWMFieldCorrectLogin | MWMFieldCorrectPassword
};
using namespace osm;
@interface MWMAuthorizationOSMLoginViewController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField * loginTextField;
@ -99,7 +101,7 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
return YES;
}
- (void)storeCredentials:(osm::TKeySecret)keySecret
- (void)storeCredentials:(TKeySecret)keySecret
{
NSString * requestToken = @(keySecret.first.c_str());
NSString * requestSecret = @(keySecret.second.c_str());
@ -169,12 +171,12 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
string const username = self.loginTextField.text.UTF8String;
string const password = self.passwordTextField.text.UTF8String;
// TODO(AlexZ): Change to production.
osm::OsmOAuth auth = osm::OsmOAuth::DevServerAuth();
osm::OsmOAuth::AuthResult const result = auth.AuthorizePassword(username, password);
OsmOAuth auth = osm::OsmOAuth::DevServerAuth();
OsmOAuth::AuthResult const result = auth.AuthorizePassword(username, password);
dispatch_async(dispatch_get_main_queue(), ^
{
[self stopSpinner];
if (result == osm::OsmOAuth::AuthResult::OK)
if (result == OsmOAuth::AuthResult::OK)
[self storeCredentials:auth.GetToken()];
else
[self showAlert:L(@"invalid_username_or_password")];

View file

@ -30,7 +30,6 @@ using WeekDayView = MWMPlacePageOpeningHoursDayView *;
@property (weak, nonatomic) id<MWMPlacePageOpeningHoursCellProtocol> delegate;
@property (nonatomic) BOOL isClosed;
@property (nonatomic, readonly) BOOL isExpanded;
@property (nonatomic) BOOL haveExpandSchedule;
@end
@ -90,9 +89,9 @@ WeekDayView getWeekDayView()
cd.isCompatibility = YES;
[cd setCompatibilityText:info isPlaceholder:delegate.isPlaceholder];
}
BOOL const isExpanded = self.isExpanded;
self.middleSeparator.hidden = !isExpanded;
self.weekDaysView.hidden = !isExpanded;
BOOL const isHidden = !self.isExpanded;
self.middleSeparator.hidden = isHidden;
self.weekDaysView.hidden = isHidden;
[cd invalidate];
}

View file

@ -19,22 +19,24 @@ typedef NS_ENUM(NSUInteger, MWMEditorSection)
MWMEditorSectionDetails
};
vector<MWMPlacePageCellType> const kSectionNameCellTypes{MWMPlacePageCellTypeName};
vector<MWMPlacePageCellType> const gSectionNameCellTypes{MWMPlacePageCellTypeName};
vector<MWMPlacePageCellType> const kSectionAddressCellTypes{
vector<MWMPlacePageCellType> const gSectionAddressCellTypes{
{MWMPlacePageCellTypeStreet, MWMPlacePageCellTypeBuilding, MWMPlacePageCellTypeSpacer}};
vector<MWMPlacePageCellType> const kSectionDetailsCellTypes{
vector<MWMPlacePageCellType> const gSectionDetailsCellTypes{
{MWMPlacePageCellTypeOpenHours, MWMPlacePageCellTypePhoneNumber, MWMPlacePageCellTypeWebsite,
MWMPlacePageCellTypeEmail, MWMPlacePageCellTypeCuisine, MWMPlacePageCellTypeWiFi,
MWMPlacePageCellTypeSpacer}};
map<vector<MWMPlacePageCellType>, MWMEditorSection> const kCellTypesSectionMap{
{kSectionNameCellTypes, MWMEditorSectionName},
{kSectionAddressCellTypes, MWMEditorSectionAddress},
{kSectionDetailsCellTypes, MWMEditorSectionDetails}};
using CellTypesSectionMap = pair<vector<MWMPlacePageCellType>, MWMEditorSection>;
MWMPlacePageCellTypeValueMap const kCellType2ReuseIdentifier{
vector<CellTypesSectionMap> const gCellTypesSectionMap{
{gSectionNameCellTypes, MWMEditorSectionName},
{gSectionAddressCellTypes, MWMEditorSectionAddress},
{gSectionDetailsCellTypes, MWMEditorSectionDetails}};
MWMPlacePageCellTypeValueMap const gCellType2ReuseIdentifier{
{MWMPlacePageCellTypeName, "MWMEditorNameTableViewCell"},
{MWMPlacePageCellTypeStreet, "MWMEditorSelectTableViewCell"},
{MWMPlacePageCellTypeBuilding, "MWMEditorTextTableViewCell"},
@ -48,8 +50,8 @@ MWMPlacePageCellTypeValueMap const kCellType2ReuseIdentifier{
NSString * reuseIdentifier(MWMPlacePageCellType cellType)
{
auto const it = kCellType2ReuseIdentifier.find(cellType);
BOOL const haveCell = (it != kCellType2ReuseIdentifier.end());
auto const it = gCellType2ReuseIdentifier.find(cellType);
BOOL const haveCell = (it != gCellType2ReuseIdentifier.end());
ASSERT(haveCell, ());
return haveCell ? @(it->second.c_str()) : @"";
}
@ -161,7 +163,7 @@ static NSString * const kCuisineEditorSegue = @"Editor2CuisineEditorSegue";
m_sections.clear();
m_cells.clear();
m_edited_cells.clear();
for (auto cellsSection : kCellTypesSectionMap)
for (auto cellsSection : gCellTypesSectionMap)
{
for (auto cellType : cellsSection.first)
{
@ -439,7 +441,7 @@ static NSString * const kCuisineEditorSegue = @"Editor2CuisineEditorSegue";
break;
}
case MWMPlacePageCellTypeStreet:
// [self performSegueWithIdentifier:@"Editor2StreetEditorSegue" sender:nil];
// TODO
break;
case MWMPlacePageCellTypeCuisine:
[self performSegueWithIdentifier:kCuisineEditorSegue sender:nil];
@ -471,6 +473,7 @@ static NSString * const kCuisineEditorSegue = @"Editor2CuisineEditorSegue";
{
if ([[self getCuisines] isEqualToSet:cuisines])
return;
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];

View file

@ -20,7 +20,7 @@ CGFloat const kDirectionArrowSide = 26.;
CGFloat const kOffsetFromTitleToDistance = 12.;
CGFloat const kOffsetFromDistanceToArrow = 8.;
MWMPlacePageCellTypeValueMap const kCellType2ReuseIdentifier{
MWMPlacePageCellTypeValueMap const gCellType2ReuseIdentifier{
{MWMPlacePageCellTypeWiFi, "PlacePageInfoCell"},
{MWMPlacePageCellTypeCoordinate, "PlacePageInfoCell"},
{MWMPlacePageCellTypePostcode, "PlacePageInfoCell"},
@ -34,8 +34,8 @@ MWMPlacePageCellTypeValueMap const kCellType2ReuseIdentifier{
NSString * reuseIdentifier(MWMPlacePageCellType cellType)
{
auto const it = kCellType2ReuseIdentifier.find(cellType);
BOOL const haveCell = (it != kCellType2ReuseIdentifier.end());
auto const it = gCellType2ReuseIdentifier.find(cellType);
BOOL const haveCell = (it != gCellType2ReuseIdentifier.end());
ASSERT(haveCell, ());
return haveCell ? @(it->second.c_str()) : @"";
}
@ -62,7 +62,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType)
[super awakeFromNib];
self.featureTable.delegate = self;
self.featureTable.dataSource = self;
for (auto const & type : kCellType2ReuseIdentifier)
for (auto const & type : gCellType2ReuseIdentifier)
{
NSString * identifier = @(type.second.c_str());
[self.featureTable registerNib:[UINib nibWithNibName:identifier bundle:nil]

View file

@ -14,7 +14,7 @@ namespace
NSString * const kOSMCuisineSeparator = @";";
array<MWMPlacePageCellType, 10> const kPatternFieldsArray{
array<MWMPlacePageCellType, 10> const gMetaFieldsMap{
{MWMPlacePageCellTypePostcode, MWMPlacePageCellTypePhoneNumber, MWMPlacePageCellTypeWebsite,
MWMPlacePageCellTypeURL, MWMPlacePageCellTypeEmail, MWMPlacePageCellTypeOpenHours,
MWMPlacePageCellTypeWiFi, MWMPlacePageCellTypeCoordinate, MWMPlacePageCellTypeBookmark,
@ -105,8 +105,8 @@ void initFieldsMap()
- (void)sortMetaFields
{
auto const begin = kPatternFieldsArray.begin();
auto const end = kPatternFieldsArray.end();
auto const begin = gMetaFieldsMap.begin();
auto const end = gMetaFieldsMap.end();
sort(m_fields.begin(), m_fields.end(), [&](MWMPlacePageCellType a, MWMPlacePageCellType b)
{
return find(begin, end, a) < find(begin, end, b);
@ -117,7 +117,7 @@ void initFieldsMap()
{
NSAssert(value >= Metadata::FMD_COUNT, @"Incorrect enum value");
MWMPlacePageCellType const field = static_cast<MWMPlacePageCellType>(value);
if (find(kPatternFieldsArray.begin(), kPatternFieldsArray.end(), field) == kPatternFieldsArray.end())
if (find(gMetaFieldsMap.begin(), gMetaFieldsMap.end(), field) == gMetaFieldsMap.end())
return;
if (find(m_fields.begin(), m_fields.end(), field) == m_fields.end())
m_fields.emplace_back(field);
@ -137,7 +137,7 @@ void initFieldsMap()
[self addMetaField:key];
NSAssert(key >= Metadata::FMD_COUNT, @"Incorrect enum value");
MWMPlacePageCellType const cellType = static_cast<MWMPlacePageCellType>(key);
m_values.emplace(cellType, value);
m_values[cellType] = value;
}
- (void)configureForBookmark:(UserMark const *)bookmark
@ -295,7 +295,6 @@ void initFieldsMap()
- (BOOL)isCellEditable:(MWMPlacePageCellType)cellType
{
return YES;
return m_editableFields.count(cellType) == 1;
}
@ -408,8 +407,7 @@ void initFieldsMap()
if ([_cuisines isEqualToSet:cuisines])
return;
_cuisines = cuisines;
NSMutableArray<NSString *> * localizedCuisines =
[NSMutableArray arrayWithCapacity:self.cuisines.count];
NSMutableArray<NSString *> * localizedCuisines = [NSMutableArray arrayWithCapacity:self.cuisines.count];
for (NSString * cus in self.cuisines)
{
NSString * cuisine = [NSString stringWithFormat:@"cuisine_%@", cus];