[traffic][ios] Make HttpTraffSource configurable in Preferences

Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
Yannik Bloscheck
2025-08-06 16:54:03 +02:00
parent dde50bd0a1
commit 73a70d943e
9 changed files with 387 additions and 0 deletions

View File

@@ -44,6 +44,14 @@ struct SettingsNavigationView: View {
@State var shouldAvoidMotorwaysWhileRouting: Bool = false
/// If live traffic data should be used
@State var hasLiveTraffic: Bool = false
/// The url of the live traffic data server
@State var liveTrafficServerUrlString: String = ""
/// The actual view
var body: some View {
List {
@@ -123,6 +131,24 @@ struct SettingsNavigationView: View {
} header: {
Text("driving_options_title")
}
Section {
Toggle(isOn: $hasLiveTraffic) {
VStack(alignment: .leading) {
Text("traffic_http_enabled")
Text("traffic_http_enabled_description")
.font(.footnote)
.foregroundStyle(.secondary)
}
}
.tint(.accent)
TextField("traffic_http_url", text: $liveTrafficServerUrlString, prompt: Text("traffic_http_url_not_set"))
.tint(.accent)
} header: {
Text("traffic_http")
}
}
.accentColor(.accent)
.navigationViewStyle(StackNavigationViewStyle())
@@ -138,6 +164,8 @@ struct SettingsNavigationView: View {
shouldAvoidUnpavedRoadsWhileRouting = Settings.shouldAvoidUnpavedRoadsWhileRouting
shouldAvoidFerriesWhileRouting = Settings.shouldAvoidFerriesWhileRouting
shouldAvoidMotorwaysWhileRouting = Settings.shouldAvoidMotorwaysWhileRouting
hasLiveTraffic = Settings.hasLiveTraffic
liveTrafficServerUrlString = Settings.liveTrafficServerUrl?.absoluteString ?? ""
}
.onChange(of: hasPerspectiveViewWhileRouting) { changedHasPerspectiveViewWhileRouting in
Settings.hasPerspectiveViewWhileRouting = changedHasPerspectiveViewWhileRouting
@@ -174,5 +202,15 @@ struct SettingsNavigationView: View {
.onChange(of: shouldAvoidMotorwaysWhileRouting) { changedShouldAvoidMotorwaysWhileRouting in
Settings.shouldAvoidMotorwaysWhileRouting = changedShouldAvoidMotorwaysWhileRouting
}
.onChange(of: hasLiveTraffic) { changedHasLiveTraffic in
Settings.hasLiveTraffic = changedHasLiveTraffic
}
.onChange(of: liveTrafficServerUrlString) { changedLiveTrafficServerUrlString in
if !changedLiveTrafficServerUrlString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty, let changedLiveTrafficServerUrl = URL(string: changedLiveTrafficServerUrlString.trimmingCharacters(in: .whitespacesAndNewlines)) {
Settings.liveTrafficServerUrl = changedLiveTrafficServerUrl
} else {
Settings.liveTrafficServerUrl = nil
}
}
}
}