diff options
author | Ilya Grechuhin <i.grechuhin@gmail.com> | 2016-12-15 16:19:01 +0300 |
---|---|---|
committer | Ilya Grechuhin <i.grechuhin@gmail.com> | 2016-12-15 18:08:43 +0300 |
commit | 3b7a716dc7cfa82b2419b677554f01c796ca99de (patch) | |
tree | 31af23375524c465bb74bbc6f576b63ba72e1889 /iphone/Maps/Settings | |
parent | 98123085dc3677f1d036acf2df0b105ca12751c2 (diff) |
[swift] [ios] Migrated Settings cells to Swift.
Diffstat (limited to 'iphone/Maps/Settings')
18 files changed, 264 insertions, 195 deletions
diff --git a/iphone/Maps/Settings/Cells/LinkCell.h b/iphone/Maps/Settings/Cells/LinkCell.h deleted file mode 100644 index abbfce412d..0000000000 --- a/iphone/Maps/Settings/Cells/LinkCell.h +++ /dev/null @@ -1,8 +0,0 @@ -#import "MWMTableViewCell.h" - -@interface LinkCell : MWMTableViewCell - -@property(nonatomic) IBOutlet UILabel * titleLabel; -@property(nonatomic) IBOutlet UILabel * infoLabel; - -@end diff --git a/iphone/Maps/Settings/Cells/LinkCell.mm b/iphone/Maps/Settings/Cells/LinkCell.mm deleted file mode 100644 index 1ca486d125..0000000000 --- a/iphone/Maps/Settings/Cells/LinkCell.mm +++ /dev/null @@ -1,12 +0,0 @@ -#import "LinkCell.h" -#import "UIColor+MapsMeColor.h" - -@implementation LinkCell - -- (void)awakeFromNib -{ - [super awakeFromNib]; - self.backgroundColor = [UIColor white]; -} - -@end diff --git a/iphone/Maps/Settings/Cells/SelectableCell.h b/iphone/Maps/Settings/Cells/SelectableCell.h deleted file mode 100644 index d86d8819d1..0000000000 --- a/iphone/Maps/Settings/Cells/SelectableCell.h +++ /dev/null @@ -1,7 +0,0 @@ -#import "MWMTableViewCell.h" - -@interface SelectableCell : MWMTableViewCell - -@property (weak, nonatomic) IBOutlet UILabel * titleLabel; - -@end diff --git a/iphone/Maps/Settings/Cells/SelectableCell.mm b/iphone/Maps/Settings/Cells/SelectableCell.mm deleted file mode 100644 index 289e5c7b23..0000000000 --- a/iphone/Maps/Settings/Cells/SelectableCell.mm +++ /dev/null @@ -1,12 +0,0 @@ -#import "SelectableCell.h" -#import "UIColor+MapsMeColor.h" - -@implementation SelectableCell - -- (void)awakeFromNib -{ - [super awakeFromNib]; - self.backgroundColor = [UIColor white]; -} - -@end diff --git a/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift b/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift new file mode 100644 index 0000000000..8c1135acb1 --- /dev/null +++ b/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift @@ -0,0 +1,29 @@ +@objc final class SettingsTableViewLinkCell: MWMTableViewCell { + + static let cellId = "SettingsTableViewLinkCell" + + @IBOutlet fileprivate weak var title: UILabel! + @IBOutlet fileprivate weak var info: UILabel! + + func config(title: String, info: String?) { + backgroundColor = UIColor.white() + + self.title.text = title + styleTitle() + + self.info.text = info + self.info.isHidden = info == nil + styleInfo() + } + + fileprivate func styleTitle() { + title.textColor = UIColor.blackPrimaryText() + title.font = UIFont.regular17() + } + + fileprivate func styleInfo() { + info.textColor = UIColor.blackSecondaryText() + info.font = UIFont.regular17() + } + +} diff --git a/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift b/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift new file mode 100644 index 0000000000..6b4dc8775e --- /dev/null +++ b/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift @@ -0,0 +1,19 @@ +@objc final class SettingsTableViewSelectableCell: MWMTableViewCell { + + static let cellId = "SettingsTableViewSelectableCell" + + @IBOutlet fileprivate weak var title: UILabel! + + func config(title: String) { + backgroundColor = UIColor.white() + + self.title.text = title + styleTitle() + } + + fileprivate func styleTitle() { + title.textColor = UIColor.blackPrimaryText() + title.font = UIFont.regular17() + } + +} diff --git a/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift b/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift new file mode 100644 index 0000000000..deb83451b7 --- /dev/null +++ b/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift @@ -0,0 +1,45 @@ +@objc protocol SettingsTableViewSwitchCellDelegate { + + func switchCell(_ cell: SettingsTableViewSwitchCell, didChangeValue value: Bool) + +} + +@objc final class SettingsTableViewSwitchCell: MWMTableViewCell { + + static let cellId = "SettingsTableViewSwitchCell" + + @IBOutlet fileprivate weak var title: UILabel! + @IBOutlet fileprivate weak var switchButton: UISwitch! { + didSet { + switchButton.addTarget(self, action: #selector(switchChanged), for: .valueChanged) + } + } + + weak var delegate: SettingsTableViewSwitchCellDelegate? + + func config(delegate: SettingsTableViewSwitchCellDelegate, title: String, isOn: Bool) { + backgroundColor = UIColor.white() + + self.delegate = delegate + + self.title.text = title + styleTitle() + + self.switchButton.isOn = isOn + styleSwitchButton() + } + + @IBAction fileprivate func switchChanged() { + delegate?.switchCell(self, didChangeValue: switchButton.isOn) + } + + fileprivate func styleTitle() { + title.textColor = UIColor.blackPrimaryText() + title.font = UIFont.regular17() + } + + fileprivate func styleSwitchButton() { + switchButton.onTintColor = UIColor.linkBlue() + } + +} diff --git a/iphone/Maps/Settings/Cells/SwitchCell.h b/iphone/Maps/Settings/Cells/SwitchCell.h deleted file mode 100644 index 8dfb1ad1c4..0000000000 --- a/iphone/Maps/Settings/Cells/SwitchCell.h +++ /dev/null @@ -1,17 +0,0 @@ -#import "MWMTableViewCell.h" - -@class SwitchCell; -@protocol SwitchCellDelegate <NSObject> - -- (void)switchCell:(SwitchCell *)cell didChangeValue:(BOOL)value; - -@end - -@interface SwitchCell : MWMTableViewCell - -@property(weak, nonatomic) IBOutlet UILabel * titleLabel; -@property(weak, nonatomic) IBOutlet UISwitch * switchButton; - -@property(weak, nonatomic) id<SwitchCellDelegate> delegate; - -@end diff --git a/iphone/Maps/Settings/Cells/SwitchCell.mm b/iphone/Maps/Settings/Cells/SwitchCell.mm deleted file mode 100644 index 292ec81b43..0000000000 --- a/iphone/Maps/Settings/Cells/SwitchCell.mm +++ /dev/null @@ -1,18 +0,0 @@ -#import "SwitchCell.h" -#import "UIColor+MapsMeColor.h" - -@implementation SwitchCell - -- (void)awakeFromNib -{ - [super awakeFromNib]; - [self.switchButton addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; - self.backgroundColor = [UIColor white]; -} - -- (void)switchChanged:(UISwitch *)sender -{ - [self.delegate switchCell:self didChangeValue:sender.on]; -} - -@end diff --git a/iphone/Maps/Settings/MWMAboutController.mm b/iphone/Maps/Settings/MWMAboutController.mm index 6df96a4dc4..ba58e96647 100644 --- a/iphone/Maps/Settings/MWMAboutController.mm +++ b/iphone/Maps/Settings/MWMAboutController.mm @@ -1,8 +1,8 @@ #import "MWMAboutController.h" #import "AppInfo.h" -#import "LinkCell.h" #import "MWMMailViewController.h" #import "Statistics.h" +#import "SwiftBridge.h" #import "WebViewController.h" #import "3party/Alohalytics/src/alohalytics_objc.h" @@ -18,13 +18,13 @@ extern NSString * const kAlohalyticsTapEventKey; @property(weak, nonatomic) IBOutlet UILabel * versionLabel; @property(weak, nonatomic) IBOutlet UILabel * dateLabel; -@property(weak, nonatomic) IBOutlet LinkCell * websiteCell; -@property(weak, nonatomic) IBOutlet LinkCell * blogCell; -@property(weak, nonatomic) IBOutlet LinkCell * facebookCell; -@property(weak, nonatomic) IBOutlet LinkCell * twitterCell; -@property(weak, nonatomic) IBOutlet LinkCell * subscribeCell; -@property(weak, nonatomic) IBOutlet LinkCell * rateCell; -@property(weak, nonatomic) IBOutlet LinkCell * copyrightCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * websiteCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * blogCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * facebookCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * twitterCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * subscribeCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * rateCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * copyrightCell; @property(nonatomic) IBOutlet UIView * headerView; @@ -56,7 +56,7 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - LinkCell * cell = static_cast<LinkCell *>([tableView cellForRowAtIndexPath:indexPath]); + auto cell = static_cast<SettingsTableViewLinkCell *>([tableView cellForRowAtIndexPath:indexPath]); if (cell == self.websiteCell) { [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"website"]; diff --git a/iphone/Maps/Settings/MWMMobileInternetViewController.mm b/iphone/Maps/Settings/MWMMobileInternetViewController.mm index 822e791003..a2bca313fd 100644 --- a/iphone/Maps/Settings/MWMMobileInternetViewController.mm +++ b/iphone/Maps/Settings/MWMMobileInternetViewController.mm @@ -1,17 +1,17 @@ #import "MWMMobileInternetViewController.h" #import "MWMNetworkPolicy.h" -#import "SelectableCell.h" #import "Statistics.h" +#import "SwiftBridge.h" using namespace network_policy; using np = platform::NetworkPolicy; @interface MWMMobileInternetViewController () -@property(weak, nonatomic) IBOutlet SelectableCell * always; -@property(weak, nonatomic) IBOutlet SelectableCell * ask; -@property(weak, nonatomic) IBOutlet SelectableCell * never; -@property(weak, nonatomic) SelectableCell * selected; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * always; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * ask; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * never; +@property(weak, nonatomic) SettingsTableViewSelectableCell * selected; @end @@ -22,7 +22,7 @@ using np = platform::NetworkPolicy; [super viewDidLoad]; self.title = L(@"mobile_data"); - SelectableCell * selected; + SettingsTableViewSelectableCell * selected; switch (GetStage()) { case np::Stage::Always: selected = self.always; break; @@ -33,7 +33,7 @@ using np = platform::NetworkPolicy; self.selected = selected; } -- (void)setSelected:(SelectableCell *)selected +- (void)setSelected:(SettingsTableViewSelectableCell *)selected { if ([_selected isEqual:selected]) return; @@ -61,7 +61,7 @@ using np = platform::NetworkPolicy; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - SelectableCell * selected = self.selected; + SettingsTableViewSelectableCell * selected = self.selected; selected.accessoryType = UITableViewCellAccessoryNone; selected = [tableView cellForRowAtIndexPath:indexPath]; selected.accessoryType = UITableViewCellAccessoryCheckmark; diff --git a/iphone/Maps/Settings/MWMNightModeController.mm b/iphone/Maps/Settings/MWMNightModeController.mm index 0ffb6f81db..96e209e88d 100644 --- a/iphone/Maps/Settings/MWMNightModeController.mm +++ b/iphone/Maps/Settings/MWMNightModeController.mm @@ -1,18 +1,18 @@ #import "MWMNightModeController.h" #import "MWMSettings.h" #import "MapsAppDelegate.h" -#import "SelectableCell.h" #import "Statistics.h" +#import "SwiftBridge.h" #import "UIColor+MapsMeColor.h" #include "Framework.h" @interface MWMNightModeController () -@property(weak, nonatomic) IBOutlet SelectableCell * autoSwitch; -@property(weak, nonatomic) IBOutlet SelectableCell * on; -@property(weak, nonatomic) IBOutlet SelectableCell * off; -@property(weak, nonatomic) SelectableCell * selectedCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * autoSwitch; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * on; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * off; +@property(weak, nonatomic) SettingsTableViewSelectableCell * selectedCell; @end @@ -45,7 +45,7 @@ } } -- (void)setSelectedCell:(SelectableCell *)cell +- (void)setSelectedCell:(SettingsTableViewSelectableCell *)cell { if ([_selectedCell isEqual:cell]) return; @@ -91,7 +91,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - SelectableCell * selectedCell = self.selectedCell; + SettingsTableViewSelectableCell * selectedCell = self.selectedCell; selectedCell.accessoryType = UITableViewCellAccessoryNone; selectedCell = [tableView cellForRowAtIndexPath:indexPath]; selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; diff --git a/iphone/Maps/Settings/MWMRecentTrackSettingsController.mm b/iphone/Maps/Settings/MWMRecentTrackSettingsController.mm index 3b0ec4a2f8..5e3b726ec9 100644 --- a/iphone/Maps/Settings/MWMRecentTrackSettingsController.mm +++ b/iphone/Maps/Settings/MWMRecentTrackSettingsController.mm @@ -1,6 +1,6 @@ #import "MWMRecentTrackSettingsController.h" -#import "SelectableCell.h" #import "Statistics.h" +#import "SwiftBridge.h" #include "Framework.h" @@ -12,13 +12,13 @@ typedef NS_ENUM(NSUInteger, DurationInHours) { One = 1, Two = 2, Six = 6, Twelve @interface MWMRecentTrackSettingsController () -@property(weak, nonatomic) IBOutlet SelectableCell * none; -@property(weak, nonatomic) IBOutlet SelectableCell * oneHour; -@property(weak, nonatomic) IBOutlet SelectableCell * twoHours; -@property(weak, nonatomic) IBOutlet SelectableCell * sixHours; -@property(weak, nonatomic) IBOutlet SelectableCell * twelveHours; -@property(weak, nonatomic) IBOutlet SelectableCell * oneDay; -@property(weak, nonatomic) SelectableCell * selectedCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * none; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * oneHour; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * twoHours; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * sixHours; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * twelveHours; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * oneDay; +@property(weak, nonatomic) SettingsTableViewSelectableCell * selectedCell; @end @@ -48,7 +48,7 @@ typedef NS_ENUM(NSUInteger, DurationInHours) { One = 1, Two = 2, Six = 6, Twelve self.selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; } -- (void)setSelectedCell:(SelectableCell *)selectedCell +- (void)setSelectedCell:(SettingsTableViewSelectableCell *)selectedCell { _selectedCell = selectedCell; auto & f = GetFramework(); @@ -90,7 +90,7 @@ typedef NS_ENUM(NSUInteger, DurationInHours) { One = 1, Two = 2, Six = 6, Twelve - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - SelectableCell * selectedCell = self.selectedCell; + SettingsTableViewSelectableCell * selectedCell = self.selectedCell; selectedCell.accessoryType = UITableViewCellAccessoryNone; selectedCell = [tableView cellForRowAtIndexPath:indexPath]; selectedCell.selected = NO; diff --git a/iphone/Maps/Settings/MWMSettingsViewController.mm b/iphone/Maps/Settings/MWMSettingsViewController.mm index 881db9ec5d..f22799ffd9 100644 --- a/iphone/Maps/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMSettingsViewController.mm @@ -1,12 +1,11 @@ #import "MWMSettingsViewController.h" -#import "LinkCell.h" #import "LocaleTranslator.h" #import "MWMAuthorizationCommon.h" #import "MWMNetworkPolicy.h" #import "MWMSettings.h" #import "MWMTextToSpeech.h" #import "Statistics.h" -#import "SwitchCell.h" +#import "SwiftBridge.h" #import "WebViewController.h" #import "3party/Alohalytics/src/alohalytics_objc.h" @@ -17,27 +16,27 @@ extern NSString * const kAlohalyticsTapEventKey; -@interface MWMSettingsViewController ()<SwitchCellDelegate> +@interface MWMSettingsViewController ()<SettingsTableViewSwitchCellDelegate> -@property(weak, nonatomic) IBOutlet LinkCell * profileCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * profileCell; -@property(weak, nonatomic) IBOutlet LinkCell * unitsCell; -@property(weak, nonatomic) IBOutlet SwitchCell * zoomButtonsCell; -@property(weak, nonatomic) IBOutlet SwitchCell * is3dCell; -@property(weak, nonatomic) IBOutlet SwitchCell * autoDownloadCell; -@property(weak, nonatomic) IBOutlet LinkCell * mobileInternetCell; -@property(weak, nonatomic) IBOutlet LinkCell * recentTrackCell; -@property(weak, nonatomic) IBOutlet SwitchCell * compassCalibrationCell; -@property(weak, nonatomic) IBOutlet SwitchCell * showOffersCell; -@property(weak, nonatomic) IBOutlet SwitchCell * statisticsCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * unitsCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * zoomButtonsCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * is3dCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * autoDownloadCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * mobileInternetCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * recentTrackCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * compassCalibrationCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * showOffersCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * statisticsCell; -@property(weak, nonatomic) IBOutlet LinkCell * nightModeCell; -@property(weak, nonatomic) IBOutlet SwitchCell * perspectiveViewCell; -@property(weak, nonatomic) IBOutlet SwitchCell * autoZoomCell; -@property(weak, nonatomic) IBOutlet LinkCell * voiceInstructionsCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * nightModeCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * perspectiveViewCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * autoZoomCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * voiceInstructionsCell; -@property(weak, nonatomic) IBOutlet LinkCell * helpCell; -@property(weak, nonatomic) IBOutlet LinkCell * aboutCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * helpCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * aboutCell; @end @@ -60,92 +59,128 @@ extern NSString * const kAlohalyticsTapEventKey; [self configProfileSection]; [self configCommonSection]; [self configNavigationSection]; + [self configInfoSection]; } - (void)configProfileSection { NSString * userName = osm_auth_ios::OSMUserName(); - self.profileCell.infoLabel.text = userName.length != 0 ? userName : @""; + [self.profileCell configWithTitle:L(@"profile") info:userName.length != 0 ? userName : @""]; } - (void)configCommonSection { switch ([MWMSettings measurementUnits]) { - case measurement_utils::Units::Metric: self.unitsCell.infoLabel.text = L(@"kilometres"); break; - case measurement_utils::Units::Imperial: self.unitsCell.infoLabel.text = L(@"miles"); break; + case measurement_utils::Units::Metric: + [self.unitsCell configWithTitle:L(@"measurement_units") info:L(@"kilometres")]; + break; + case measurement_utils::Units::Imperial: + [self.unitsCell configWithTitle:L(@"measurement_units") info:L(@"miles")]; + break; } - self.zoomButtonsCell.switchButton.on = [MWMSettings zoomButtonsEnabled]; - self.zoomButtonsCell.delegate = self; + [self.zoomButtonsCell configWithDelegate:self + title:L(@"pref_zoom_title") + isOn:[MWMSettings zoomButtonsEnabled]]; bool on = true, _ = true; GetFramework().Load3dMode(_, on); - self.is3dCell.switchButton.on = on; - self.is3dCell.delegate = self; + [self.is3dCell configWithDelegate:self title:L(@"pref_map_3d_buildings_title") isOn:on]; - self.autoDownloadCell.switchButton.on = [MWMSettings autoDownloadEnabled]; - self.autoDownloadCell.delegate = self; + [self.autoDownloadCell configWithDelegate:self + title:L(@"autodownload") + isOn:[MWMSettings autoDownloadEnabled]]; - NSString * internetLabel = nil; - using np = platform::NetworkPolicy; + using stage = platform::NetworkPolicy::Stage; switch (network_policy::GetStage()) { - case np::Stage::Always: internetLabel = L(@"mobile_data_option_always"); break; - case np::Stage::Session: internetLabel = L(@"mobile_data_option_today"); break; - case np::Stage::Never: internetLabel = L(@"mobile_data_option_never"); break; + case stage::Always: + [self.mobileInternetCell configWithTitle:L(@"mobile_data") + info:L(@"mobile_data_option_always")]; + break; + case stage::Session: + [self.mobileInternetCell configWithTitle:L(@"mobile_data") info:L(@"mobile_data_option_today")]; + break; + case stage::Never: + [self.mobileInternetCell configWithTitle:L(@"mobile_data") info:L(@"mobile_data_option_never")]; + break; } - self.mobileInternetCell.infoLabel.text = internetLabel; if (!GpsTracker::Instance().IsEnabled()) { - self.recentTrackCell.infoLabel.text = L(@"duration_disabled"); + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") + info:L(@"duration_disabled")]; } else { switch (GpsTracker::Instance().GetDuration().count()) { - case 1: self.recentTrackCell.infoLabel.text = L(@"duration_1_hour"); break; - case 2: self.recentTrackCell.infoLabel.text = L(@"duration_2_hours"); break; - case 6: self.recentTrackCell.infoLabel.text = L(@"duration_6_hours"); break; - case 12: self.recentTrackCell.infoLabel.text = L(@"duration_12_hours"); break; - case 24: self.recentTrackCell.infoLabel.text = L(@"duration_1_day"); break; + case 1: + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") + info:L(@"duration_1_hour")]; + break; + case 2: + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") + info:L(@"duration_2_hours")]; + break; + case 6: + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") + info:L(@"duration_6_hours")]; + break; + case 12: + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") + info:L(@"duration_12_hours")]; + break; + case 24: + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") + info:L(@"duration_1_day")]; + break; default: NSAssert(false, @"Incorrect hours value"); break; } } - self.compassCalibrationCell.switchButton.on = [MWMSettings compassCalibrationEnabled]; - self.compassCalibrationCell.delegate = self; + [self.compassCalibrationCell configWithDelegate:self + title:L(@"pref_calibration_title") + isOn:[MWMSettings compassCalibrationEnabled]]; - self.showOffersCell.switchButton.on = ![MWMSettings adForbidden]; - self.showOffersCell.delegate = self; + [self.showOffersCell configWithDelegate:self + title:L(@"showcase_settings_title") + isOn:![MWMSettings adForbidden]]; - self.statisticsCell.switchButton.on = [MWMSettings statisticsEnabled]; - self.statisticsCell.delegate = self; + [self.statisticsCell configWithDelegate:self + title:L(@"allow_statistics") + isOn:[MWMSettings statisticsEnabled]]; } - (void)configNavigationSection { if ([MWMSettings autoNightModeEnabled]) { - self.nightModeCell.infoLabel.text = L(@"pref_map_style_auto"); + [self.nightModeCell configWithTitle:L(@"pref_map_style_title") info:L(@"pref_map_style_auto")]; } else { switch (GetFramework().GetMapStyle()) { - case MapStyleDark: self.nightModeCell.infoLabel.text = L(@"pref_map_style_night"); break; - default: self.nightModeCell.infoLabel.text = L(@"pref_map_style_default"); break; + case MapStyleDark: + [self.nightModeCell configWithTitle:L(@"pref_map_style_title") + info:L(@"pref_map_style_night")]; + break; + default: + [self.nightModeCell configWithTitle:L(@"pref_map_style_title") + info:L(@"pref_map_style_default")]; + break; } } bool _ = true, on = true; GetFramework().Load3dMode(on, _); - self.perspectiveViewCell.switchButton.on = on; - self.perspectiveViewCell.delegate = self; + [self.perspectiveViewCell configWithDelegate:self title:L(@"pref_map_3d_title") isOn:on]; - self.autoZoomCell.switchButton.on = GetFramework().LoadAutoZoom(); - self.autoZoomCell.delegate = self; + [self.autoZoomCell configWithDelegate:self + title:L(@"pref_map_auto_zoom") + isOn:GetFramework().LoadAutoZoom()]; if ([MWMTextToSpeech isTTSEnabled]) { @@ -154,22 +189,29 @@ extern NSString * const kAlohalyticsTapEventKey; { string const savedLanguageTwine = locale_translator::bcp47ToTwineLanguage(savedLanguage); NSString * language = @(tts::translatedTwine(savedLanguageTwine).c_str()); - self.voiceInstructionsCell.infoLabel.text = language; + [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") info:language]; } else { - self.voiceInstructionsCell.infoLabel.text = @""; + [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") info:nil]; } } else { - self.voiceInstructionsCell.infoLabel.text = L(@"duration_disabled"); + [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") + info:L(@"duration_disabled")]; } } -#pragma mark - SwitchCellDelegate +- (void)configInfoSection +{ + [self.helpCell configWithTitle:L(@"help") info:nil]; + [self.aboutCell configWithTitle:L(@"about_menu_title") info:nil]; +} + +#pragma mark - SettingsTableViewSwitchCellDelegate -- (void)switchCell:(SwitchCell *)cell didChangeValue:(BOOL)value +- (void)switchCell:(SettingsTableViewSwitchCell *)cell didChangeValue:(BOOL)value { if (cell == self.zoomButtonsCell) { @@ -240,7 +282,7 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - LinkCell * cell = static_cast<LinkCell *>([tableView cellForRowAtIndexPath:indexPath]); + auto cell = static_cast<SettingsTableViewLinkCell *>([tableView cellForRowAtIndexPath:indexPath]); if (cell == self.profileCell) { [Statistics logEvent:kStatSettingsOpenSection withParameters:@{kStatName : kStatAuthorization}]; diff --git a/iphone/Maps/Settings/MWMTTSLanguageViewController.mm b/iphone/Maps/Settings/MWMTTSLanguageViewController.mm index 8b1e2b269a..4529c4214f 100644 --- a/iphone/Maps/Settings/MWMTTSLanguageViewController.mm +++ b/iphone/Maps/Settings/MWMTTSLanguageViewController.mm @@ -1,7 +1,7 @@ -#import "MWMTextToSpeech.h" #import "MWMTTSLanguageViewController.h" #import "MWMTTSSettingsViewController.h" -#import "SelectableCell.h" +#import "MWMTextToSpeech.h" +#import "SwiftBridge.h" #import "UIColor+MapsMeColor.h" static NSString * const kUnwingSegueIdentifier = @"UnwindToTTSSettings"; @@ -15,7 +15,7 @@ static NSString * const kUnwingSegueIdentifier = @"UnwindToTTSSettings"; self.tableView.separatorColor = [UIColor blackDividers]; } -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(SelectableCell *)sender +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(SettingsTableViewSelectableCell *)sender { if (![segue.identifier isEqualToString:kUnwingSegueIdentifier]) return; @@ -31,10 +31,14 @@ static NSString * const kUnwingSegueIdentifier = @"UnwindToTTSSettings"; return [[MWMTextToSpeech tts] availableLanguages].size(); } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +- (UITableViewCell *)tableView:(UITableView *)tableView + cellForRowAtIndexPath:(NSIndexPath *)indexPath { - SelectableCell * cell = (SelectableCell *)[tableView dequeueReusableCellWithIdentifier:[SelectableCell className]]; - cell.titleLabel.text = @([[MWMTextToSpeech tts] availableLanguages][indexPath.row].second.c_str()); + auto cellId = [SettingsTableViewSelectableCell cellId]; + auto cell = static_cast<SettingsTableViewSelectableCell *>( + [tableView dequeueReusableCellWithIdentifier:cellId]); + [cell + configWithTitle:@([[MWMTextToSpeech tts] availableLanguages][indexPath.row].second.c_str())]; return cell; } diff --git a/iphone/Maps/Settings/MWMTTSSettingsViewController.h b/iphone/Maps/Settings/MWMTTSSettingsViewController.h index 9c364a5247..f52576ce96 100644 --- a/iphone/Maps/Settings/MWMTTSSettingsViewController.h +++ b/iphone/Maps/Settings/MWMTTSSettingsViewController.h @@ -1,7 +1,7 @@ #import "MWMTableViewController.h" -#include "std/utility.hpp" #include "std/string.hpp" +#include "std/utility.hpp" @interface MWMTTSSettingsViewController : MWMTableViewController diff --git a/iphone/Maps/Settings/MWMTTSSettingsViewController.mm b/iphone/Maps/Settings/MWMTTSSettingsViewController.mm index bc120aee3c..36c040c4a1 100644 --- a/iphone/Maps/Settings/MWMTTSSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMTTSSettingsViewController.mm @@ -1,9 +1,8 @@ #import "MWMTTSSettingsViewController.h" #import <AVFoundation/AVFoundation.h> -#import "LinkCell.h" #import "MWMTextToSpeech.h" -#import "SelectableCell.h" #import "Statistics.h" +#import "SwiftBridge.h" #import "UIColor+MapsMeColor.h" #import "WebViewController.h" @@ -110,10 +109,12 @@ using namespace locale_translator; { if (indexPath.row == 0) { - SelectableCell * cell = (SelectableCell *)[tableView - dequeueReusableCellWithIdentifier:[SelectableCell className]]; - cell.titleLabel.text = L(@"duration_disabled"); - cell.accessoryType = [MWMTextToSpeech isTTSEnabled] ? UITableViewCellAccessoryNone : UITableViewCellAccessoryCheckmark; + auto cellId = [SettingsTableViewSelectableCell cellId]; + auto cell = static_cast<SettingsTableViewSelectableCell *>( + [tableView dequeueReusableCellWithIdentifier:cellId]); + [cell configWithTitle:L(@"duration_disabled")]; + cell.accessoryType = [MWMTextToSpeech isTTSEnabled] ? UITableViewCellAccessoryNone + : UITableViewCellAccessoryCheckmark; return cell; } else @@ -121,17 +122,19 @@ using namespace locale_translator; NSInteger const row = indexPath.row - 1; if (row == _languages.size()) { - LinkCell * cell = - (LinkCell *)[tableView dequeueReusableCellWithIdentifier:[LinkCell className]]; - cell.titleLabel.text = L(@"pref_tts_other_section_title"); + auto cellId = [SettingsTableViewLinkCell cellId]; + auto cell = static_cast<SettingsTableViewLinkCell *>( + [tableView dequeueReusableCellWithIdentifier:cellId]); + [cell configWithTitle:L(@"pref_tts_other_section_title") info:nil]; return cell; } else { - SelectableCell * cell = (SelectableCell *)[tableView - dequeueReusableCellWithIdentifier:[SelectableCell className]]; + auto cellId = [SettingsTableViewSelectableCell cellId]; + auto cell = static_cast<SettingsTableViewSelectableCell *>( + [tableView dequeueReusableCellWithIdentifier:cellId]); pair<string, string> const p = _languages[row]; - cell.titleLabel.text = @(p.second.c_str()); + [cell configWithTitle:@(p.second.c_str())]; BOOL const isSelected = [@(p.first.c_str()) isEqualToString:[MWMTextToSpeech savedLanguage]]; cell.accessoryType = [MWMTextToSpeech isTTSEnabled] && isSelected @@ -143,9 +146,10 @@ using namespace locale_translator; } else { - LinkCell * cell = - (LinkCell *)[tableView dequeueReusableCellWithIdentifier:[LinkCell className]]; - cell.titleLabel.text = L(@"pref_tts_how_to_set_up_voice"); + auto cellId = [SettingsTableViewLinkCell cellId]; + auto cell = static_cast<SettingsTableViewLinkCell *>( + [tableView dequeueReusableCellWithIdentifier:cellId]); + [cell configWithTitle:L(@"pref_tts_how_to_set_up_voice") info:nil]; return cell; } } diff --git a/iphone/Maps/Settings/MWMUnitsController.mm b/iphone/Maps/Settings/MWMUnitsController.mm index 859b99e12c..d82139c005 100644 --- a/iphone/Maps/Settings/MWMUnitsController.mm +++ b/iphone/Maps/Settings/MWMUnitsController.mm @@ -1,13 +1,13 @@ #import "MWMUnitsController.h" #import "MWMSettings.h" -#import "SelectableCell.h" #import "Statistics.h" +#import "SwiftBridge.h" @interface MWMUnitsController () -@property(weak, nonatomic) IBOutlet SelectableCell * kilometers; -@property(weak, nonatomic) IBOutlet SelectableCell * miles; -@property(weak, nonatomic) SelectableCell * selectedCell; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * kilometers; +@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * miles; +@property(weak, nonatomic) SettingsTableViewSelectableCell * selectedCell; @end @@ -25,9 +25,9 @@ } } -- (void)setSelectedCell:(SelectableCell *)cell +- (void)setSelectedCell:(SettingsTableViewSelectableCell *)cell { - SelectableCell * selectedCell = _selectedCell; + SettingsTableViewSelectableCell * selectedCell = _selectedCell; if (selectedCell == cell) return; |