Merge pull request #2 from brentsimmons/master

Syncing with
This commit is contained in:
Stuart Breckenridge 2019-06-16 07:19:23 +08:00 committed by GitHub
commit 4887fb7f5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 23 deletions

View File

@ -20,7 +20,7 @@ Heres [How to Support NetNewsWire](Technotes/HowToSupportNetNewsWire.markdown
[Join the Slack group](https://join.slack.com/t/netnewswire/shared_invite/enQtNjM4MDA1MjQzMDkzLTNlNjBhOWVhYzdhYjA4ZWFhMzQ1MTUxYjU0NTE5ZGY0YzYwZWJhNjYwNTNmNTg2NjIwYWY4YzhlYzk5NmU3ZTc) to talk with other NetNewsWire users — and to help out, if youd like to, by testing, coding, writing, providing feedback, or just helping us think things through. Everybody is welcome and encouraged to join.
Every community member is expected to abide by the code of conduct which is included in the [Contributing](Contributing.md) page.
Every community member is expected to abide by the code of conduct which is included in the [Contributing](CONTRIBUTING.md) page.
#### Pull Requests

View File

@ -9,10 +9,12 @@
import SwiftUI
import Combine
import Account
import RSWeb
struct SettingsDetailAccountView : View {
@ObjectBinding var viewModel: ViewModel
@State private var verifyDelete = false
@State private var showFeedbinCredentials = false
var body: some View {
List {
@ -26,15 +28,19 @@ struct SettingsDetailAccountView : View {
Text("Active")
}
}
Section {
HStack {
Spacer()
Button(action: {
}) {
Text("Credentials")
if viewModel.isCreditialsAvailable {
Section {
HStack {
Spacer()
Button(action: {
self.showFeedbinCredentials = true
}) {
Text("Credentials")
}
.presentation(showFeedbinCredentials ? feedbinCredentialsModal : nil)
.onDisappear() { self.showFeedbinCredentials = false }
Spacer()
}
Spacer()
}
}
if viewModel.isDeletable {
@ -62,6 +68,11 @@ struct SettingsDetailAccountView : View {
}
var feedbinCredentialsModal: Modal {
let feedbinViewModel = SettingsFeedbinAccountView.ViewModel(account: viewModel.account)
return Modal(SettingsFeedbinAccountView(viewModel: feedbinViewModel))
}
class ViewModel: BindableObject {
let didChange = PassthroughSubject<ViewModel, Never>()
let account: Account
@ -94,6 +105,10 @@ struct SettingsDetailAccountView : View {
}
}
var isCreditialsAvailable: Bool {
return account.type != .onMyMac
}
var isDeletable: Bool {
return AccountManager.shared.defaultAccount != account
}

View File

@ -16,8 +16,7 @@ struct SettingsFeedbinAccountView : View {
@ObjectBinding var viewModel: ViewModel
@State var busy: Bool = false
@State var error: Text = Text("")
var account: Account? = nil
var body: some View {
NavigationView {
List {
@ -25,15 +24,15 @@ struct SettingsFeedbinAccountView : View {
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin").padding()
) {
HStack {
Spacer()
TextField($viewModel.email, placeholder: Text("Email"))
.textContentType(.username)
Spacer()
Text("Email:")
Divider()
TextField($viewModel.email)
.textContentType(.username)
}
HStack {
Spacer()
SecureField($viewModel.password, placeholder: Text("Password"))
Spacer()
Text("Password:")
Divider()
SecureField($viewModel.password)
}
}
Section(footer:
@ -46,7 +45,11 @@ struct SettingsFeedbinAccountView : View {
HStack {
Spacer()
Button(action: { self.addAccount() }) {
Text("Add Account")
if viewModel.isUpdate {
Text("Update Account")
} else {
Text("Add Account")
}
}
.disabled(!viewModel.isValid)
Spacer()
@ -65,7 +68,8 @@ struct SettingsFeedbinAccountView : View {
private func addAccount() {
busy = true
error = Text("")
let emailAddress = viewModel.email.trimmingCharacters(in: .whitespaces)
let credentials = Credentials.basic(username: emailAddress, password: viewModel.password)
@ -80,11 +84,11 @@ struct SettingsFeedbinAccountView : View {
var newAccount = false
let workAccount: Account
if self.account == nil {
if self.viewModel.account == nil {
workAccount = AccountManager.shared.createAccount(type: .feedbin)
newAccount = true
} else {
workAccount = self.account!
workAccount = self.viewModel.account!
}
do {
@ -122,6 +126,18 @@ struct SettingsFeedbinAccountView : View {
class ViewModel: BindableObject {
let didChange = PassthroughSubject<ViewModel, Never>()
var account: Account? = nil
init() {
}
init(account: Account) {
self.account = account
if case .basic(let username, let password) = try? account.retrieveBasicCredentials() {
self.email = username
self.password = password
}
}
var email: String = "" {
didSet {
@ -134,6 +150,10 @@ struct SettingsFeedbinAccountView : View {
}
}
var isUpdate: Bool {
return account != nil
}
var isValid: Bool {
return !email.isEmpty && !password.isEmpty
}
@ -144,7 +164,7 @@ struct SettingsFeedbinAccountView : View {
#if DEBUG
struct SettingsFeedbinAccountView_Previews : PreviewProvider {
static var previews: some View {
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())
}
}
#endif