From ca8901bade34828e1b88494ac0a0ab93d9cb6de7 Mon Sep 17 00:00:00 2001 From: Arnfried Griesert Date: Wed, 8 Mar 2023 13:28:11 +0000 Subject: [PATCH] MESSENGER-3425 permalink prefix developer settings screen --- Config/BWIBuildSettings.swift | 4 + Riot/Assets/de.lproj/Bwi.strings | 3 + Riot/Assets/en.lproj/Bwi.strings | 3 + .../DeveloperSettingsView.swift | 94 +++++++++++-------- 4 files changed, 66 insertions(+), 38 deletions(-) diff --git a/Config/BWIBuildSettings.swift b/Config/BWIBuildSettings.swift index 187655b8c..c960c3978 100644 --- a/Config/BWIBuildSettings.swift +++ b/Config/BWIBuildSettings.swift @@ -567,6 +567,10 @@ class BWIBuildSettings: NSObject { // MARK: User Search var sortUserSearchResultsAlphabetically = true + // MARK: Permalinks + var permalinkPrefixSettings = false + var permalinkPrefixes: [String] = [] + // MARK: Client error search term var clientErrorSearchTerm = "Request failed: client error" } diff --git a/Riot/Assets/de.lproj/Bwi.strings b/Riot/Assets/de.lproj/Bwi.strings index d623e84ad..e3cc8c99b 100644 --- a/Riot/Assets/de.lproj/Bwi.strings +++ b/Riot/Assets/de.lproj/Bwi.strings @@ -585,6 +585,9 @@ // MARK: - Chat creation "room_creation_title" = "Neue Direktnachricht"; +// MARK: - Permalink +"settings_permalink_prefix_picker_title" = "Permalink Prefix"; + // MARK: - Notification Settings "settings_notify_me_for" = "Benachrichtige mich für"; "room_notifs_settings_encrypted_room_notice" = ""; diff --git a/Riot/Assets/en.lproj/Bwi.strings b/Riot/Assets/en.lproj/Bwi.strings index 70015e18b..5b73a50a6 100644 --- a/Riot/Assets/en.lproj/Bwi.strings +++ b/Riot/Assets/en.lproj/Bwi.strings @@ -465,6 +465,9 @@ // MARK: - Chat creation "room_creation_title" = "New chat"; +// MARK: - Permalink +"settings_permalink_prefix_picker_title" = "Permalink Prefix"; + // MARK: - Notification Settings "settings_notify_me_for" = "Notify me for"; "room_notifs_settings_encrypted_room_notice" = ""; diff --git a/bwi/DeveloperSettings/DeveloperSettingsView.swift b/bwi/DeveloperSettings/DeveloperSettingsView.swift index cb7827895..822ce4fe6 100644 --- a/bwi/DeveloperSettings/DeveloperSettingsView.swift +++ b/bwi/DeveloperSettings/DeveloperSettingsView.swift @@ -34,50 +34,68 @@ struct DeveloperSettingsView: View { @State private var showAlert = false @State private var showAlertBirthdayCampaign = false + @State private var permalinkPrefix: String? = UserDefaults.standard.string(forKey: "bwi_permalink_prefix") var body: some View { - List { - Button(action: { showAlert = createNewPersonalNotesRoom(mxSession: session) }) { - Text(BWIL10n.bwiSettingsDeveloperCreateNewPersonalNotesRoom) - .foregroundColor(Color(ThemeService.shared().theme.tintColor)) - .font(.system(size: 17)) - } - .alert(isPresented: $showAlert) { - Alert(title: Text(BWIL10n.bwiSettingsDeveloper), dismissButton: .default(Text("Ok"))) - } - - Button(action: { showAlert = resetMatomoInfoScreen() }) { - Text(BWIL10n.bwiSettingsDeveloperResetMatomoInfo) - .foregroundColor(Color(ThemeService.shared().theme.tintColor)) - .font(.system(size: 17)) - } - .alert(isPresented: $showAlert) { - Alert(title: Text(BWIL10n.bwiSettingsDeveloperShowMatomoPrivacyNotesResetted), message: Text(BWIL10n.bwiSettingsDeveloperShowMatomoPrivacyNotesResetted), dismissButton: .default(Text("Ok"))) - } - Button(action: { showAlertBirthdayCampaign = resetBirthdayCampaignScreen(mxSession: session) }) { - Text(BWIL10n.bwiSettingsDeveloperSettingsResetBirthdayBanner) - .foregroundColor(Color(ThemeService.shared().theme.tintColor)) - .font(.system(size: 17)) - } - .alert(isPresented: $showAlertBirthdayCampaign) { - Alert(title: Text(BWIL10n.bwiSettingsDeveloperSettingsBirthdayBannerResettetTitle), message: Text(BWIL10n.bwiSettingsDeveloperSettingsBirthdayBannerResettetMessage), dismissButton: .default(Text("Ok"))) - } - Button(action: { _ = restrictUser(mxSession: session) }) { - Text(BWIL10n.bwiSettingsDeveloperRestrictUser) - .foregroundColor(Color(ThemeService.shared().theme.tintColor)) - .font(.system(size: 17)) - } - Button(action: { _ = unrestrictUser(mxSession: session) }) { + Form { + SwiftUI.Section { + Button(action: { showAlert = createNewPersonalNotesRoom(mxSession: session) }) { + Text(BWIL10n.bwiSettingsDeveloperCreateNewPersonalNotesRoom) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } + .alert(isPresented: $showAlert) { + Alert(title: Text(BWIL10n.bwiSettingsDeveloper), dismissButton: .default(Text("Ok"))) + } + + Button(action: { showAlert = resetMatomoInfoScreen() }) { + Text(BWIL10n.bwiSettingsDeveloperResetMatomoInfo) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } + .alert(isPresented: $showAlert) { + Alert(title: Text(BWIL10n.bwiSettingsDeveloperShowMatomoPrivacyNotesResetted), message: Text(BWIL10n.bwiSettingsDeveloperShowMatomoPrivacyNotesResetted), dismissButton: .default(Text("Ok"))) + } + Button(action: { showAlertBirthdayCampaign = resetBirthdayCampaignScreen(mxSession: session) }) { + Text(BWIL10n.bwiSettingsDeveloperSettingsResetBirthdayBanner) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } + .alert(isPresented: $showAlertBirthdayCampaign) { + Alert(title: Text(BWIL10n.bwiSettingsDeveloperSettingsBirthdayBannerResettetTitle), message: Text(BWIL10n.bwiSettingsDeveloperSettingsBirthdayBannerResettetMessage), dismissButton: .default(Text("Ok"))) + } + Button(action: { _ = restrictUser(mxSession: session) }) { + Text(BWIL10n.bwiSettingsDeveloperRestrictUser) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } + Button(action: { _ = unrestrictUser(mxSession: session) }) { Text(BWIL10n.bwiSettingsDeveloperUnrestrictUser) - .foregroundColor(Color(ThemeService.shared().theme.tintColor)) - .font(.system(size: 17)) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } + Button(action: { _ = unmarkBannerVersion(mxSession: session) }) { + Text(BWIL10n.bwiSettingsDeveloperUnmarkBanner) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } } - Button(action: { _ = unmarkBannerVersion(mxSession: session) }) { - Text(BWIL10n.bwiSettingsDeveloperUnmarkBanner) - .foregroundColor(Color(ThemeService.shared().theme.tintColor)) - .font(.system(size: 17)) + if BWIBuildSettings.shared.permalinkPrefixSettings && !BWIBuildSettings.shared.permalinkPrefixes.isEmpty { + SwiftUI.Section(header: Text(BWIL10n.settingsPermalinkPrefixPickerTitle)) { + Picker("", selection: $permalinkPrefix) { + ForEach(BWIBuildSettings.shared.permalinkPrefixes, id: \.self) { prefix in + Text(prefix) + .tag(String?.some(prefix)) + } + } + .id(UUID()) + .onChange(of: permalinkPrefix) { newValue in + UserDefaults.standard.set(newValue, forKey: "bwi_permalink_prefix") + } + } } } + .listStyle(.grouped) .navigationTitle(BWIL10n.bwiSettingsDeveloper) .navigationBarTitleDisplayMode(.inline) }