[ios] Fixed cuisine editing.

This commit is contained in:
VladiMihaylenko 2016-03-14 17:22:16 +03:00 committed by Sergey Yershov
parent 28e0bcb00b
commit 08a56e420d
6 changed files with 19 additions and 157 deletions

View file

@ -1,16 +0,0 @@
#include "std/string.hpp"
@protocol MWMCuisineEditorTableViewCellProtocol <NSObject>
- (void)change:(string const &)key selected:(BOOL)selected;
@end
@interface MWMCuisineEditorTableViewCell : UITableViewCell
- (void)configWithDelegate:(id<MWMCuisineEditorTableViewCellProtocol>)delegate
key:(string const &)key
translation:(string const &)translation
selected:(BOOL)selected;
@end

View file

@ -1,37 +0,0 @@
#import "MWMCuisineEditorTableViewCell.h"
@interface MWMCuisineEditorTableViewCell ()
{
string m_key;
}
@property (weak, nonatomic) IBOutlet UILabel * label;
@property (weak, nonatomic) IBOutlet UIImageView * selectedIcon;
@property (weak, nonatomic) id<MWMCuisineEditorTableViewCellProtocol> delegate;
@end
@implementation MWMCuisineEditorTableViewCell
- (void)configWithDelegate:(id<MWMCuisineEditorTableViewCellProtocol>)delegate
key:(string const &)key
translation:(string const &)translation
selected:(BOOL)selected
{
self.delegate = delegate;
m_key = key;
self.label.text = @(translation.c_str());
self.selectedIcon.hidden = !selected;
}
#pragma mark - Actions
- (IBAction)selectAction
{
BOOL const selected = self.selectedIcon.hidden;
self.selectedIcon.hidden = !selected;
[self.delegate change:m_key selected:selected];
}
@end

View file

@ -1,72 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="MWMCuisineEditorTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="264" translatesAutoresizingMaskIntoConstraints="NO" id="hOY-VB-nFg">
<rect key="frame" x="16" y="12" width="264" height="19"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular17"/>
<userDefinedRuntimeAttribute type="string" keyPath="colorName" value="blackPrimaryText"/>
</userDefinedRuntimeAttributes>
</label>
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_checkmark" translatesAutoresizingMaskIntoConstraints="NO" id="mIn-6M-GtU">
<rect key="frame" x="284" y="8" width="28" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="Q8k-5y-yNe"/>
<constraint firstAttribute="width" constant="28" id="YR5-CD-Ydv"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="coloring" value="MWMBlue"/>
</userDefinedRuntimeAttributes>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3Pe-AU-T9A">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<connections>
<action selector="selectAction" destination="KGk-i7-Jjw" eventType="touchUpInside" id="LsC-MR-8cu"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="3Pe-AU-T9A" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="0AO-q7-CzE"/>
<constraint firstAttribute="trailing" secondItem="hOY-VB-nFg" secondAttribute="trailing" constant="40" id="2gu-wq-Y7B"/>
<constraint firstItem="mIn-6M-GtU" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="5ie-0h-fd1"/>
<constraint firstAttribute="bottom" secondItem="hOY-VB-nFg" secondAttribute="bottom" constant="12" id="8e2-Vf-KRD"/>
<constraint firstAttribute="bottom" secondItem="3Pe-AU-T9A" secondAttribute="bottom" id="SBx-de-g1Q"/>
<constraint firstItem="3Pe-AU-T9A" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="dMo-wQ-AZ7"/>
<constraint firstItem="hOY-VB-nFg" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="fqp-n8-snv"/>
<constraint firstItem="hOY-VB-nFg" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="12" id="jFG-ai-aHe"/>
<constraint firstAttribute="trailing" secondItem="3Pe-AU-T9A" secondAttribute="trailing" id="yAc-8o-uEl"/>
<constraint firstAttribute="trailing" secondItem="mIn-6M-GtU" secondAttribute="trailing" constant="8" id="ygv-Mk-Ord"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="white"/>
</userDefinedRuntimeAttributes>
</tableViewCellContentView>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="white"/>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="label" destination="hOY-VB-nFg" id="9sU-pI-3IC"/>
<outlet property="selectedIcon" destination="mIn-6M-GtU" id="yUn-EQ-5l2"/>
</connections>
</tableViewCell>
</objects>
<resources>
<image name="ic_checkmark" width="28" height="28"/>
</resources>
</document>

View file

