mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Remove Multiplatform targets
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// AddAccountSignUp.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 06/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
#if os(iOS)
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
|
||||
/// Helper functions common to most account services.
|
||||
protocol AddAccountSignUp {
|
||||
func presentSignUpOption(_ accountType: AccountType)
|
||||
}
|
||||
|
||||
|
||||
extension AddAccountSignUp {
|
||||
func presentSignUpOption(_ accountType: AccountType) {
|
||||
#if os(macOS)
|
||||
switch accountType {
|
||||
case .bazQux:
|
||||
NSWorkspace.shared.open(URL(string: "https://bazqux.com")!)
|
||||
case .feedbin:
|
||||
NSWorkspace.shared.open(URL(string: "https://feedbin.com/signup")!)
|
||||
case .feedly:
|
||||
NSWorkspace.shared.open(URL(string: "https://feedly.com")!)
|
||||
case .feedWrangler:
|
||||
NSWorkspace.shared.open(URL(string: "https://feedwrangler.net/users/new")!)
|
||||
case .freshRSS:
|
||||
NSWorkspace.shared.open(URL(string: "https://freshrss.org")!)
|
||||
case .inoreader:
|
||||
NSWorkspace.shared.open(URL(string: "https://www.inoreader.com")!)
|
||||
case .newsBlur:
|
||||
NSWorkspace.shared.open(URL(string: "https://newsblur.com")!)
|
||||
case .theOldReader:
|
||||
NSWorkspace.shared.open(URL(string: "https://theoldreader.com")!)
|
||||
default:
|
||||
return
|
||||
}
|
||||
#else
|
||||
switch accountType {
|
||||
case .bazQux:
|
||||
UIApplication.shared.open(URL(string: "https://bazqux.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .feedbin:
|
||||
UIApplication.shared.open(URL(string: "https://feedbin.com/signup")!, options: [:], completionHandler: nil)
|
||||
case .feedly:
|
||||
UIApplication.shared.open(URL(string: "https://feedly.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .feedWrangler:
|
||||
UIApplication.shared.open(URL(string: "https://feedwrangler.net/users/new")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .freshRSS:
|
||||
UIApplication.shared.open(URL(string: "https://freshrss.org")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .inoreader:
|
||||
UIApplication.shared.open(URL(string: "https://www.inoreader.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .newsBlur:
|
||||
UIApplication.shared.open(URL(string: "https://newsblur.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .theOldReader:
|
||||
UIApplication.shared.open(URL(string: "https://theoldreader.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
default:
|
||||
return
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// AddFeedWranglerViewModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedWranglerViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateFeedWrangler() {
|
||||
|
||||
isAuthenticating = true
|
||||
let credentials = Credentials(type: .feedWranglerBasic, username: username, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .feedWrangler, credentials: credentials) { result in
|
||||
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .feedWrangler)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .feedWranglerBasic)
|
||||
try account.removeCredentials(type: .feedWranglerToken)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// AddFeedbinViewModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedbinViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateFeedbin() {
|
||||
isAuthenticating = true
|
||||
let credentials = Credentials(type: .basic, username: username, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .feedbin, credentials: credentials) { result in
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .feedbin)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .basic)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.isAuthenticating = false
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// AddFeedlyViewModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedlyViewModel: ObservableObject, OAuthAccountAuthorizationOperationDelegate, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
|
||||
func authenticateFeedly() {
|
||||
isAuthenticating = true
|
||||
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
|
||||
addAccount.delegate = self
|
||||
#if os(macOS)
|
||||
addAccount.presentationAnchor = NSApplication.shared.windows.last
|
||||
#else
|
||||
addAccount.presentationAnchor = UIApplication.shared.windows.last
|
||||
#endif
|
||||
MainThreadOperationQueue.shared.add(addAccount)
|
||||
}
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didCreate account: Account) {
|
||||
|
||||
isAuthenticating = false
|
||||
|
||||
// macOS only: `ASWebAuthenticationSession` leaves the browser in the foreground.
|
||||
// Ensure the app is in the foreground so the user can see their Feedly account load.
|
||||
#if os(macOS)
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
#endif
|
||||
|
||||
account.refreshAll { [weak self] result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self?.accountUpdateError = .other(error: error)
|
||||
self?.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error) {
|
||||
isAuthenticating = false
|
||||
|
||||
// macOS only: `ASWebAuthenticationSession` leaves the browser in the foreground.
|
||||
// Ensure the app is in the foreground so the user can see the error.
|
||||
#if os(macOS)
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
#endif
|
||||
|
||||
accountUpdateError = .other(error: error)
|
||||
showError = true
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// AddNewsBlurViewModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddNewsBlurViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateNewsBlur() {
|
||||
isAuthenticating = true
|
||||
let credentials = Credentials(type: .newsBlurBasic, username: username, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .newsBlur, credentials: credentials) { result in
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .newsBlur)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .newsBlurBasic)
|
||||
try account.removeCredentials(type: .newsBlurSessionId)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
//
|
||||
// AddReaderAPIViewModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddReaderAPIViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var apiUrl: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateReaderAccount(_ accountType: AccountType) {
|
||||
isAuthenticating = true
|
||||
|
||||
let credentials = Credentials(type: .readerBasic, username: username, secret: password)
|
||||
|
||||
if accountType == .freshRSS {
|
||||
Account.validateCredentials(type: accountType, credentials: credentials, endpoint: URL(string: apiUrl)!) { result in
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .freshRSS)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .readerBasic)
|
||||
try account.removeCredentials(type: .readerAPIKey)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Account.validateCredentials(type: accountType, credentials: credentials) { result in
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .freshRSS)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .readerBasic)
|
||||
try account.removeCredentials(type: .readerAPIKey)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
//
|
||||
// AddCloudKitAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
|
||||
struct AddCloudKitAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
|
||||
var body: some View {
|
||||
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, footer: formFooter, content: {
|
||||
Button(action: {
|
||||
_ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(AccountManager.shared.activeAccounts.filter({ $0.type == .cloudKit }).count > 0)
|
||||
})
|
||||
}.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(AccountType.cloudKit.localizedAccountName()))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.cloudKit.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your iCloud account.")
|
||||
.font(.headline)
|
||||
|
||||
Text("This account syncs across your Mac and iOS devices using your iCloud account.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
_ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Create")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(AccountManager.shared.activeAccounts.filter({ $0.type == .cloudKit }).count > 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, maxHeight: 150)
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.cloudKit.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("This account syncs across your Mac and iOS devices using your iCloud account.").foregroundColor(.secondary)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
}
|
||||
|
||||
struct AddCloudKitAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddCloudKitAccountView()
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
//
|
||||
// AddFeedWranglerAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
|
||||
struct AddFeedWranglerAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedWranglerViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateFeedWrangler()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text("Feed Wrangler"))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedWrangler.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feed Wrangler account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don’t have a Feed Wrangler account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedWrangler)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedWrangler()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.feedWrangler.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feed Wrangler account and sync your feeds across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don’t have a Feed Wrangler account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedWrangler)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedWranglerAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedWranglerAccountView()
|
||||
}
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
//
|
||||
// AddFeedbinAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 02/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddFeedbinAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedbinViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateFeedbin()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text("Feedbin"))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedbin.image()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feedbin account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don’t have a Feedbin account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedbin)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedbin()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.feedbin.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feedbin account and sync your feeds across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don’t have a Feedbin account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedbin)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedbinAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedbinAccountView()
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
//
|
||||
// AddFeedlyAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddFeedlyAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedlyViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateFeedly()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
})
|
||||
})
|
||||
}.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(AccountType.feedly.localizedAccountName()))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedly.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feedly account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don’t have a Feedly account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedly)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedly()
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(AccountManager.shared.activeAccounts.filter({ $0.type == .cloudKit }).count > 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, maxHeight: 150)
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.feedly.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feedly account and sync your feeds across your devices. Your username and password will be encrypted and stored in Keychain.\n\nDon’t have an Feedly account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedly)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedlyAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedlyAccountView()
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
//
|
||||
// AddLocalAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 02/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
struct AddLocalAccountView: View {
|
||||
|
||||
@State private var newAccountName: String = ""
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Account Name", text: $newAccountName)
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
let newAccount = AccountManager.shared.createAccount(type: .onMyMac)
|
||||
newAccount.name = newAccountName
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
})
|
||||
})
|
||||
}.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(AccountType.onMyMac.localizedAccountName()))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.onMyMac.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Create a local account on your Mac.")
|
||||
.font(.headline)
|
||||
Text("Local accounts store their data on your Mac. They do not sync across your devices.")
|
||||
.font(.callout)
|
||||
.foregroundColor(.secondary)
|
||||
HStack {
|
||||
Text("Name: ")
|
||||
TextField("Account Name", text: $newAccountName)
|
||||
}.padding(.top, 8)
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
let newAccount = AccountManager.shared.createAccount(type: .onMyMac)
|
||||
newAccount.name = newAccountName
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Create")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.defaultAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.onMyMac.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Local accounts do not sync your feeds across devices.").foregroundColor(.secondary)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddLocalAccount_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddLocalAccountView()
|
||||
}
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
//
|
||||
// AddNewsBlurAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddNewsBlurAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddNewsBlurViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateNewsBlur()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text("NewsBlur"))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.newsBlur.image()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your NewsBlur account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don’t have a NewsBlur account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.newsBlur)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateNewsBlur()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.newsBlur.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your NewsBlur account and sync your feeds across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don’t have a NewsBlur account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.newsBlur)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
}
|
||||
|
||||
struct AddNewsBlurAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddNewsBlurAccountView()
|
||||
}
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
//
|
||||
// AddReaderAPIAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddReaderAPIAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddReaderAPIViewModel()
|
||||
public var accountType: AccountType
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if accountType == .freshRSS {
|
||||
TextField("API URL", text: $model.apiUrl)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateReaderAccount(accountType)
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(createDisabled())
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(accountType.localizedAccountName()))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
accountType.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your \(accountType.localizedAccountName()) account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
if accountType == .freshRSS {
|
||||
Text("Don’t have a \(accountType.localizedAccountName()) instance?")
|
||||
.font(.callout)
|
||||
} else {
|
||||
Text("Don’t have an \(accountType.localizedAccountName()) account?")
|
||||
.font(.callout)
|
||||
}
|
||||
Button(action: {
|
||||
model.presentSignUpOption(accountType)
|
||||
}, label: {
|
||||
Text(accountType == .freshRSS ? "Find out more." : "Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
if accountType == .freshRSS {
|
||||
Text("API URL")
|
||||
}
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
if accountType == .freshRSS {
|
||||
TextField("https://myfreshrss.rocks", text: $model.apiUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateReaderAccount(accountType)
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(createDisabled())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(width: 400, height: height())
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
func createDisabled() -> Bool {
|
||||
if accountType == .freshRSS {
|
||||
return model.username.isEmpty || model.password.isEmpty || !model.apiUrl.mayBeURL
|
||||
}
|
||||
return model.username.isEmpty || model.password.isEmpty
|
||||
}
|
||||
|
||||
func height() -> CGFloat {
|
||||
if accountType == .freshRSS {
|
||||
return 260
|
||||
}
|
||||
return 230
|
||||
}
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
accountType.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your \(accountType.localizedAccountName()) account and sync your feeds across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don’t have a \(accountType.localizedAccountName()) instance?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(accountType)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddReaderAPIAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddReaderAPIAccountView(accountType: .freshRSS)
|
||||
//AddReaderAPIAccountView(accountType: .inoreader)
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
//
|
||||
// AddFolderModel.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Alex Faber on 04/07/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
import RSCore
|
||||
import SwiftUI
|
||||
|
||||
|
||||
class AddFolderModel: ObservableObject {
|
||||
|
||||
@Published var shouldDismiss: Bool = false
|
||||
@Published var folderName: String = ""
|
||||
@Published var selectedAccountIndex: Int = 0
|
||||
@Published var accounts: [Account] = []
|
||||
|
||||
@Published var showError: Bool = false
|
||||
@Published var showProgressIndicator: Bool = false
|
||||
|
||||
init() {
|
||||
for account in
|
||||
AccountManager.shared.sortedActiveAccounts{
|
||||
accounts.append(account)
|
||||
}
|
||||
}
|
||||
|
||||
func addFolder() {
|
||||
let account = accounts[selectedAccountIndex]
|
||||
|
||||
showProgressIndicator = true
|
||||
|
||||
account.addFolder(folderName){ result in
|
||||
self.showProgressIndicator = false
|
||||
|
||||
switch result {
|
||||
case .success(_):
|
||||
self.shouldDismiss = true
|
||||
|
||||
case .failure(let error):
|
||||
print("Error")
|
||||
print(error)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
//
|
||||
// AddFolderView.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Alex Faber on 04/07/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
struct AddFolderView: View {
|
||||
|
||||
@ObservedObject private var viewModel = AddFolderModel()
|
||||
@Binding var isPresented: Bool
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
iosForm
|
||||
.onReceive(viewModel.$shouldDismiss, perform: {
|
||||
dismiss in
|
||||
if dismiss == true {
|
||||
isPresented = false
|
||||
}
|
||||
})
|
||||
#else
|
||||
macForm
|
||||
.onReceive(viewModel.$shouldDismiss, perform: { dismiss in
|
||||
if dismiss == true {
|
||||
isPresented = false
|
||||
}
|
||||
})
|
||||
#endif
|
||||
}
|
||||
#if os(iOS)
|
||||
var iosForm: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
Section {
|
||||
TextField("Name", text: $viewModel.folderName)
|
||||
}
|
||||
Section {
|
||||
accountPicker
|
||||
}
|
||||
}
|
||||
.navigationTitle("Add Folder")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationBarItems(
|
||||
leading:Button("Cancel", action: {
|
||||
isPresented = false
|
||||
}
|
||||
)
|
||||
.help("Cancel Adding Folder"),
|
||||
trailing:Button("Add", action: {
|
||||
viewModel.addFolder()
|
||||
}
|
||||
)
|
||||
.disabled(viewModel.folderName.isEmpty)
|
||||
.help("Save Adding Folder")
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macForm: some View {
|
||||
Form {
|
||||
HStack {
|
||||
Spacer()
|
||||
Image(rsImage: AppAssets.faviconTemplateImage)
|
||||
.resizable()
|
||||
.renderingMode(.template)
|
||||
.frame(width: 30, height: 30)
|
||||
Text("Add a Folder")
|
||||
.font(.title)
|
||||
Spacer()
|
||||
}
|
||||
|
||||
LazyVGrid(columns: [GridItem(.fixed(75), spacing: 10, alignment: .trailing),GridItem(.fixed(400), spacing: 0, alignment: .leading) ], alignment: .leading, spacing: 10, pinnedViews: [], content:{
|
||||
Text("Name:").bold()
|
||||
TextField("Name", text: $viewModel.folderName)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.help("The name of the folder you want to create")
|
||||
Text("Account:").bold()
|
||||
accountPicker
|
||||
.help("Pick the account you want to create a folder in.")
|
||||
})
|
||||
buttonStack
|
||||
}
|
||||
.frame(maxWidth: 485)
|
||||
.padding(12)
|
||||
}
|
||||
#endif
|
||||
|
||||
var accountPicker: some View {
|
||||
Picker("Account:", selection: $viewModel.selectedAccountIndex, content: {
|
||||
ForEach(0..<viewModel.accounts.count, id: \.self, content: { index in
|
||||
Text("\(viewModel.accounts[index].account?.nameForDisplay ?? "")").tag(index)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
var buttonStack: some View {
|
||||
HStack {
|
||||
if viewModel.showProgressIndicator == true {
|
||||
ProgressView()
|
||||
.frame(width: 25, height: 25)
|
||||
.help("Adding Folder")
|
||||
}
|
||||
Spacer()
|
||||
Button("Cancel", action: {
|
||||
isPresented = false
|
||||
})
|
||||
.help("Cancel Adding Folder")
|
||||
|
||||
Button("Add", action: {
|
||||
viewModel.addFolder()
|
||||
})
|
||||
.disabled(viewModel.folderName.isEmpty)
|
||||
.help("Add Folder")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
//
|
||||
// AddWebFeedModel.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 4/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
import RSCore
|
||||
import SwiftUI
|
||||
|
||||
enum AddWebFeedError: LocalizedError {
|
||||
|
||||
case none, alreadySubscribed, initialDownload, noFeeds
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .alreadySubscribed:
|
||||
return NSLocalizedString("Can’t add this feed because you’ve already subscribed to it.", comment: "Feed finder")
|
||||
case .initialDownload:
|
||||
return NSLocalizedString("Can’t add this feed because of a download error.", comment: "Feed finder")
|
||||
case .noFeeds:
|
||||
return NSLocalizedString("Can’t add a feed because no feed was found.", comment: "Feed finder")
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AddWebFeedModel: ObservableObject {
|
||||
|
||||
@Published var shouldDismiss: Bool = false
|
||||
@Published var providedURL: String = ""
|
||||
@Published var providedName: String = ""
|
||||
@Published var selectedFolderIndex: Int = 0
|
||||
@Published var addFeedError: AddWebFeedError? {
|
||||
didSet {
|
||||
addFeedError != AddWebFeedError.none ? (showError = true) : (showError = false)
|
||||
}
|
||||
}
|
||||
@Published var showError: Bool = false
|
||||
@Published var containers: [Container] = []
|
||||
@Published var showProgressIndicator: Bool = false
|
||||
|
||||
init() {
|
||||
for account in AccountManager.shared.sortedActiveAccounts {
|
||||
containers.append(account)
|
||||
if let sortedFolders = account.sortedFolders {
|
||||
containers.append(contentsOf: sortedFolders)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pasteUrlFromPasteboard() {
|
||||
guard let stringFromPasteboard = urlStringFromPasteboard, stringFromPasteboard.mayBeURL else {
|
||||
return
|
||||
}
|
||||
providedURL = stringFromPasteboard
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
var urlStringFromPasteboard: String? {
|
||||
if let urlString = NSPasteboard.urlString(from: NSPasteboard.general) {
|
||||
return urlString.normalizedURL
|
||||
}
|
||||
return nil
|
||||
}
|
||||
#else
|
||||
var urlStringFromPasteboard: String? {
|
||||
if let urlString = UIPasteboard.general.url?.absoluteString {
|
||||
return urlString.normalizedURL
|
||||
}
|
||||
return nil
|
||||
}
|
||||
#endif
|
||||
|
||||
struct AccountAndFolderSpecifier {
|
||||
let account: Account
|
||||
let folder: Folder?
|
||||
}
|
||||
|
||||
func accountAndFolderFromContainer(_ container: Container) -> AccountAndFolderSpecifier? {
|
||||
if let account = container as? Account {
|
||||
return AccountAndFolderSpecifier(account: account, folder: nil)
|
||||
}
|
||||
if let folder = container as? Folder, let account = folder.account {
|
||||
return AccountAndFolderSpecifier(account: account, folder: folder)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addWebFeed() {
|
||||
if let account = accountAndFolderFromContainer(containers[selectedFolderIndex])?.account {
|
||||
|
||||
showProgressIndicator = true
|
||||
|
||||
let normalizedURLString = providedURL.normalizedURL
|
||||
|
||||
guard !normalizedURLString.isEmpty, let url = URL(string: normalizedURLString) else {
|
||||
showProgressIndicator = false
|
||||
return
|
||||
}
|
||||
|
||||
let container = containers[selectedFolderIndex]
|
||||
|
||||
if account.hasWebFeed(withURL: normalizedURLString) {
|
||||
addFeedError = .alreadySubscribed
|
||||
showProgressIndicator = false
|
||||
return
|
||||
}
|
||||
|
||||
account.createWebFeed(url: url.absoluteString, name: providedName, container: container, validateFeed: true, completion: { [weak self] result in
|
||||
self?.showProgressIndicator = false
|
||||
switch result {
|
||||
case .success(let feed):
|
||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.webFeed: feed])
|
||||
self?.shouldDismiss = true
|
||||
case .failure(let error):
|
||||
switch error {
|
||||
case AccountError.createErrorAlreadySubscribed:
|
||||
self?.addFeedError = .alreadySubscribed
|
||||
return
|
||||
case AccountError.createErrorNotFound:
|
||||
self?.addFeedError = .noFeeds
|
||||
return
|
||||
default:
|
||||
print("Error")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func smallIconImage(for container: Container) -> RSImage? {
|
||||
if let smallIconProvider = container as? SmallIconProvider {
|
||||
return smallIconProvider.smallIcon?.image
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
//
|
||||
// AddWebFeedView.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 3/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
|
||||
struct AddWebFeedView: View {
|
||||
|
||||
@StateObject private var viewModel = AddWebFeedModel()
|
||||
@Binding var isPresented: Bool
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
iosForm
|
||||
.onAppear {
|
||||
viewModel.pasteUrlFromPasteboard()
|
||||
}
|
||||
.onReceive(viewModel.$shouldDismiss, perform: { dismiss in
|
||||
if dismiss == true {
|
||||
isPresented = false
|
||||
}
|
||||
})
|
||||
#else
|
||||
macForm
|
||||
.onAppear {
|
||||
viewModel.pasteUrlFromPasteboard()
|
||||
}.alert(isPresented: $viewModel.showError) {
|
||||
Alert(title: Text("Oops"),
|
||||
message: Text(viewModel.addFeedError!.localizedDescription),
|
||||
dismissButton: Alert.Button.cancel({
|
||||
viewModel.addFeedError = AddWebFeedError.none
|
||||
}))
|
||||
}
|
||||
.onChange(of: viewModel.shouldDismiss, perform: { dismiss in
|
||||
if dismiss == true {
|
||||
isPresented = false
|
||||
}
|
||||
})
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
var macForm: some View {
|
||||
Form {
|
||||
HStack {
|
||||
Spacer()
|
||||
Image(rsImage: AppAssets.faviconTemplateImage)
|
||||
.resizable()
|
||||
.renderingMode(.template)
|
||||
.frame(width: 30, height: 30)
|
||||
Text("Add a Web Feed")
|
||||
.font(.title)
|
||||
Spacer()
|
||||
}.padding()
|
||||
|
||||
LazyVGrid(columns: [GridItem(.fixed(75), spacing: 10, alignment: .trailing),GridItem(.fixed(400), spacing: 0, alignment: .leading) ], alignment: .leading, spacing: 10, pinnedViews: [], content:{
|
||||
Text("URL:").bold()
|
||||
urlTextField
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.help("The URL of the feed you want to add.")
|
||||
Text("Name:").bold()
|
||||
providedNameTextField
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.help("The name of the feed. (Optional.)")
|
||||
Text("Folder:").bold()
|
||||
folderPicker
|
||||
.help("Pick the folder you want to add the feed to.")
|
||||
})
|
||||
buttonStack
|
||||
}
|
||||
.frame(maxWidth: 485)
|
||||
.padding(12)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
var iosForm: some View {
|
||||
NavigationView {
|
||||
List {
|
||||
urlTextField
|
||||
providedNameTextField
|
||||
folderPicker
|
||||
}
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitle("Add Web Feed")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationBarItems(leading:
|
||||
Button("Cancel", action: {
|
||||
isPresented = false
|
||||
})
|
||||
.help("Cancel Add Feed")
|
||||
, trailing:
|
||||
HStack(spacing: 12) {
|
||||
if viewModel.showProgressIndicator == true {
|
||||
ProgressView()
|
||||
}
|
||||
Button("Add", action: {
|
||||
viewModel.addWebFeed()
|
||||
})
|
||||
.disabled(!viewModel.providedURL.mayBeURL)
|
||||
.help("Add Feed")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ViewBuilder var urlTextField: some View {
|
||||
#if os(iOS)
|
||||
TextField("URL", text: $viewModel.providedURL)
|
||||
.disableAutocorrection(true)
|
||||
.autocapitalization(UITextAutocapitalizationType.none)
|
||||
#else
|
||||
TextField("URL", text: $viewModel.providedURL)
|
||||
.disableAutocorrection(true)
|
||||
#endif
|
||||
}
|
||||
|
||||
var providedNameTextField: some View {
|
||||
TextField("Title (Optional)", text: $viewModel.providedName)
|
||||
}
|
||||
|
||||
@ViewBuilder var folderPicker: some View {
|
||||
#if os(iOS)
|
||||
Picker("Folder", selection: $viewModel.selectedFolderIndex, content: {
|
||||
ForEach(0..<viewModel.containers.count, id: \.self, content: { position in
|
||||
if let containerName = (viewModel.containers[position] as? DisplayNameProvider)?.nameForDisplay {
|
||||
if viewModel.containers[position] is Folder {
|
||||
HStack(alignment: .top) {
|
||||
if let image = viewModel.smallIconImage(for: viewModel.containers[position]) {
|
||||
Image(rsImage: image)
|
||||
.foregroundColor(Color("AccentColor"))
|
||||
}
|
||||
Text("\(containerName)")
|
||||
.tag(position)
|
||||
}.padding(.leading, 16)
|
||||
} else {
|
||||
HStack(alignment: .top) {
|
||||
if let image = viewModel.smallIconImage(for: viewModel.containers[position]) {
|
||||
Image(rsImage: image)
|
||||
.foregroundColor(Color("AccentColor"))
|
||||
}
|
||||
Text(containerName)
|
||||
.tag(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
#else
|
||||
Picker("", selection: $viewModel.selectedFolderIndex, content: {
|
||||
ForEach(0..<viewModel.containers.count, id: \.self, content: { index in
|
||||
if let containerName = (viewModel.containers[index] as? DisplayNameProvider)?.nameForDisplay {
|
||||
if viewModel.containers[index] is Folder {
|
||||
HStack {
|
||||
if let image = viewModel.smallIconImage(for: viewModel.containers[index]) {
|
||||
Image(rsImage: image)
|
||||
}
|
||||
Text("\(containerName)")
|
||||
}
|
||||
.padding(.leading, 2)
|
||||
.tag(index)
|
||||
} else {
|
||||
Text(containerName)
|
||||
.padding(.leading, 2)
|
||||
.tag(index)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.padding(.leading, -8)
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
var buttonStack: some View {
|
||||
HStack {
|
||||
if viewModel.showProgressIndicator == true {
|
||||
ProgressView()
|
||||
.frame(width: 25, height: 25)
|
||||
.help("Adding Feed")
|
||||
}
|
||||
Spacer()
|
||||
Button("Cancel", action: {
|
||||
isPresented = false
|
||||
})
|
||||
.help("Cancel Add Feed")
|
||||
|
||||
Button("Add", action: {
|
||||
viewModel.addWebFeed()
|
||||
})
|
||||
.disabled(!viewModel.providedURL.mayBeURL)
|
||||
.help("Add Feed")
|
||||
}
|
||||
.padding(.trailing, 2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user