mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Converts AppDefaults to singleton
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// AccountsPreferencesView.swift
|
||||
// macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 27/6/20.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AccountPreferencesViewModel {
|
||||
let accountTypes = ["On My Mac", "FeedBin"]
|
||||
var selectedAccount = Int?.none
|
||||
}
|
||||
|
||||
struct AccountsPreferencesView: View {
|
||||
|
||||
@State private var viewModel = AccountPreferencesViewModel()
|
||||
@State private var addAccountViewModel = AccountPreferencesViewModel()
|
||||
@State private var showAddAccountView: Bool = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
VStack(alignment: .leading) {
|
||||
List(selection: $viewModel.selectedAccount, content: {
|
||||
ForEach(0..<viewModel.accountTypes.count, content: { i in
|
||||
AccountDetailRow(imageName: "desktopcomputer", accountName: viewModel.accountTypes[i]).padding(.vertical, 8)
|
||||
})
|
||||
})
|
||||
HStack {
|
||||
Button("+", action: {
|
||||
showAddAccountView.toggle()
|
||||
})
|
||||
Button("-", action: {})
|
||||
.disabled(viewModel.selectedAccount == nil)
|
||||
Spacer()
|
||||
}
|
||||
}.frame(width: 225, height: 300, alignment: .leading)
|
||||
VStack(alignment: .leading) {
|
||||
viewModel.selectedAccount == nil ? Text("Select Account") : Text(viewModel.accountTypes[viewModel.selectedAccount!])
|
||||
Spacer()
|
||||
}.frame(width: 225, height: 300, alignment: .leading)
|
||||
}
|
||||
Spacer()
|
||||
}.sheet(isPresented: $showAddAccountView,
|
||||
onDismiss: { showAddAccountView.toggle() },
|
||||
content: {
|
||||
AddAccountView()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AccountDetailRow: View {
|
||||
|
||||
var imageName: String
|
||||
var accountName: String
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Image(systemName: imageName).font(.headline)
|
||||
Text(accountName).font(.headline)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddAccountView: View {
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
let accountTypes = ["On My Mac", "FeedBin"]
|
||||
@State var selectedAccount: Int = 0
|
||||
@State private var userName: String = ""
|
||||
@State private var password: String = ""
|
||||
|
||||
var body: some View {
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text("Add an Account").font(.headline)
|
||||
Form {
|
||||
Picker("Account Type",
|
||||
selection: $selectedAccount,
|
||||
content: {
|
||||
ForEach(0..<accountTypes.count, content: {
|
||||
AccountDetailRow(imageName: "desktopcomputer", accountName: accountTypes[$0])
|
||||
})
|
||||
})
|
||||
|
||||
if selectedAccount == 1 {
|
||||
TextField("Email", text: $userName)
|
||||
SecureField("Password", text: $password)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
|
||||
Button(action: { presentationMode.wrappedValue.dismiss() }, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
|
||||
if selectedAccount == 0 {
|
||||
Button("Add", action: {})
|
||||
}
|
||||
|
||||
if selectedAccount != 0 {
|
||||
Button("Create", action: {})
|
||||
.disabled(userName.count == 0 || password.count == 0)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}.frame(width: 300, alignment: .top).padding()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class AddAccountModel: ObservableObject {
|
||||
let accountTypes = ["On My Mac", "FeedBin"]
|
||||
@Published var selectedAccount = Int?.none
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// AdvancedPreferencesView.swift
|
||||
// macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 27/6/20.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AdvancedPreferencesView: View {
|
||||
|
||||
@EnvironmentObject private var preferences: AppDefaults
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Form {
|
||||
Toggle("Check for app updates automatically", isOn: $preferences.checkForUpdatesAutomatically)
|
||||
|
||||
Toggle("Download Test Builds", isOn: $preferences.downloadTestBuilds)
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("If you’re not sure, don't enable test builds. Test builds may have bugs, which may include crashing bugs and data loss.").foregroundColor(.secondary)
|
||||
Spacer()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Check for Updates", action: {})
|
||||
Spacer()
|
||||
}.padding(.vertical, 12)
|
||||
|
||||
|
||||
Toggle("Send Crash Logs Automatically", isOn: $preferences.sendCrashLogs)
|
||||
|
||||
Spacer()
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Privacy Policy", action: {})
|
||||
Spacer()
|
||||
}.padding(.top, 12)
|
||||
|
||||
|
||||
}
|
||||
Spacer()
|
||||
}.frame(width: 300, alignment: .center)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// GeneralPreferencesView.swift
|
||||
// macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 27/6/20.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct GeneralPreferencesView: View {
|
||||
|
||||
@EnvironmentObject private var defaults: AppDefaults
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Form {
|
||||
Picker("Refresh Feeds",
|
||||
selection: $defaults.interval,
|
||||
content: {
|
||||
ForEach(RefreshInterval.allCases, content: { interval in
|
||||
Text(interval.description()).tag(interval.rawValue)
|
||||
})
|
||||
}).frame(width: 300, alignment: .center)
|
||||
|
||||
Toggle("Open webpages in background in browser", isOn: $defaults.openInBrowserInBackground)
|
||||
|
||||
Toggle("Hide Unread Count in Dock", isOn: $defaults.hideDockUnreadCount)
|
||||
}
|
||||
Spacer()
|
||||
}.frame(width: 300, alignment: .center)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user