Rewrite OPML import/export to avoid ActionSheet

This commit is contained in:
Maurice Parker
2019-10-20 07:47:22 -05:00
parent c18f5f7537
commit 329d5ccfeb
4 changed files with 90 additions and 58 deletions

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)