From 959974e43c1060d0717988bc67672af0247666bd Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Thu, 15 Dec 2016 17:23:42 +0300 Subject: [PATCH] [swift] Review fixes. --- .../Classes/MWMTableViewCell+CellId.swift | 3 + iphone/Maps/Maps.xcodeproj/project.pbxproj | 8 ++ .../Cells/SettingsTableViewLinkCell.swift | 2 - .../SettingsTableViewSelectableCell.swift | 2 - .../Cells/SettingsTableViewSwitchCell.swift | 2 - .../Settings/MWMSettingsViewController.mm | 91 ++++++------------- 6 files changed, 40 insertions(+), 68 deletions(-) create mode 100644 iphone/Maps/Classes/MWMTableViewCell+CellId.swift diff --git a/iphone/Maps/Classes/MWMTableViewCell+CellId.swift b/iphone/Maps/Classes/MWMTableViewCell+CellId.swift new file mode 100644 index 0000000000..2f07f390cd --- /dev/null +++ b/iphone/Maps/Classes/MWMTableViewCell+CellId.swift @@ -0,0 +1,3 @@ +extension MWMTableViewCell { + static func cellId() -> String { return String(describing: self) } +} diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index afa1139e4a..94ab1de4aa 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -16,6 +16,9 @@ 34002A6E1D2F9D0700AC201E /* MWMRouter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34002A6C1D2F9D0700AC201E /* MWMRouter.mm */; }; 3400A6811CA29D7D003DA0EC /* NSString+Categories.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */; }; 3400A6821CA29D7D003DA0EC /* NSString+Categories.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */; }; + 3400AB381E02E8CE004036E2 /* MWMTableViewCell+CellId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3400AB371E02E8CE004036E2 /* MWMTableViewCell+CellId.swift */; }; + 3400AB391E02E8CE004036E2 /* MWMTableViewCell+CellId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3400AB371E02E8CE004036E2 /* MWMTableViewCell+CellId.swift */; }; + 3400AB3A1E02E8CE004036E2 /* MWMTableViewCell+CellId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3400AB371E02E8CE004036E2 /* MWMTableViewCell+CellId.swift */; }; 3401CD671C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */; }; 3401CD681C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */; }; 3401CD691C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3401CD661C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib */; }; @@ -1416,6 +1419,7 @@ 34002A6C1D2F9D0700AC201E /* MWMRouter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMRouter.mm; sourceTree = ""; }; 3400A67F1CA29D7D003DA0EC /* NSString+Categories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+Categories.h"; path = "Categories/NSString+Categories.h"; sourceTree = ""; }; 3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "NSString+Categories.mm"; path = "Categories/NSString+Categories.mm"; sourceTree = ""; }; + 3400AB371E02E8CE004036E2 /* MWMTableViewCell+CellId.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "MWMTableViewCell+CellId.swift"; sourceTree = ""; }; 3401CD641C3C03A80028C6F8 /* MWMEditorTextTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMEditorTextTableViewCell.h; sourceTree = ""; }; 3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMEditorTextTableViewCell.mm; sourceTree = ""; }; 3401CD661C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMEditorTextTableViewCell.xib; sourceTree = ""; }; @@ -2417,6 +2421,7 @@ 974D041B1977DE430081D0A7 /* LocalNotificationManager.mm */, B0DFE62F1A1B78A200B6C35E /* LocalNotifications.plist */, F626D52C1C3E6CAA00C17D15 /* MWMTableViewCell.h */, + 3400AB371E02E8CE004036E2 /* MWMTableViewCell+CellId.swift */, F626D52D1C3E6CAA00C17D15 /* MWMTableViewCell.mm */, 46F26CD610F623BA00ECCA39 /* EAGLView.h */, 46F26CD710F623BA00ECCA39 /* EAGLView.mm */, @@ -4880,6 +4885,7 @@ 3491E7CB1C06F1F10042FE24 /* MWMPlacePageButtonCell.mm in Sources */, 348C26051D701B9F00813924 /* MWMHelpController.mm in Sources */, 348868EB1D8721650069BBA3 /* MWMSearchNoResults.mm in Sources */, + 3400AB381E02E8CE004036E2 /* MWMTableViewCell+CellId.swift in Sources */, 346B42AB1DD5E3D20094EBEE /* MWMLocationNotFoundAlert.mm in Sources */, 34BBB7231DD0853B0002E025 /* MWMSearchManager+Layout.mm in Sources */, 341F99D91C6B1165001C67B8 /* MWMMapDownloaderPlaceTableViewCell.mm in Sources */, @@ -5133,6 +5139,7 @@ 6741AA1D1BF340DE002C974C /* MWMDownloadTransitMapAlert.mm in Sources */, 341F99DA1C6B1165001C67B8 /* MWMMapDownloaderPlaceTableViewCell.mm in Sources */, 341F99D61C6B1165001C67B8 /* MWMMapDownloaderLargeCountryTableViewCell.mm in Sources */, + 3400AB391E02E8CE004036E2 /* MWMTableViewCell+CellId.swift in Sources */, 346B42AC1DD5E3D20094EBEE /* MWMLocationNotFoundAlert.mm in Sources */, 34BBB7241DD0853B0002E025 /* MWMSearchManager+Layout.mm in Sources */, 348C26061D701B9F00813924 /* MWMHelpController.mm in Sources */, @@ -5336,6 +5343,7 @@ 849CF71A1DE842290024A8A5 /* MWMDropDown.mm in Sources */, 849CF71B1DE842290024A8A5 /* MWMEditorSelectTableViewCell.mm in Sources */, 849CF71C1DE842290024A8A5 /* MWMPageController.mm in Sources */, + 3400AB3A1E02E8CE004036E2 /* MWMTableViewCell+CellId.swift in Sources */, 849CF71D1DE842290024A8A5 /* MWMNavigationDashboardManager.mm in Sources */, 849CF71E1DE842290024A8A5 /* MWMEditorViewController.mm in Sources */, 849CF71F1DE842290024A8A5 /* MWMMapDownloaderExtendedDataSourceWithAds.mm in Sources */, diff --git a/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift b/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift index 8c1135acb1..2ca6547bec 100644 --- a/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift +++ b/iphone/Maps/Settings/Cells/SettingsTableViewLinkCell.swift @@ -1,7 +1,5 @@ @objc final class SettingsTableViewLinkCell: MWMTableViewCell { - static let cellId = "SettingsTableViewLinkCell" - @IBOutlet fileprivate weak var title: UILabel! @IBOutlet fileprivate weak var info: UILabel! diff --git a/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift b/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift index 6b4dc8775e..d5df003c07 100644 --- a/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift +++ b/iphone/Maps/Settings/Cells/SettingsTableViewSelectableCell.swift @@ -1,7 +1,5 @@ @objc final class SettingsTableViewSelectableCell: MWMTableViewCell { - static let cellId = "SettingsTableViewSelectableCell" - @IBOutlet fileprivate weak var title: UILabel! func config(title: String) { diff --git a/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift b/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift index deb83451b7..0335f2d8d9 100644 --- a/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift +++ b/iphone/Maps/Settings/Cells/SettingsTableViewSwitchCell.swift @@ -6,8 +6,6 @@ @objc final class SettingsTableViewSwitchCell: MWMTableViewCell { - static let cellId = "SettingsTableViewSwitchCell" - @IBOutlet fileprivate weak var title: UILabel! @IBOutlet fileprivate weak var switchButton: UISwitch! { didSet { diff --git a/iphone/Maps/Settings/MWMSettingsViewController.mm b/iphone/Maps/Settings/MWMSettingsViewController.mm index f22799ffd9..873141db22 100644 --- a/iphone/Maps/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMSettingsViewController.mm @@ -70,15 +70,13 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)configCommonSection { + NSString * units = nil; switch ([MWMSettings measurementUnits]) { - 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; + case measurement_utils::Units::Metric: units = L(@"kilometres"); break; + case measurement_utils::Units::Imperial: units = L(@"miles"); break; } + [self.unitsCell configWithTitle:L(@"measurement_units") info:units]; [self.zoomButtonsCell configWithDelegate:self title:L(@"pref_zoom_title") @@ -92,53 +90,36 @@ extern NSString * const kAlohalyticsTapEventKey; title:L(@"autodownload") isOn:[MWMSettings autoDownloadEnabled]]; + NSString * mobileInternet = nil; using stage = platform::NetworkPolicy::Stage; switch (network_policy::GetStage()) { - 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; + case stage::Always: mobileInternet = L(@"mobile_data_option_always"); break; + case stage::Session: mobileInternet = L(@"mobile_data_option_today"); break; + case stage::Never: mobileInternet = L(@"mobile_data_option_never"); break; } + [self.mobileInternetCell configWithTitle:L(@"mobile_data") info:mobileInternet]; + + NSString * recentTrack = nil; if (!GpsTracker::Instance().IsEnabled()) { - [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") - info:L(@"duration_disabled")]; + recentTrack = L(@"duration_disabled"); } else { switch (GpsTracker::Instance().GetDuration().count()) { - 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; + case 1: recentTrack = L(@"duration_1_hour"); break; + case 2: recentTrack = L(@"duration_2_hours"); break; + case 6: recentTrack = L(@"duration_6_hours"); break; + case 12: recentTrack = L(@"duration_12_hours"); break; + case 24: recentTrack = L(@"duration_1_day"); break; default: NSAssert(false, @"Incorrect hours value"); break; } } + [self.recentTrackCell configWithTitle:L(@"pref_track_record_title") info:recentTrack]; + [self.compassCalibrationCell configWithDelegate:self title:L(@"pref_calibration_title") @@ -155,24 +136,14 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)configNavigationSection { + NSString * nightMode = nil; if ([MWMSettings autoNightModeEnabled]) - { - [self.nightModeCell configWithTitle:L(@"pref_map_style_title") info:L(@"pref_map_style_auto")]; - } + nightMode = L(@"pref_map_style_auto"); + else if (GetFramework().GetMapStyle() == MapStyleDark) + nightMode = L(@"pref_map_style_night"); else - { - switch (GetFramework().GetMapStyle()) - { - 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; - } - } + nightMode = L(@"pref_map_style_default"); + [self.nightModeCell configWithTitle:L(@"pref_map_style_title") info:nightMode]; bool _ = true, on = true; GetFramework().Load3dMode(on, _); @@ -182,25 +153,21 @@ extern NSString * const kAlohalyticsTapEventKey; title:L(@"pref_map_auto_zoom") isOn:GetFramework().LoadAutoZoom()]; + NSString * voiceInstructions = nil; if ([MWMTextToSpeech isTTSEnabled]) { NSString * savedLanguage = [MWMTextToSpeech savedLanguage]; if (savedLanguage.length != 0) { string const savedLanguageTwine = locale_translator::bcp47ToTwineLanguage(savedLanguage); - NSString * language = @(tts::translatedTwine(savedLanguageTwine).c_str()); - [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") info:language]; - } - else - { - [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") info:nil]; + voiceInstructions = @(tts::translatedTwine(savedLanguageTwine).c_str()); } } else { - [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") - info:L(@"duration_disabled")]; + voiceInstructions = L(@"duration_disabled"); } + [self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") info:voiceInstructions]; } - (void)configInfoSection