Add fresh RSS account with credentials account view
This commit is contained in:
parent
86c9100e70
commit
81a92738f9
@ -38,7 +38,8 @@ class SettingsAddAccountModel: ObservableObject {
|
|||||||
SettingsAddAccount(name: "Feedly", accountType: .feedly),
|
SettingsAddAccount(name: "Feedly", accountType: .feedly),
|
||||||
SettingsAddAccount(name: "Feed Wrangler", accountType: .feedWrangler),
|
SettingsAddAccount(name: "Feed Wrangler", accountType: .feedWrangler),
|
||||||
SettingsAddAccount(name: "iCloud", accountType: .cloudKit),
|
SettingsAddAccount(name: "iCloud", accountType: .cloudKit),
|
||||||
SettingsAddAccount(name: "NewsBlur", accountType: .newsBlur)
|
SettingsAddAccount(name: "NewsBlur", accountType: .newsBlur),
|
||||||
|
SettingsAddAccount(name: "Fresh RSS", accountType: .freshRSS)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ struct SettingsAddAccountView: View {
|
|||||||
switch model.selectedAccountType {
|
switch model.selectedAccountType {
|
||||||
case .onMyMac:
|
case .onMyMac:
|
||||||
SettingsLocalAccountView()
|
SettingsLocalAccountView()
|
||||||
case .feedbin, .feedWrangler, .newsBlur:
|
case .feedbin, .feedWrangler, .newsBlur, .freshRSS:
|
||||||
SettingsCredentialsAccountView(accountType: model.selectedAccountType!)
|
SettingsCredentialsAccountView(accountType: model.selectedAccountType!)
|
||||||
case .cloudKit:
|
case .cloudKit:
|
||||||
SettingsCloudKitAccountView()
|
SettingsCloudKitAccountView()
|
||||||
|
@ -16,6 +16,7 @@ class SettingsCredentialsAccountModel: ObservableObject {
|
|||||||
@Published var shouldDismiss: Bool = false
|
@Published var shouldDismiss: Bool = false
|
||||||
@Published var email: String = ""
|
@Published var email: String = ""
|
||||||
@Published var password: String = ""
|
@Published var password: String = ""
|
||||||
|
@Published var apiUrl: String = ""
|
||||||
@Published var busy: Bool = false
|
@Published var busy: Bool = false
|
||||||
@Published var accountCredentialsError: AccountCredentialsError? {
|
@Published var accountCredentialsError: AccountCredentialsError? {
|
||||||
didSet {
|
didSet {
|
||||||
@ -43,6 +44,9 @@ class SettingsCredentialsAccountModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isValid: Bool {
|
var isValid: Bool {
|
||||||
|
if apiUrlEnabled {
|
||||||
|
return !email.isEmpty && !password.isEmpty && !apiUrl.isEmpty
|
||||||
|
}
|
||||||
return !email.isEmpty && !password.isEmpty
|
return !email.isEmpty && !password.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +73,10 @@ class SettingsCredentialsAccountModel: ObservableObject {
|
|||||||
return accountType == .newsBlur ? NSLocalizedString("Username or Email", comment: "") : NSLocalizedString("Email", comment: "")
|
return accountType == .newsBlur ? NSLocalizedString("Username or Email", comment: "") : NSLocalizedString("Email", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var apiUrlEnabled: Bool {
|
||||||
|
return accountType == .freshRSS
|
||||||
|
}
|
||||||
|
|
||||||
func addAccount() {
|
func addAccount() {
|
||||||
switch accountType {
|
switch accountType {
|
||||||
case .feedbin:
|
case .feedbin:
|
||||||
@ -77,6 +85,8 @@ class SettingsCredentialsAccountModel: ObservableObject {
|
|||||||
addFeedWranglerAccount()
|
addFeedWranglerAccount()
|
||||||
case .newsBlur:
|
case .newsBlur:
|
||||||
addNewsBlurAccount()
|
addNewsBlurAccount()
|
||||||
|
case .freshRSS:
|
||||||
|
addFreshRSSAccount()
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -221,4 +231,51 @@ extension SettingsCredentialsAccountModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK:- Fresh RSS
|
||||||
|
|
||||||
|
func addFreshRSSAccount() {
|
||||||
|
busy = true
|
||||||
|
let credentials = Credentials(type: .readerBasic, username: email, secret: password)
|
||||||
|
|
||||||
|
Account.validateCredentials(type: .freshRSS, credentials: credentials, endpoint: URL(string: apiUrl)!) { [weak self] result in
|
||||||
|
|
||||||
|
guard let self = self else { return }
|
||||||
|
|
||||||
|
self.busy = false
|
||||||
|
|
||||||
|
switch result {
|
||||||
|
case .success(let validatedCredentials):
|
||||||
|
|
||||||
|
guard let validatedCredentials = validatedCredentials else {
|
||||||
|
self.accountCredentialsError = .invalidCredentials
|
||||||
|
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.shouldDismiss = true
|
||||||
|
account.refreshAll(completion: { result in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
break
|
||||||
|
case .failure(let error):
|
||||||
|
self.accountCredentialsError = .other(error: error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
self.accountCredentialsError = .keyChain
|
||||||
|
}
|
||||||
|
|
||||||
|
case .failure:
|
||||||
|
self.accountCredentialsError = .noNetwork
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ struct SettingsCredentialsAccountView: View {
|
|||||||
Text(settingsModel.showPassword ? "Hide" : "Show")
|
Text(settingsModel.showPassword ? "Hide" : "Show")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if settingsModel.apiUrlEnabled {
|
||||||
|
TextField("API URL", text: $settingsModel.apiUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Section(footer: errorFooter) {
|
Section(footer: errorFooter) {
|
||||||
HStack {
|
HStack {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user