@ -1,4 +1,3 @@
#import "MWMCuisineEditorTableViewCell.h"
#import "MWMCuisineEditorViewController.h"
#import "UIColor+MapsMeColor.h"
@ -20,7 +19,7 @@ vector<string> SliceKeys(vector<pair<string, string>> const & v)
}
} // namespace
@interface MWMCuisineEditorViewController ()<MWMCuisineEditorTableViewCellProtocol, UISearchBarDelegate>
@interface MWMCuisineEditorViewController () <UISearchBarDelegate>
{
osm::TAllCuisines m_allCuisines;
vector<string> m_selectedCuisines;
@ -39,7 +38,6 @@ vector<string> SliceKeys(vector<pair<string, string>> const & v)
[self configNavBar];
[self configSearchBar];
[self configData];
[self configTable];
}
#pragma mark - UISearchBarDelegate
@ -131,12 +129,6 @@ vector<string> SliceKeys(vector<pair<string, string>> const & v)
m_selectedCuisines = [self.delegate getSelectedCuisines];
}
- (void)configTable
{
[self.tableView registerNib:[UINib nibWithNibName:kCuisineEditorCell bundle:nil]
forCellReuseIdentifier:kCuisineEditorCell];
}
#pragma mark - Actions
- (void)onCancel
@ -154,17 +146,24 @@ vector<string> SliceKeys(vector<pair<string, string>> const & v)
- (void)change:(string const &)key selected:(BOOL)selected
{
string const translated {osm::Cuisines::Instance().Translate(key)};
if (selected)
m_selectedCuisines.push_back(key);
m_selectedCuisines.push_back(translated);
else
m_selectedCuisines.erase(find(m_selectedCuisines.begin(), m_selectedCuisines.end(), key));
m_selectedCuisines.erase(find(m_selectedCuisines.begin(), m_selectedCuisines.end(), translated));
}
#pragma mark - UITableViewDataSource
- (UITableViewCell * _Nonnull)tableView:(UITableView * _Nonnull)tableView cellForRowAtIndexPath:(NSIndexPath * _Nonnull)indexPath
{
return [tableView dequeueReusableCellWithIdentifier:kCuisineEditorCell];
UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:[UITableViewCell className]];
NSInteger const index = indexPath.row;
string const translated {osm::Cuisines::Instance().Translate(m_displayedKeys[index])};
BOOL const selected = find(m_selectedCuisines.begin(), m_selectedCuisines.end(), translated) != m_selectedCuisines.end();
cell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
cell.textLabel.text = @(translated.c_str());
return cell;
}
- (NSInteger)tableView:(UITableView * _Nonnull)tableView numberOfRowsInSection:(NSInteger)section
@ -174,12 +173,13 @@ vector<string> SliceKeys(vector<pair<string, string>> const & v)
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView * _Nonnull)tableView willDisplayCell:(MWMCuisineEditorTableViewCell * _Nonnull)cell forRowAtIndexPath:(NSIndexPath * _Nonnull)indexPath
- (void)tableView:(UITableView * _Nonnull)tableView didSelectRowAtIndexPath:(NSIndexPath * _Nonnull)indexPath
{
NSInteger const index = indexPath.row;
string const & key = m_displayedKeys[index];
BOOL const selected = find(m_selectedCuisines.begin(), m_selectedCuisines.end(), key) != m_selectedCuisines.end();
[cell configWithDelegate:self key:key translation:osm::Cuisines::Instance().Translate(key) selected:selected];
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:NO animated:YES];
BOOL const isAlreadySelected = cell.accessoryType == UITableViewCellAccessoryCheckmark;
cell.accessoryType = isAlreadySelected ? UITableViewCellAccessoryNone : UITableViewCellAccessoryCheckmark;
[self change:m_displayedKeys[indexPath.row] selected:!isAlreadySelected];
}
@end

View file

