From a6d5a7ffd8c4b886b97e2dcb80a3859a42afc2e8 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Tue, 28 Nov 2017 16:21:55 +0300 Subject: [PATCH] [MAPSME-6071] [ios] Added error state handling for name field in editor. --- .../MWMEditorAdditionalNameTableViewCell.h | 2 + .../MWMEditorAdditionalNameTableViewCell.mm | 56 ++++++++++++++++++- .../MWMEditorAdditionalNameTableViewCell.xib | 48 ++++++++++++---- .../Cells/MWMEditorTextTableViewCell.xib | 25 ++++++--- iphone/Maps/UI/Editor/MWMEditorCommon.h | 2 +- .../Maps/UI/Editor/MWMEditorViewController.mm | 34 ++++++----- 6 files changed, 127 insertions(+), 40 deletions(-) diff --git a/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.h b/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.h index 0c7fae91e5..a7e01dbc0d 100644 --- a/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.h +++ b/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.h @@ -11,6 +11,8 @@ langCode:(NSInteger)langCode langName:(NSString *)langName name:(NSString *)name + errorMessage:(NSString *)errorMessage + isValid:(BOOL)isValid keyboardType:(UIKeyboardType)keyboardType; @end diff --git a/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.mm b/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.mm index 70d459c1e4..fbf0516df7 100644 --- a/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.mm +++ b/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.mm @@ -1,15 +1,23 @@ #import "MWMEditorAdditionalNameTableViewCell.h" +namespace +{ +CGFloat const kErrorLabelHeight = 16; +} // namespace + @interface MWMEditorAdditionalNameTableViewCell () @property(weak, nonatomic) IBOutlet UILabel * languageLabel; -@property(weak, nonatomic) IBOutlet UIButton * languageButton; @property(weak, nonatomic) IBOutlet UITextField * textField; +@property(weak, nonatomic) IBOutlet UILabel * errorLabel; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint * errorLabelHeight; @property(nonatomic, readwrite) NSInteger code; @property(weak, nonatomic) id delegate; +@property(nonatomic) BOOL isValid; + @end @implementation MWMEditorAdditionalNameTableViewCell @@ -18,19 +26,63 @@ langCode:(NSInteger)langCode langName:(NSString *)langName name:(NSString *)name + errorMessage:(NSString *)errorMessage + isValid:(BOOL)isValid keyboardType:(UIKeyboardType)keyboardType { self.delegate = delegate; self.code = langCode; self.languageLabel.text = langName; - [self.languageButton setTitle:langName forState:UIControlStateNormal]; + self.errorLabel.text = errorMessage; + self.isValid = isValid; self.textField.text = name; self.textField.keyboardType = keyboardType; + self.textField.backgroundColor = [UIColor clearColor]; + [self processValidation]; } - (IBAction)changeLanguageTap { [self.delegate editAdditionalNameLanguage:self.code]; } + +- (void)processValidation +{ + if (self.isValid) + { + self.errorLabelHeight.constant = 0; + self.contentView.backgroundColor = [UIColor white]; + } + else + { + self.errorLabelHeight.constant = kErrorLabelHeight; + self.contentView.backgroundColor = [UIColor errorPink]; + } + [self layoutIfNeeded]; +} + +- (void)changeInvalidCellState +{ + if (self.isValid) + return; + self.isValid = YES; + [self processValidation]; + [self.delegate tryToChangeInvalidStateForCell:self]; +} + #pragma mark - UITextFieldDelegate +- (BOOL)textField:(UITextField *)textField + shouldChangeCharactersInRange:(NSRange)range + replacementString:(NSString *)string +{ + [self changeInvalidCellState]; + return YES; +} + +- (BOOL)textFieldShouldClear:(UITextField *)textField +{ + [self changeInvalidCellState]; + return YES; +} + - (void)textFieldDidEndEditing:(UITextField *)textField { [self.delegate cell:self changedText:textField.text]; diff --git a/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.xib b/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.xib index da315f3138..2f823b5301 100644 --- a/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.xib +++ b/iphone/Maps/UI/Editor/Cells/MWMEditorAdditionalNameTableViewCell.xib @@ -1,10 +1,18 @@ - + + + + - + + + + HelveticaNeue + + @@ -12,10 +20,12 @@ - + + + @@ -42,15 +54,32 @@ + + + - + + - - + + @@ -60,15 +89,12 @@ + + - - - - - diff --git a/iphone/Maps/UI/Editor/Cells/MWMEditorTextTableViewCell.xib b/iphone/Maps/UI/Editor/Cells/MWMEditorTextTableViewCell.xib index fef2ebbd30..8fed33a2f7 100644 --- a/iphone/Maps/UI/Editor/Cells/MWMEditorTextTableViewCell.xib +++ b/iphone/Maps/UI/Editor/Cells/MWMEditorTextTableViewCell.xib @@ -1,10 +1,19 @@ - - + + + + + - + + + + + HelveticaNeue + + @@ -12,11 +21,11 @@ - + - + @@ -27,7 +36,7 @@ - + @@ -44,12 +53,12 @@