[ios] Added search in cuisine editor.

This commit is contained in:
VladiMihaylenko 2016-02-09 15:07:00 +03:00 committed by Sergey Yershov
parent 004d20ca90
commit 4390c5a893
4 changed files with 111 additions and 45 deletions

View file

@ -1,4 +1,4 @@
#import "ViewController.h"
#import "TableViewController.h"
@protocol MWMCuisineEditorProtocol <NSObject>
@ -6,7 +6,7 @@
@end
@interface MWMCuisineEditorViewController : ViewController
@interface MWMCuisineEditorViewController : TableViewController
@property (weak, nonatomic) id<MWMCuisineEditorProtocol> delegate;

View file

@ -7,32 +7,82 @@ namespace
NSString * const kCuisineEditorCell = @"MWMCuisineEditorTableViewCell";
} // namespace
@interface MWMCuisineEditorViewController ()<UITableViewDelegate, UITableViewDataSource,
MWMCuisineEditorTableViewCellProtocol>
@interface MWMCuisineEditorViewController ()<MWMCuisineEditorTableViewCellProtocol, UISearchBarDelegate>
@property (weak, nonatomic) IBOutlet UITableView * tableView;
@property (nonatomic) NSArray<NSString *> * cuisineKeys;
@property (copy, nonatomic) NSArray<NSString *> * cuisineKeys;
@property (copy, nonatomic) NSArray<NSString *> * filtredKeys;
@property (nonatomic) NSMutableSet<NSString *> * selectedCuisines;
@property (weak, nonatomic) IBOutlet UISearchBar * searchBar;
@end
@implementation MWMCuisineEditorViewController
- (void)awakeFromNib
{
self.tableView.separatorColor = [UIColor blackDividers];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self configNavBar];
[self configSearchBar];
[self configData];
[self configTable];
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
self.filtredKeys = [_cuisineKeys filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString * value, NSDictionary<NSString *,id> *)
{
if (!searchText.length)
return YES;
NSString * cuisine = [NSString stringWithFormat:@"cuisine_%@", value];
return [[L(cuisine) capitalizedStringWithLocale:[NSLocale currentLocale]] containsString:searchText];
}]];
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
[self searchBar:searchBar setActiveState:YES];
return YES;
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
if (searchBar.text.length == 0)
{
[self searchBar:searchBar setActiveState:NO];
self.filtredKeys = nil;
}
return YES;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
searchBar.text = @"";
[self searchBar:searchBar setActiveState:NO];
self.filtredKeys = nil;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
- (void)searchBar:(UISearchBar *)searchBar setActiveState:(BOOL)isActiveState
{
[searchBar setShowsCancelButton:isActiveState animated:YES];
[self.navigationController setNavigationBarHidden:isActiveState animated:YES];
}
#pragma mark - Configuration
- (void)configNavBar
@ -49,6 +99,15 @@ namespace
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
}
- (void)configSearchBar
{
self.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor primary]];
self.searchBar.placeholder = L(@"search_in_cuisine");
UITextField * textFiled = [self.searchBar valueForKey:@"searchField"];
UILabel * placeholder = [textFiled valueForKey:@"_placeholderLabel"];
placeholder.textColor = [UIColor blackHintText];
}
- (void)configData
{
NSString * stringsPath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"];
@ -76,6 +135,19 @@ namespace
forCellReuseIdentifier:kCuisineEditorCell];
}
#pragma mark - Accessors
- (NSArray<NSString *> *)cuisineKeys
{
return self.filtredKeys != nil ? self.filtredKeys : _cuisineKeys;
}
- (void)setFiltredKeys:(NSArray<NSString *> *)filtredKeys
{
_filtredKeys = filtredKeys;
[self.tableView reloadData];
}
#pragma mark - Actions
- (void)onCancel

View file