@ -34,10 +34,6 @@
340837161B72451A00B5C185 /* MWMShareLocationActivityItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340837151B72451A00B5C185 /* MWMShareLocationActivityItem.mm */; };
340C20E31C3E565600111D22 /* MWMCuisineEditorViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340C20E21C3E565600111D22 /* MWMCuisineEditorViewController.mm */; };
340C20E41C3E565600111D22 /* MWMCuisineEditorViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340C20E21C3E565600111D22 /* MWMCuisineEditorViewController.mm */; };
340C21111C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340C210F1C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm */; };
340C21121C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340C210F1C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm */; };
340C21131C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 340C21101C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib */; };
340C21141C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 340C21101C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib */; };
340E10601B944DAB00D975D5 /* MWMSearchHistoryManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340E105F1B944DAB00D975D5 /* MWMSearchHistoryManager.mm */; };
340E10631B949D1900D975D5 /* MWMSearchBookmarksManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340E10621B949D1900D975D5 /* MWMSearchBookmarksManager.mm */; };
340F24631B14910500F874CD /* RouteState.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340F24621B14910500F874CD /* RouteState.mm */; };
@ -861,9 +857,6 @@
340C20E11C3E565600111D22 /* MWMCuisineEditorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCuisineEditorViewController.h; sourceTree = "<group>"; };
340C20E21C3E565600111D22 /* MWMCuisineEditorViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCuisineEditorViewController.mm; sourceTree = "<group>"; };
340C20E51C3E58B000111D22 /* MWMEditorCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMEditorCommon.h; sourceTree = "<group>"; };
340C210E1C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCuisineEditorTableViewCell.h; sourceTree = "<group>"; };
340C210F1C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCuisineEditorTableViewCell.mm; sourceTree = "<group>"; };
340C21101C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMCuisineEditorTableViewCell.xib; sourceTree = "<group>"; };
340DC82B1C4E72C700EAA2CC /* liboauthcpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liboauthcpp.a; path = "../../../omim-xcode-build/Debug/liboauthcpp.a"; sourceTree = "<group>"; };
340E105E1B944DAB00D975D5 /* MWMSearchHistoryManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSearchHistoryManager.h; sourceTree = "<group>"; };
340E105F1B944DAB00D975D5 /* MWMSearchHistoryManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMSearchHistoryManager.mm; sourceTree = "<group>"; };
@ -1857,9 +1850,6 @@
children = (
340C20E11C3E565600111D22 /* MWMCuisineEditorViewController.h */,
340C20E21C3E565600111D22 /* MWMCuisineEditorViewController.mm */,
340C210E1C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.h */,
340C210F1C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm */,
340C21101C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib */,
);
path = Cuisine;
sourceTree = "<group>";
@ -3296,7 +3286,6 @@
3401CD7F1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.xib in Resources */,
9DA46A121C47E95700EF52BA /* drules_proto_legacy.bin in Resources */,
4A23D15B1B8B4DD700D4EB6F /* drules_proto_clear.bin in Resources */,
340C21131C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib in Resources */,
341C2A5B1B720B8A00AD41A1 /* MWMAPIBarView.xib in Resources */,
34B82AC51B84608600180497 /* MWMSearchHistoryClearCell.xib in Resources */,
F653CE181C71F62400A453F1 /* MWMAddPlaceNavigationBar.xib in Resources */,
@ -3435,7 +3424,6 @@
6741A9841BF340DE002C974C /* MWMSearchShowOnMapCell.xib in Resources */,
6741A9851BF340DE002C974C /* MWMBottomMenuCollectionViewPortraitCell.xib in Resources */,
9DA46A131C47E95700EF52BA /* drules_proto_legacy.bin in Resources */,
340C21141C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.xib in Resources */,
6741A9871BF340DE002C974C /* drules_proto_clear.bin in Resources */,
6741A9881BF340DE002C974C /* MWMAPIBarView.xib in Resources */,
671182E41C7F0DD800CB8177 /* WorldCoasts_obsolete.mwm in Resources */,
@ -3582,7 +3570,6 @@
FAFCB63613366E78001A5C59 /* WebViewController.mm in Sources */,
34C9BD091C6DBCDA000DC38D /* MWMNavigationController.mm in Sources */,
3406FA151C6E0C3300E9FAD2 /* MWMMapDownloadDialog.mm in Sources */,
340C21111C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm in Sources */,
34C9BD021C6DB693000DC38D /* MWMTableViewController.mm in Sources */,
34CD81D71C92D96F007D2A60 /* MWMFirstLaunchController.mm in Sources */,
F63BA3711BCD5B520044C504 /* MWMTTSLanguageViewController.mm in Sources */,
@ -3798,7 +3785,6 @@
6741A9D51BF340DE002C974C /* WebViewController.mm in Sources */,
34C9BD031C6DB693000DC38D /* MWMTableViewController.mm in Sources */,
6741A9D61BF340DE002C974C /* MWMPlacePageNavigationBar.mm in Sources */,
340C21121C3FFE3100111D22 /* MWMCuisineEditorTableViewCell.mm in Sources */,
6741A9D71BF340DE002C974C /* MWMRouteHelperPanelsDrawer.mm in Sources */,
34CD81D81C92D96F007D2A60 /* MWMFirstLaunchController.mm in Sources */,
F64DA8031C52520000330E9E /* UISwitch+RuntimeAttributes.m in Sources */,

View file

@ -1246,7 +1246,7 @@
<scene sceneID="vQV-Ee-44C">
<objects>
<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">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="onDrag" dataMode="prototypes" style="grouped" separatorStyle="default" showsSelectionImmediatelyOnTouchBegin="NO" 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"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
@ -2828,5 +2828,6 @@ the world. Join us!</string>
<segue reference="w48-2Y-VXA"/>
<segue reference="Z0Z-aU-Vrq"/>
<segue reference="Pet-Wq-d4a"/>
<segue reference="fuS-6s-TH4"/>
</inferredMetricsTieBreakers>
</document>