mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Models now handle sign up presentations
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// 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://feedwrangler.net/users/new")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .feedWrangler:
|
||||
UIApplication.shared.open(URL(string: "https://freshrss.org")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .freshRSS:
|
||||
UIApplication.shared.open(URL(string: "https://www.inoreader.com")!, 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
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,14 @@ import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedWranglerViewModel: ObservableObject {
|
||||
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() {
|
||||
|
||||
|
||||
@@ -12,13 +12,14 @@ import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedbinViewModel: ObservableObject {
|
||||
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
|
||||
|
||||
@@ -12,12 +12,13 @@ import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedlyViewModel: ObservableObject, OAuthAccountAuthorizationOperationDelegate {
|
||||
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 = ""
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateFeedly() {
|
||||
isAuthenticating = true
|
||||
|
||||
@@ -12,7 +12,7 @@ import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddNewsBlurViewModel: ObservableObject {
|
||||
class AddNewsBlurViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
|
||||
@@ -12,7 +12,7 @@ import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddReaderAPIViewModel: ObservableObject {
|
||||
class AddReaderAPIViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@@ -20,6 +20,7 @@ class AddReaderAPIViewModel: ObservableObject {
|
||||
@Published var password: String = ""
|
||||
@Published var apiUrl: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateReaderAccount(_ accountType: AccountType) {
|
||||
isAuthenticating = true
|
||||
|
||||
@@ -69,7 +69,7 @@ struct AddFeedWranglerAccountView: View {
|
||||
Text("Don't have a Feed Wrangler account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
NSWorkspace.shared.open(URL(string: "https://feedwrangler.net/users/new")!)
|
||||
model.presentSignUpOption(.feedWrangler)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
@@ -137,7 +137,7 @@ struct AddFeedWranglerAccountView: View {
|
||||
AccountType.newsBlur.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Text("Sign in to your NewsBlur account.")
|
||||
Text("Sign in to your Feed Wrangler account.")
|
||||
.font(.headline)
|
||||
|
||||
Text("This account syncs across your subscriptions across devices.")
|
||||
|
||||
@@ -30,10 +30,35 @@ struct AddFeedbinAccountView: View {
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, footer: ProgressView()
|
||||
.hidden(!model.isAuthenticating) , content: {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
SecureField("Password", text: $model.password)
|
||||
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: {
|
||||
@@ -81,7 +106,7 @@ struct AddFeedbinAccountView: View {
|
||||
Text("Don't have a Feedbin account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
NSWorkspace.shared.open(URL(string: "https://feedbin.com/signup")!)
|
||||
model.presentSignUpOption(.feedbin)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
@@ -161,9 +186,12 @@ struct AddFeedbinAccountView: View {
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feedbin account and sync your subscriptions 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: {}, label: {
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedbin)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
|
||||
@@ -53,7 +53,7 @@ struct AddFeedlyAccountView: View {
|
||||
Text("Don't have a Feedly account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
NSWorkspace.shared.open(URL(string: "https://feedly.com")!)
|
||||
model.presentSignUpOption(.feedly)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
@@ -70,7 +70,7 @@ struct AddFeedlyAccountView: View {
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
authenticateFeedly()
|
||||
model.authenticateFeedly()
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
|
||||
@@ -66,7 +66,7 @@ struct AddNewsBlurAccountView: View {
|
||||
Text("Don't have a NewsBlur account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
NSWorkspace.shared.open(URL(string: "https://newsblur.com")!)
|
||||
model.presentSignUpOption(.newsBlur)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
|
||||
@@ -53,10 +53,8 @@ struct AddReaderAPIAccountView: View {
|
||||
Text("Don't have an \(accountType.localizedAccountName()) account?")
|
||||
.font(.callout)
|
||||
}
|
||||
|
||||
|
||||
Button(action: {
|
||||
signUp()
|
||||
model.presentSignUpOption(accountType)
|
||||
}, label: {
|
||||
Text(accountType == .freshRSS ? "Find out more." : "Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
@@ -140,36 +138,6 @@ struct AddReaderAPIAccountView: View {
|
||||
}
|
||||
return 230
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private func signUp() {
|
||||
switch accountType {
|
||||
case .freshRSS:
|
||||
#if os(macOS)
|
||||
NSWorkspace.shared.open(URL(string: "https://freshrss.org")!)
|
||||
#endif
|
||||
case .inoreader:
|
||||
#if os(macOS)
|
||||
NSWorkspace.shared.open(URL(string: "https://www.inoreader.com")!)
|
||||
#endif
|
||||
case .bazQux:
|
||||
#if os(macOS)
|
||||
NSWorkspace.shared.open(URL(string: "https://bazqux.com")!)
|
||||
#endif
|
||||
case .theOldReader:
|
||||
#if os(macOS)
|
||||
NSWorkspace.shared.open(URL(string: "https://theoldreader.com")!)
|
||||
#endif
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct AddReaderAPIAccountView_Previews: PreviewProvider {
|
||||
|
||||
Reference in New Issue
Block a user