[ios] Adding setting to change map appearance

Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
Yannik Bloscheck
2025-07-21 13:26:50 +02:00
committed by Yannik Bloscheck
parent e7cdaba817
commit 110648fb89
5 changed files with 62 additions and 6 deletions

View File

@@ -53,8 +53,21 @@ final class ThemeManager: NSObject {
} }
}(actualTheme) }(actualTheme)
if Settings.mapAppearance == .light {
if actualTheme == .vehicleDay || actualTheme == .vehicleNight {
FrameworkHelper.setTheme(.vehicleDay)
} else {
FrameworkHelper.setTheme(.day)
}
} else if Settings.mapAppearance == .dark {
if actualTheme == .vehicleDay || actualTheme == .vehicleNight {
FrameworkHelper.setTheme(.vehicleNight)
} else {
FrameworkHelper.setTheme(.night)
}
} else {
FrameworkHelper.setTheme(actualTheme) FrameworkHelper.setTheme(actualTheme)
}
if nightMode != newNightMode || StyleManager.shared.hasTheme() == false{ if nightMode != newNightMode || StyleManager.shared.hasTheme() == false{
UIColor.setNightMode(newNightMode) UIColor.setNightMode(newNightMode)
if newNightMode { if newNightMode {

View File

@@ -209,6 +209,9 @@
"pref_zoom_title" = "Zoom buttons"; "pref_zoom_title" = "Zoom buttons";
"pref_left_button_type" = "Left Main Button"; "pref_left_button_type" = "Left Main Button";
/* Settings «Map» category: «Map Appearance» title */
"pref_mapappearance_title" = "Map Appearance";
/* Settings «Map» category: «Appearance» title */ /* Settings «Map» category: «Appearance» title */
"pref_appearance_title" = "Appearance"; "pref_appearance_title" = "Appearance";

View File

@@ -219,6 +219,9 @@
"pref_zoom_title" = "Zoom buttons"; "pref_zoom_title" = "Zoom buttons";
"pref_left_button_type" = "Left Main Button"; "pref_left_button_type" = "Left Main Button";
/* Settings «Map» category: «Map Appearance» title */
"pref_mapappearance_title" = "Map Appearance";
/* Settings «Map» category: «Appearance» title */ /* Settings «Map» category: «Appearance» title */
"pref_appearance_title" = "Appearance"; "pref_appearance_title" = "Appearance";

View File

@@ -12,6 +12,10 @@ import Combine
static private let userDefaultsKeyLeftButtonType = "LeftButtonType" static private let userDefaultsKeyLeftButtonType = "LeftButtonType"
/// Key for storing the map appearance in the user defaults
static private let userDefaultsKeyMapAppearance = "MapAppearance"
/// The current distance unit /// The current distance unit
static var distanceUnit: DistanceUnit { static var distanceUnit: DistanceUnit {
get { get {
@@ -147,6 +151,23 @@ import Combine
} }
/// The current map appearance
@objc static var mapAppearance: Appearance {
get {
let mapAppearanceRawValue = UserDefaults.standard.integer(forKey: userDefaultsKeyMapAppearance)
if mapAppearanceRawValue != 0, let mapAppearance = Appearance(rawValue: mapAppearanceRawValue) {
return mapAppearance
}
return .auto
}
set {
UserDefaults.standard.set(newValue.rawValue, forKey: userDefaultsKeyMapAppearance)
ThemeManager.invalidate()
}
}
/// The current appearance /// The current appearance
@objc static var appearance: Appearance { @objc static var appearance: Appearance {
get { get {

View File

@@ -36,6 +36,10 @@ struct SettingsView: View {
@State private var shouldTransliterateToLatin: Bool = true @State private var shouldTransliterateToLatin: Bool = true
/// The selected map appearance
@State private var selectedMapAppearance: Settings.Appearance = .auto
/// The selected appearance /// The selected appearance
@State private var selectedAppearance: Settings.Appearance = .auto @State private var selectedAppearance: Settings.Appearance = .auto
@@ -135,12 +139,12 @@ struct SettingsView: View {
Toggle("transliteration_title", isOn: $shouldTransliterateToLatin) Toggle("transliteration_title", isOn: $shouldTransliterateToLatin)
.tint(.accent) .tint(.accent)
Picker(selection: $selectedAppearance) { Picker(selection: $selectedMapAppearance) {
ForEach(Settings.Appearance.allCases) { appearance in ForEach(Settings.Appearance.allCases) { mapAppearance in
Text(appearance.description) Text(mapAppearance.description)
} }
} label: { } label: {
Text("pref_appearance_title") Text("pref_mapappearance_title")
} }
} }
@@ -198,6 +202,14 @@ struct SettingsView: View {
} }
Section { Section {
Picker(selection: $selectedAppearance) {
ForEach(Settings.Appearance.allCases) { appearance in
Text(appearance.description)
}
} label: {
Text("pref_appearance_title")
}
Toggle("pref_calibration_title", isOn: $shouldCalibrateCompass) Toggle("pref_calibration_title", isOn: $shouldCalibrateCompass)
.tint(.accent) .tint(.accent)
@@ -256,6 +268,7 @@ struct SettingsView: View {
hasAutomaticDownload = Settings.hasAutomaticDownload hasAutomaticDownload = Settings.hasAutomaticDownload
hasIncreasedFontsize = Settings.hasIncreasedFontsize hasIncreasedFontsize = Settings.hasIncreasedFontsize
shouldTransliterateToLatin = Settings.shouldTransliterateToLatin shouldTransliterateToLatin = Settings.shouldTransliterateToLatin
selectedMapAppearance = Settings.mapAppearance
selectedAppearance = Settings.appearance selectedAppearance = Settings.appearance
shouldSync = Settings.shouldSync shouldSync = Settings.shouldSync
shouldCalibrateCompass = Settings.shouldCalibrateCompass shouldCalibrateCompass = Settings.shouldCalibrateCompass
@@ -284,6 +297,9 @@ struct SettingsView: View {
.onChange(of: shouldTransliterateToLatin) { changedShouldTransliterateToLatin in .onChange(of: shouldTransliterateToLatin) { changedShouldTransliterateToLatin in
Settings.shouldTransliterateToLatin = changedShouldTransliterateToLatin Settings.shouldTransliterateToLatin = changedShouldTransliterateToLatin
} }
.onChange(of: selectedMapAppearance) { changedSelectedMapAppearance in
Settings.mapAppearance = changedSelectedMapAppearance
}
.onChange(of: selectedAppearance) { changedSelectedAppearance in .onChange(of: selectedAppearance) { changedSelectedAppearance in
Settings.appearance = changedSelectedAppearance Settings.appearance = changedSelectedAppearance
} }