@ -663,6 +663,12 @@ using namespace osm_auth_ios;
UITextField * textField = [UITextField appearance];
textField.keyboardAppearance = [UIColor isNightMode] ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault;
UISearchBar * searchBar = [UISearchBar appearance];
searchBar.barTintColor = [UIColor primary];
UITextField * textFieldInSearchBar = [UITextField appearanceWhenContainedIn:[UISearchBar class], nil];
textField.backgroundColor = [UIColor white];
textFieldInSearchBar.defaultTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackPrimaryText]};
}
@ -789,7 +795,6 @@ using namespace osm_auth_ios;
return;
[ud setBool:YES forKey:kUserDafaultsNeedToEnableTTS];
[ud synchronize];
}
#pragma mark - Standby

View file

@ -748,8 +748,8 @@
<navigationItem key="navigationItem" id="n8f-MH-xDc"/>
<connections>
<segue destination="Ld6-gM-2hk" kind="custom" identifier="Editor2OpeningHoursEditorSegue" customClass="MWMSegue" id="EMH-RE-PDh"/>
<segue destination="IAA-1a-ZuZ" kind="custom" identifier="Editor2CuisineEditorSegue" customClass="MWMSegue" id="WK7-zs-Cgl"/>
<segue destination="Heu-QR-M0N" kind="custom" identifier="Editor2StreetEditorSegue" customClass="MWMSegue" id="iJS-b1-GuT"/>
<segue destination="xZs-iI-22O" kind="custom" identifier="Editor2CuisineEditorSegue" customClass="MWMSegue" id="qEA-7d-gOo"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FGq-OI-eQl" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -757,44 +757,33 @@
<point key="canvasLocation" x="330" y="2753"/>
</scene>
<!--Cuisine Editor View Controller-->
<scene sceneID="dIV-0o-2RN">
<scene sceneID="vQV-Ee-44C">
<objects>
<viewController id="IAA-1a-ZuZ" customClass="MWMCuisineEditorViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="z1V-lE-err"/>
<viewControllerLayoutGuide type="bottom" id="9dL-CH-whb"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="t1d-A1-7Yr">
<tableViewController id="xZs-iI-22O" customClass="MWMCuisineEditorViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="onDrag" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="SYG-xq-jrS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="p0S-WX-gWg">
<rect key="frame" x="0.0" y="20" width="600" height="580"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<connections>
<outlet property="dataSource" destination="IAA-1a-ZuZ" id="Ndb-O3-616"/>
<outlet property="delegate" destination="IAA-1a-ZuZ" id="7yW-1N-N0s"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="p0S-WX-gWg" firstAttribute="leading" secondItem="t1d-A1-7Yr" secondAttribute="leading" id="9Wu-GM-itJ"/>
<constraint firstItem="p0S-WX-gWg" firstAttribute="top" secondItem="z1V-lE-err" secondAttribute="bottom" id="LA4-lP-hYg"/>
<constraint firstAttribute="trailing" secondItem="p0S-WX-gWg" secondAttribute="trailing" id="OYS-XC-4Uv"/>
<constraint firstItem="9dL-CH-whb" firstAttribute="top" secondItem="p0S-WX-gWg" secondAttribute="bottom" id="qK5-X4-7oc"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="pressBackground"/>
</userDefinedRuntimeAttributes>
</view>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<searchBar key="tableHeaderView" contentMode="redraw" id="pHC-Wt-cjL">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="xZs-iI-22O" id="Evb-70-unW"/>
</connections>
</searchBar>
<connections>
<outlet property="dataSource" destination="xZs-iI-22O" id="wxj-Ad-vkh"/>
<outlet property="delegate" destination="xZs-iI-22O" id="cU3-6B-crV"/>
</connections>
</tableView>
<connections>
<outlet property="tableView" destination="p0S-WX-gWg" id="bSM-kw-QBG"/>
<outlet property="searchBar" destination="pHC-Wt-cjL" id="rfQ-RO-JbZ"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="O74-1p-da7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="w9h-sx-JP3" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="352" y="3513"/>
<point key="canvasLocation" x="322" y="3513"/>
</scene>
<!--Opening Hours Editor View Controller-->
<scene sceneID="UAI-uc-U5w">