From 329d5ccfeb4c828efa316ea5f933723424682598 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 20 Oct 2019 07:47:22 -0500 Subject: [PATCH] Rewrite OPML import/export to avoid ActionSheet --- NetNewsWire.xcodeproj/project.pbxproj | 8 +++ ...SubscriptionsExportAccountPickerView.swift | 34 +++++++++ ...SubscriptionsImportAccountPickerView.swift | 34 +++++++++ iOS/Settings/SettingsView.swift | 72 ++++--------------- 4 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 iOS/Settings/SettingsSubscriptionsExportAccountPickerView.swift create mode 100644 iOS/Settings/SettingsSubscriptionsImportAccountPickerView.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 788aad61c..736bfa8c6 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -43,6 +43,8 @@ 513146C5235A8FDB00387FDC /* SyncDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51554C01228B6EB50055115A /* SyncDatabase.framework */; }; 51314704235C41FC00387FDC /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 51314707235C41FC00387FDC /* Intents.intentdefinition */; }; 51314705235C41FC00387FDC /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 51314707235C41FC00387FDC /* Intents.intentdefinition */; }; + 51314716235C862200387FDC /* SettingsSubscriptionsImportAccountPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51314715235C862200387FDC /* SettingsSubscriptionsImportAccountPickerView.swift */; }; + 51314718235C89ED00387FDC /* SettingsSubscriptionsExportAccountPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51314717235C89ED00387FDC /* SettingsSubscriptionsExportAccountPickerView.swift */; }; 51322855232EED360033D4ED /* VibrantSelectAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51322854232EED360033D4ED /* VibrantSelectAction.swift */; }; 51322859232FDDB80033D4ED /* VibrantButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51322858232FDDB80033D4ED /* VibrantButtonStyle.swift */; }; 5132285B232FF2C40033D4ED /* SettingsRefreshSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5132285A232FF2C40033D4ED /* SettingsRefreshSelectionView.swift */; }; @@ -752,6 +754,8 @@ 513146B1235A81A400387FDC /* AddFeedIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeedIntentHandler.swift; sourceTree = ""; }; 51314706235C41FC00387FDC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = Base; path = Base.lproj/Intents.intentdefinition; sourceTree = ""; }; 51314714235C420900387FDC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Intents.strings; sourceTree = ""; }; + 51314715235C862200387FDC /* SettingsSubscriptionsImportAccountPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSubscriptionsImportAccountPickerView.swift; sourceTree = ""; }; + 51314717235C89ED00387FDC /* SettingsSubscriptionsExportAccountPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSubscriptionsExportAccountPickerView.swift; sourceTree = ""; }; 51322854232EED360033D4ED /* VibrantSelectAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VibrantSelectAction.swift; sourceTree = ""; }; 51322858232FDDB80033D4ED /* VibrantButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VibrantButtonStyle.swift; sourceTree = ""; }; 5132285A232FF2C40033D4ED /* SettingsRefreshSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRefreshSelectionView.swift; sourceTree = ""; }; @@ -1300,7 +1304,9 @@ 5132293A23305D4C0033D4ED /* SettingsAboutView.swift */, 513229302330523F0033D4ED /* SettingsAttributedStringView.swift */, 5132285A232FF2C40033D4ED /* SettingsRefreshSelectionView.swift */, + 51314717235C89ED00387FDC /* SettingsSubscriptionsExportAccountPickerView.swift */, 5194B5F122B69FCC00144881 /* SettingsSubscriptionsExportDocumentPickerView.swift */, + 51314715235C862200387FDC /* SettingsSubscriptionsImportAccountPickerView.swift */, 5194B5ED22B6965300144881 /* SettingsSubscriptionsImportDocumentPickerView.swift */, 515E4F06232506240057B0E7 /* Account */, ); @@ -2995,6 +3001,7 @@ 51C452AC22650FD200C03939 /* AppNotifications.swift in Sources */, 51EF0F7E2277A57D0050506E /* MasterTimelineAccessibilityCellLayout.swift in Sources */, 51C452762265091600C03939 /* MasterTimelineViewController.swift in Sources */, + 51314718235C89ED00387FDC /* SettingsSubscriptionsExportAccountPickerView.swift in Sources */, 5183CCE9226F68D90010922C /* AccountRefreshTimer.swift in Sources */, 51C452882265093600C03939 /* AddFeedViewController.swift in Sources */, 51934CCE2310792F006127BE /* ActivityManager.swift in Sources */, @@ -3024,6 +3031,7 @@ 513229312330523F0033D4ED /* SettingsAttributedStringView.swift in Sources */, 51D6A5BC23199C85001C27D8 /* MasterTimelineDataSource.swift in Sources */, 51934CCB230F599B006127BE /* ThemedNavigationController.swift in Sources */, + 51314716235C862200387FDC /* SettingsSubscriptionsImportAccountPickerView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/iOS/Settings/SettingsSubscriptionsExportAccountPickerView.swift b/iOS/Settings/SettingsSubscriptionsExportAccountPickerView.swift new file mode 100644 index 000000000..33bc3ea40 --- /dev/null +++ b/iOS/Settings/SettingsSubscriptionsExportAccountPickerView.swift @@ -0,0 +1,34 @@ +// +// SettingsSubscriptionsExportAccountPickerView.swift +// NetNewsWire-iOS +// +// Created by Maurice Parker on 10/20/19. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import SwiftUI +import Account + +struct SettingsSubscriptionsExportAccountPickerView: View { + + @Environment(\.presentationMode) var presentation + @State private var selectedAccount: Account? + @State private var isOPMLExportDocPickerPresented: Bool = false + + var body: some View { + Form { + ForEach(AccountManager.shared.sortedAccounts) { account in + Button(action: { + self.selectedAccount = account + self.isOPMLExportDocPickerPresented = true + }) { + Text(verbatim: account.nameForDisplay) + }.buttonStyle(VibrantButtonStyle(alignment: .leading)) + } + }.sheet(isPresented: $isOPMLExportDocPickerPresented, onDismiss: { self.presentation.wrappedValue.dismiss() }) { + SettingsSubscriptionsExportDocumentPickerView(account: self.selectedAccount!) + } + .navigationBarTitle(Text("Select Account"), displayMode: .inline) + } + +} diff --git a/iOS/Settings/SettingsSubscriptionsImportAccountPickerView.swift b/iOS/Settings/SettingsSubscriptionsImportAccountPickerView.swift new file mode 100644 index 000000000..0ce3fbdc6 --- /dev/null +++ b/iOS/Settings/SettingsSubscriptionsImportAccountPickerView.swift @@ -0,0 +1,34 @@ +// +// SettingsSubscriptionsImportAccountPickerView.swift +// NetNewsWire-iOS +// +// Created by Maurice Parker on 10/20/19. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import SwiftUI +import Account + +struct SettingsSubscriptionsImportAccountPickerView: View { + + @Environment(\.presentationMode) var presentation + @State private var selectedAccount: Account? + @State private var isOPMLImportDocPickerPresented: Bool = false + + var body: some View { + Form { + ForEach(AccountManager.shared.sortedActiveAccounts) { account in + Button(action: { + self.selectedAccount = account + self.isOPMLImportDocPickerPresented = true + }) { + Text(verbatim: account.nameForDisplay) + }.buttonStyle(VibrantButtonStyle(alignment: .leading)) + } + }.sheet(isPresented: $isOPMLImportDocPickerPresented, onDismiss: { self.presentation.wrappedValue.dismiss() }) { + SettingsSubscriptionsImportDocumentPickerView(account: self.selectedAccount!) + } + .navigationBarTitle(Text("Select Account"), displayMode: .inline) + } + +} diff --git a/iOS/Settings/SettingsView.swift b/iOS/Settings/SettingsView.swift index c853d60c4..40b6929f0 100644 --- a/iOS/Settings/SettingsView.swift +++ b/iOS/Settings/SettingsView.swift @@ -19,6 +19,8 @@ struct SettingsView : View { @State private var accountAction: Int? = nil @State private var refreshAction: Int? = nil + @State private var importOPMLAction: Int? = nil + @State private var exportOPMLAction: Int? = nil @State private var aboutAction: Int? = nil @State private var isWebsitePresented: Bool = false @@ -91,31 +93,20 @@ struct SettingsView : View { self.refreshAction = 1 })) - Button("Import Subscriptions...") { - if AccountManager.shared.activeAccounts.count == 1 { - self.opmlAccount = AccountManager.shared.activeAccounts.first - self.isOPMLImportDocPickerPresented = true - } else { - self.isOPMLImportPresented = true - } - }.actionSheet(isPresented: $isOPMLImportPresented) { - buildSubscriptionsImportAccounts() - }.sheet(isPresented: $isOPMLImportDocPickerPresented) { - SettingsSubscriptionsImportDocumentPickerView(account: self.opmlAccount!) + NavigationLink(destination: SettingsSubscriptionsImportAccountPickerView(), tag: 1, selection: $importOPMLAction) { + Text("Import Subscriptions") } + .modifier(VibrantSelectAction(action: { + self.importOPMLAction = 1 + })) + + NavigationLink(destination: SettingsSubscriptionsExportAccountPickerView(), tag: 1, selection: $exportOPMLAction) { + Text("Export Subscriptions") + } + .modifier(VibrantSelectAction(action: { + self.exportOPMLAction = 1 + })) - Button("Export Subscriptions...") { - if AccountManager.shared.accounts.count == 1 { - self.opmlAccount = AccountManager.shared.accounts.first - self.isOPMLImportDocPickerPresented = true - } else { - self.isOPMLExportPresented = true - } - }.actionSheet(isPresented: $isOPMLExportPresented) { - buildSubscriptionsExportAccounts() - }.sheet(isPresented: $isOPMLExportDocPickerPresented) { - SettingsSubscriptionsExportDocumentPickerView(account: self.opmlAccount!) - } } } @@ -180,41 +171,6 @@ struct SettingsView : View { } } - func buildSubscriptionsImportAccounts() -> ActionSheet { - var buttons = [ActionSheet.Button]() - - for account in viewModel.activeAccounts { - if account.behaviors.contains(.disallowOPMLImports) { - continue - } - - let button = ActionSheet.Button.default(Text(verbatim: account.nameForDisplay)) { - self.opmlAccount = account - self.isOPMLImportDocPickerPresented = true - } - - buttons.append(button) - } - - buttons.append(.cancel()) - return ActionSheet(title: Text("Import Subscriptions..."), message: Text("Select the account to import your OPML file into."), buttons: buttons) - } - - func buildSubscriptionsExportAccounts() -> ActionSheet { - var buttons = [ActionSheet.Button]() - - for account in viewModel.accounts { - let button = ActionSheet.Button.default(Text(verbatim: account.nameForDisplay)) { - self.opmlAccount = account - self.isOPMLExportDocPickerPresented = true - } - buttons.append(button) - } - - buttons.append(.cancel()) - return ActionSheet(title: Text("Export Subscriptions..."), message: Text("Select the account to export out of."), buttons: buttons) - } - func buildFooter() -> some View { return Text(verbatim: "\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))") .font(.footnote)