diff --git a/iphone/Maps/Bridging/BridgeControllers.swift b/iphone/Maps/Bridging/BridgeControllers.swift index 95877ab24..3bd8b2f00 100644 --- a/iphone/Maps/Bridging/BridgeControllers.swift +++ b/iphone/Maps/Bridging/BridgeControllers.swift @@ -9,6 +9,13 @@ import UIKit profileBridgeController.view.backgroundColor = .systemGroupedBackground return profileBridgeController } + + /// The `RoutingOptionsView` for presentation in an alert + @objc static func routingOptions() -> UIViewController { + let routinOptionsBridgeController = UIHostingController(rootView: RoutingOptionsView()) + routinOptionsBridgeController.view.backgroundColor = .systemGroupedBackground + return routinOptionsBridgeController + } } diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 4ee132cf5..51c5df5d2 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -605,6 +605,10 @@ NSString *const kSettingsSegue = @"Map2Settings"; [self.navigationController pushViewController:descriptionViewController animated:YES]; } +- (void)openDrivingOptions { + [self presentViewController:BridgeControllers.routingOptions animated:YES completion:nil]; +} + - (void)processMyPositionStateModeEvent:(MWMMyPositionMode)mode { self.currentPositionMode = mode; [MWMLocationManager setMyPositionMode:mode]; diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index dae227f99..00d82824b 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 272F1F3D2E0EE0C800FA52EF /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1F3C2E0EE0C400FA52EF /* ProfileView.swift */; }; 272F1F462E0EEF9400FA52EF /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1F452E0EEF8B00FA52EF /* SafariView.swift */; }; 2765D1D02E13F9C20005CA2B /* BridgeControllers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2765D1CD2E13F9BC0005CA2B /* BridgeControllers.swift */; }; + 27768F482E1FF8880086784A /* RoutingOptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27768F472E1FF8830086784A /* RoutingOptionsView.swift */; }; 279367562E1BE16300AA5C3D /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279367552E1BE16300AA5C3D /* Settings.swift */; }; 2793675A2E1BE17300AA5C3D /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279367592E1BE17300AA5C3D /* SettingsView.swift */; }; 27AF184C2E1D5B2D00CD41E2 /* SettingsNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27AF184B2E1D5A2700CD41E2 /* SettingsNavigationView.swift */; }; @@ -775,6 +776,7 @@ 272F1F3C2E0EE0C400FA52EF /* ProfileView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = ""; tabWidth = 4; }; 272F1F452E0EEF8B00FA52EF /* SafariView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = ""; tabWidth = 4; }; 2765D1CD2E13F9BC0005CA2B /* BridgeControllers.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = BridgeControllers.swift; sourceTree = ""; tabWidth = 4; }; + 27768F472E1FF8830086784A /* RoutingOptionsView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = RoutingOptionsView.swift; sourceTree = ""; tabWidth = 4; }; 279367552E1BE16300AA5C3D /* Settings.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; tabWidth = 4; }; 279367592E1BE17300AA5C3D /* SettingsView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; name = SettingsView.swift; path = UI/Settings/SettingsView.swift; sourceTree = SOURCE_ROOT; tabWidth = 4; }; 27AF184B2E1D5A2700CD41E2 /* SettingsNavigationView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = SettingsNavigationView.swift; sourceTree = ""; tabWidth = 4; }; @@ -1946,6 +1948,14 @@ path = Model; sourceTree = ""; }; + 27768F442E1FF8620086784A /* Routing */ = { + isa = PBXGroup; + children = ( + 27768F472E1FF8830086784A /* RoutingOptionsView.swift */, + ); + path = Routing; + sourceTree = ""; + }; 27AF185B2E1DB64B00CD41E2 /* Settings Types */ = { isa = PBXGroup; children = ( @@ -3611,6 +3621,7 @@ F6E2FBFB1E097B9F0083EBEC /* UI */ = { isa = PBXGroup; children = ( + 27768F442E1FF8620086784A /* Routing */, ED9857022C4ECFFC00694F6C /* MailComposer */, ED43B8B92C12061600D07BAA /* DocumentPicker */, ED99667C2B94FBC20083CE55 /* ColorPicker */, @@ -4611,6 +4622,7 @@ EDC4E34C2C5D1BEF009286A2 /* RecentlyDeletedCategoriesViewModel.swift in Sources */, F62607FD207B790300176C5A /* SpinnerAlert.swift in Sources */, 3444DFD21F17620C00E73099 /* MWMMapWidgetsHelper.mm in Sources */, + 27768F482E1FF8880086784A /* RoutingOptionsView.swift in Sources */, 3472B5E1200F86C800DC6CD5 /* MWMEditorHelper.mm in Sources */, 99F3EB1123F418C900C713F8 /* PlacePageBuilder.swift in Sources */, 4735008A23A83CF700661A95 /* DownloadedMapsDataSource.swift in Sources */, diff --git a/iphone/Maps/Model/Settings.swift b/iphone/Maps/Model/Settings.swift index 51dd28e48..4d48d057c 100644 --- a/iphone/Maps/Model/Settings.swift +++ b/iphone/Maps/Model/Settings.swift @@ -287,7 +287,9 @@ import Combine return RoutingOptions().avoidToll } set { - RoutingOptions().avoidToll = newValue + var routingOptions = RoutingOptions() + routingOptions.avoidToll = newValue + routingOptions.save() } } @@ -298,7 +300,9 @@ import Combine return RoutingOptions().avoidDirty } set { - RoutingOptions().avoidDirty = newValue + var routingOptions = RoutingOptions() + routingOptions.avoidDirty = newValue + routingOptions.save() } } @@ -309,7 +313,9 @@ import Combine return RoutingOptions().avoidFerry } set { - RoutingOptions().avoidFerry = newValue + var routingOptions = RoutingOptions() + routingOptions.avoidFerry = newValue + routingOptions.save() } } @@ -320,7 +326,9 @@ import Combine return RoutingOptions().avoidMotorway } set { - RoutingOptions().avoidMotorway = newValue + var routingOptions = RoutingOptions() + routingOptions.avoidMotorway = newValue + routingOptions.save() } } diff --git a/iphone/Maps/UI/Routing/RoutingOptionsView.swift b/iphone/Maps/UI/Routing/RoutingOptionsView.swift new file mode 100644 index 000000000..dba1f55a3 --- /dev/null +++ b/iphone/Maps/UI/Routing/RoutingOptionsView.swift @@ -0,0 +1,81 @@ +import SwiftUI + +/// View for the routing options +struct RoutingOptionsView: View { + // MARK: - Properties + + /// The dismiss action of the environment + @Environment(\.dismiss) private var dismiss + + + /// If toll roads should be avoided during routing + @State var shouldAvoidTollRoadsWhileRouting: Bool = false + + + /// If unpaved roads should be avoided during routing + @State var shouldAvoidUnpavedRoadsWhileRouting: Bool = false + + + /// If ferries should be avoided during routing + @State var shouldAvoidFerriesWhileRouting: Bool = false + + + /// If motorways should be avoided during routing + @State var shouldAvoidMotorwaysWhileRouting: Bool = false + + + /// The actual view + var body: some View { + NavigationView { + List { + Section { + Toggle("avoid_tolls", isOn: $shouldAvoidTollRoadsWhileRouting) + .tint(.accent) + + Toggle("avoid_unpaved", isOn: $shouldAvoidUnpavedRoadsWhileRouting) + .tint(.accent) + + Toggle("avoid_ferry", isOn: $shouldAvoidFerriesWhileRouting) + .tint(.accent) + + Toggle("avoid_motorways", isOn: $shouldAvoidMotorwaysWhileRouting) + .tint(.accent) + } + } + .navigationTitle(String(localized: "driving_options_title")) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .confirmationAction) { + Button { + dismiss() + } label: { + Text("close") + } + } + } + } + .navigationViewStyle(StackNavigationViewStyle()) + .onAppear { + shouldAvoidTollRoadsWhileRouting = Settings.shouldAvoidTollRoadsWhileRouting + shouldAvoidUnpavedRoadsWhileRouting = Settings.shouldAvoidUnpavedRoadsWhileRouting + shouldAvoidFerriesWhileRouting = Settings.shouldAvoidFerriesWhileRouting + shouldAvoidMotorwaysWhileRouting = Settings.shouldAvoidMotorwaysWhileRouting + } + .onChange(of: shouldAvoidTollRoadsWhileRouting) { changedShouldAvoidTollRoadsWhileRouting in + Settings.shouldAvoidTollRoadsWhileRouting = changedShouldAvoidTollRoadsWhileRouting + } + .onChange(of: shouldAvoidUnpavedRoadsWhileRouting) { changedShouldAvoidUnpavedRoadsWhileRouting in + Settings.shouldAvoidUnpavedRoadsWhileRouting = changedShouldAvoidUnpavedRoadsWhileRouting + } + .onChange(of: shouldAvoidUnpavedRoadsWhileRouting) { changedShouldAvoidUnpavedRoadsWhileRouting in + Settings.shouldAvoidUnpavedRoadsWhileRouting = changedShouldAvoidUnpavedRoadsWhileRouting + } + .onChange(of: shouldAvoidFerriesWhileRouting) { changedShouldAvoidFerriesWhileRouting in + Settings.shouldAvoidFerriesWhileRouting = changedShouldAvoidFerriesWhileRouting + } + .onChange(of: shouldAvoidMotorwaysWhileRouting) { changedShouldAvoidMotorwaysWhileRouting in + Settings.shouldAvoidMotorwaysWhileRouting = changedShouldAvoidMotorwaysWhileRouting + } + .accentColor(.alternativeAccent) + } +} diff --git a/iphone/Maps/UI/Settings/SettingsNavigationView.swift b/iphone/Maps/UI/Settings/SettingsNavigationView.swift index 1122d972c..813854465 100644 --- a/iphone/Maps/UI/Settings/SettingsNavigationView.swift +++ b/iphone/Maps/UI/Settings/SettingsNavigationView.swift @@ -1,6 +1,6 @@ import SwiftUI -/// View for thenavigation settings +/// View for the navigation settings struct SettingsNavigationView: View { // MARK: - Properties