mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-04 20:03:45 +00:00
[traffic][ios] Make HttpTraffSource configurable in Preferences
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
NS_SWIFT_NAME(SettingsBridge)
|
||||
@interface MWMSettings : NSObject
|
||||
|
||||
+ (BOOL)liveTrafficEnabled;
|
||||
+ (void)setLiveTrafficEnabled:(BOOL)liveTrafficEnabled;
|
||||
|
||||
+ (NSURL *)liveTrafficUrl;
|
||||
+ (void)setLiveTrafficUrl:(NSURL *)liveTrafficUrl;
|
||||
|
||||
+ (BOOL)buildings3dViewEnabled;
|
||||
+ (void)setBuildings3dViewEnabled:(BOOL)buildings3dViewEnabled;
|
||||
|
||||
|
||||
@@ -26,6 +26,40 @@ NSString * const kUDFileLoggingEnabledKey = @"FileLoggingEnabledKey";
|
||||
|
||||
@implementation MWMSettings
|
||||
|
||||
+ (BOOL)liveTrafficEnabled;
|
||||
{
|
||||
return GetFramework().LoadTrafficHttpEnabled();
|
||||
}
|
||||
|
||||
+ (void)setLiveTrafficEnabled:(BOOL)liveTrafficEnabled;
|
||||
{
|
||||
auto &f = GetFramework();
|
||||
f.SaveTrafficHttpEnabled(liveTrafficEnabled);
|
||||
f.SetTrafficHttpEnabled(liveTrafficEnabled);
|
||||
}
|
||||
|
||||
+ (NSURL *)liveTrafficUrl;
|
||||
{
|
||||
NSString * link = @(GetFramework().LoadTrafficHttpUrl().c_str());
|
||||
if ([link length] == 0) {
|
||||
return nil;
|
||||
} else {
|
||||
return [NSURL URLWithString:link];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)setLiveTrafficUrl:(NSURL *)liveTrafficUrl;
|
||||
{
|
||||
auto &f = GetFramework();
|
||||
if (liveTrafficUrl == nil) {
|
||||
f.SaveTrafficHttpUrl(@"".UTF8String);
|
||||
f.SetTrafficHttpUrl(@"".UTF8String);
|
||||
} else {
|
||||
f.SaveTrafficHttpUrl(liveTrafficUrl.absoluteString.UTF8String);
|
||||
f.SetTrafficHttpUrl(liveTrafficUrl.absoluteString.UTF8String);
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)buildings3dViewEnabled;
|
||||
{
|
||||
bool _ = true, on = true;
|
||||
|
||||
@@ -696,6 +696,13 @@
|
||||
"editor_place_doesnt_exist" = "Place does not exist";
|
||||
"text_more_button" = "…more";
|
||||
|
||||
/* Live traffic data */
|
||||
"traffic_http" = "Live Traffic";
|
||||
"traffic_http_enabled" = "Enable live traffic data";
|
||||
"traffic_http_enabled_description" = "When enabled, the app will periodically retrieve traffic information from the configured URL.";
|
||||
"traffic_http_url" = "Traffic service URL";
|
||||
"traffic_http_url_not_set" = "Not set";
|
||||
|
||||
/* Phone number error message */
|
||||
"error_enter_correct_phone" = "Enter a valid phone number";
|
||||
"error_enter_correct_web" = "Enter a valid web address";
|
||||
|
||||
@@ -714,6 +714,13 @@
|
||||
"editor_place_doesnt_exist" = "Place does not exist";
|
||||
"text_more_button" = "…more";
|
||||
|
||||
/* Live traffic data */
|
||||
"traffic_http" = "Live Traffic";
|
||||
"traffic_http_enabled" = "Enable live traffic data";
|
||||
"traffic_http_enabled_description" = "When enabled, the app will periodically retrieve traffic information from the configured URL.";
|
||||
"traffic_http_url" = "Traffic service URL";
|
||||
"traffic_http_url_not_set" = "Not set";
|
||||
|
||||
/* Phone number error message */
|
||||
"error_enter_correct_phone" = "Enter a valid phone number";
|
||||
"error_enter_correct_web" = "Enter a valid web address";
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
272F1F3B2E0EE0A300FA52EF /* NoExistingProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1F3A2E0EE09500FA52EF /* NoExistingProfileView.swift */; };
|
||||
272F1F3D2E0EE0C800FA52EF /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1F3C2E0EE0C400FA52EF /* ProfileView.swift */; };
|
||||
272F1F462E0EEF9400FA52EF /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1F452E0EEF8B00FA52EF /* SafariView.swift */; };
|
||||
2747205A2E439FBA00C516DF /* libtraffxml.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 274720592E439FBA00C516DF /* libtraffxml.a */; };
|
||||
2765D1D02E13F9C20005CA2B /* BridgeControllers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2765D1CD2E13F9BC0005CA2B /* BridgeControllers.swift */; };
|
||||
27697F742E25177600FBD913 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27697F732E25177300FBD913 /* AboutView.swift */; };
|
||||
27697F7F2E254A5500FBD913 /* CopyrightView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27697F7C2E254A5000FBD913 /* CopyrightView.swift */; };
|
||||
@@ -774,6 +775,7 @@
|
||||
272F1F3A2E0EE09500FA52EF /* NoExistingProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoExistingProfileView.swift; sourceTree = "<group>"; };
|
||||
272F1F3C2E0EE0C400FA52EF /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; };
|
||||
272F1F452E0EEF8B00FA52EF /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = "<group>"; };
|
||||
274720592E439FBA00C516DF /* libtraffxml.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libtraffxml.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2765D1CD2E13F9BC0005CA2B /* BridgeControllers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BridgeControllers.swift; sourceTree = "<group>"; };
|
||||
27697F732E25177300FBD913 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
|
||||
27697F7C2E254A5000FBD913 /* CopyrightView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopyrightView.swift; sourceTree = "<group>"; };
|
||||
@@ -1813,6 +1815,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2747205A2E439FBA00C516DF /* libtraffxml.a in Frameworks */,
|
||||
FAF9DDA32A86DC54000D7037 /* libharfbuzz.a in Frameworks */,
|
||||
FA456C3C26BDC6AD00B83C20 /* Chart.framework in Frameworks */,
|
||||
FA853BF326BC5DE50026D455 /* libshaders.a in Frameworks */,
|
||||
@@ -2046,6 +2049,7 @@
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
274720592E439FBA00C516DF /* libtraffxml.a */,
|
||||
FAF9DDA22A86DC54000D7037 /* libharfbuzz.a */,
|
||||
FA456C3B26BDC6AD00B83C20 /* Chart.framework */,
|
||||
FA853BF226BC5DE50026D455 /* libshaders.a */,
|
||||
|
||||
@@ -373,6 +373,28 @@ import Combine
|
||||
}
|
||||
|
||||
|
||||
/// If live traffic data should be used
|
||||
@objc static var hasLiveTraffic: Bool {
|
||||
get {
|
||||
return SettingsBridge.liveTrafficEnabled()
|
||||
}
|
||||
set {
|
||||
SettingsBridge.setLiveTrafficEnabled(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// The url of the live traffic data server
|
||||
@objc static var liveTrafficServerUrl: URL? {
|
||||
get {
|
||||
return SettingsBridge.liveTrafficUrl()
|
||||
}
|
||||
set {
|
||||
SettingsBridge.setLiveTrafficUrl(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user