From cb409728aadd9af04f3400c1c4eb10a0a97bbd40 Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Fri, 24 Jul 2020 20:50:43 +0530 Subject: [PATCH] Add subscriptions import/export navigation link with list - refactors export/import action sheet to be a new screen with list options --- .../iOS/Settings/FeedsSettingsModel.swift | 23 +---- .../iOS/Settings/SettingsModel.swift | 9 ++ Multiplatform/iOS/Settings/SettingsView.swift | 84 +++++++++++-------- 3 files changed, 63 insertions(+), 53 deletions(-) diff --git a/Multiplatform/iOS/Settings/FeedsSettingsModel.swift b/Multiplatform/iOS/Settings/FeedsSettingsModel.swift index 40746557c..72f9545ba 100644 --- a/Multiplatform/iOS/Settings/FeedsSettingsModel.swift +++ b/Multiplatform/iOS/Settings/FeedsSettingsModel.swift @@ -44,8 +44,6 @@ enum FeedsSettingsError: LocalizedError, Equatable { } class FeedsSettingsModel: ObservableObject { - @Published var showingImportActionSheet = false - @Published var showingExportActionSheet = false @Published var exportingFilePath = "" @Published var feedsSettingsError: FeedsSettingsError? { didSet { @@ -54,25 +52,12 @@ class FeedsSettingsModel: ObservableObject { } @Published var showError: Bool = false - func onTapExportOPML(action: ((Account?) -> Void)) { - if AccountManager.shared.accounts.count == 1 { - action(AccountManager.shared.accounts.first) - } - else { - showingExportActionSheet = true - } - } - - func onTapImportOPML(action: ((Account?) -> Void)) { - switch AccountManager.shared.activeAccounts.count { - case 0: + func checkForActiveAccount() -> Bool { + if AccountManager.shared.activeAccounts.count == 0 { feedsSettingsError = .noActiveAccount - return - case 1: - action(AccountManager.shared.activeAccounts.first) - default: - showingImportActionSheet = true + return false } + return true } func generateExportURL(for account: Account) -> URL? { diff --git a/Multiplatform/iOS/Settings/SettingsModel.swift b/Multiplatform/iOS/Settings/SettingsModel.swift index a8229118d..792a91807 100644 --- a/Multiplatform/iOS/Settings/SettingsModel.swift +++ b/Multiplatform/iOS/Settings/SettingsModel.swift @@ -46,6 +46,15 @@ class SettingsModel: ObservableObject { } } + var activeAccounts: [Account] { + get { + AccountManager.shared.sortedActiveAccounts + } + set { + + } + } + // MARK: Init init() { diff --git a/Multiplatform/iOS/Settings/SettingsView.swift b/Multiplatform/iOS/Settings/SettingsView.swift index 1c1ee1fa3..ad4dbad45 100644 --- a/Multiplatform/iOS/Settings/SettingsView.swift +++ b/Multiplatform/iOS/Settings/SettingsView.swift @@ -75,19 +75,30 @@ struct SettingsView: View { var importExport: some View { Section(header: Text("Feeds"), content: { - Button(action:{ - feedsSettingsModel.onTapImportOPML(action: importOPML) - }) { - Text("Import Subscriptions") - .actionSheet(isPresented: $feedsSettingsModel.showingImportActionSheet, content: importActionSheet) - .foregroundColor(.primary) + if viewModel.activeAccounts.count > 1 { + NavigationLink("Import Subscriptions", destination: importOptions) } - Button(action:{ - feedsSettingsModel.onTapExportOPML(action: exportOPML) - }) { - Text("Export Subscriptions") - .actionSheet(isPresented: $feedsSettingsModel.showingExportActionSheet, content: exportActionSheet) - .foregroundColor(.primary) + else { + Button(action:{ + if feedsSettingsModel.checkForActiveAccount() { + importOPML(account: viewModel.activeAccounts.first) + } + }) { + Text("Import Subscriptions") + .foregroundColor(.primary) + } + } + + if viewModel.accounts.count > 1 { + NavigationLink("Export Subscriptions", destination: exportOptions) + } + else { + Button(action:{ + exportOPML(account: viewModel.accounts.first) + }) { + Text("Export Subscriptions") + .foregroundColor(.primary) + } } }) .alert(isPresented: $feedsSettingsModel.showError) { @@ -98,35 +109,40 @@ struct SettingsView: View { feedsSettingsModel.feedsSettingsError = FeedsSettingsError.none })) } - } - private func importActionSheet() -> ActionSheet { - var buttons = viewModel.accounts.map { (account) -> ActionSheet.Button in - ActionSheet.Button.default(Text(account.nameForDisplay)) { - importOPML(account: account) - } + var importOptions: some View { + List { + Section(header: Text("Choose an account to receive the imported feeds and folders"), content: { + ForEach(0.. ActionSheet { - var buttons = viewModel.accounts.map { (account) -> ActionSheet.Button in - ActionSheet.Button.default(Text(account.nameForDisplay)) { - exportOPML(account: account) - } + var exportOptions: some View { + List { + Section(header: Text("Choose an account with the subscriptions to export"), content: { + ForEach(0..