From 095c811572e9d19c5d861eb73e4269ea67892202 Mon Sep 17 00:00:00 2001 From: Lumaa Date: Fri, 26 Jan 2024 14:38:43 +0100 Subject: [PATCH] Browser setting in "Appearence" --- Threaded/Localizable.xcstrings | 30 +++++++++++ Threaded/Views/Settings/AppearenceView.swift | 57 +++++++++++--------- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/Threaded/Localizable.xcstrings b/Threaded/Localizable.xcstrings index 8536523..8a38b8b 100644 --- a/Threaded/Localizable.xcstrings +++ b/Threaded/Localizable.xcstrings @@ -277,6 +277,36 @@ } } }, + "setting.appearence.browser" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Open links" + } + } + } + }, + "setting.appearence.browser.in-app" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "in-app" + } + } + } + }, + "setting.appearence.browser.out-app" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "in a browser" + } + } + } + }, "setting.appearence.displayed-name" : { "localizations" : { "en" : { diff --git a/Threaded/Views/Settings/AppearenceView.swift b/Threaded/Views/Settings/AppearenceView.swift index 5cae12c..d0e3a57 100644 --- a/Threaded/Views/Settings/AppearenceView.swift +++ b/Threaded/Views/Settings/AppearenceView.swift @@ -42,6 +42,21 @@ struct AppearenceView: View { .pickerStyle(.inline) .listRowThreaded() + Picker(LocalizedStringKey("setting.appearence.browser"), selection: $userPreferences.browserType) { + ForEach(UserPreferences.BrowserType.allCases, id: \.self) { type in + switch (type) { + case .inApp: + Text("setting.appearence.browser.in-app") + .tag(UserPreferences.BrowserType.inApp) + case .outApp: + Text("setting.appearence.browser.out-app") + .tag(UserPreferences.BrowserType.outApp) + } + } + } + .pickerStyle(.inline) + .listRowThreaded() + if userPreferences.showExperimental { Section(header: Text("experimental")) { Toggle(LocalizedStringKey("setting.appearence.reply-symbols"), isOn: $userPreferences.experimental.replySymbol) @@ -54,34 +69,13 @@ struct AppearenceView: View { .navigationBarTitleDisplayMode(.inline) .navigationBarBackButtonHidden() .onAppear { - do { - let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences - - userPreferences.displayedName = oldPreferences.displayedName - userPreferences.profilePictureShape = oldPreferences.profilePictureShape - - userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol - } catch { - print(error) - dismiss() - } + loadOld() } .toolbar { ToolbarItem(placement: .cancellationAction) { Button { - do { - let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences - - userPreferences.displayedName = oldPreferences.displayedName - userPreferences.profilePictureShape = oldPreferences.profilePictureShape - - userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol - - dismiss() - } catch { - print(error) - dismiss() - } + loadOld() + dismiss() } label: { Text("settings.cancel") } @@ -101,6 +95,21 @@ struct AppearenceView: View { } } } + + private func loadOld() { + do { + let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences + + userPreferences.displayedName = oldPreferences.displayedName + userPreferences.profilePictureShape = oldPreferences.profilePictureShape + userPreferences.browserType = oldPreferences.browserType + + userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol + } catch { + print(error) + dismiss() + } + } } #Preview {