This commit is contained in:
Maurice Parker
2020-07-07 16:05:33 -05:00
5 changed files with 180 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
//
// SettingsAccountLabelView.swift
// Multiplatform iOS
//
// Created by Rizwan on 07/07/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import RSCore
struct SettingsAccountLabelView: View {
let accountImage: RSImage?
let accountLabel: String
var body: some View {
HStack {
Image(rsImage: accountImage!)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(height: 32)
Text(verbatim: accountLabel).font(.title)
}
.foregroundColor(.primary).padding(4.0)
}
}
struct SettingsAccountLabelView_Previews: PreviewProvider {
static var previews: some View {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .onMyMac),
accountLabel: "On My Device"
)
.previewLayout(.fixed(width: 300, height: 44))
}
}

View File

@@ -0,0 +1,54 @@
//
// SettingsAddAccountView.swift
// Multiplatform iOS
//
// Created by Rizwan on 07/07/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
struct SettingsAddAccountView: View {
@State private var isAddPresented = false
@State private var selectedAccountType: AccountType = .onMyMac
var body: some View {
List {
Button(action: {
self.selectedAccountType = AccountType.onMyMac
self.isAddPresented = true
}) {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .onMyMac),
accountLabel: Account.defaultLocalAccountName
)
}
Button(action: {
self.selectedAccountType = AccountType.feedbin
self.isAddPresented = true
}) {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .feedbin),
accountLabel: "Feedbin"
)
}
}
.listStyle(InsetGroupedListStyle())
.sheet(isPresented: $isAddPresented) {
if selectedAccountType == .onMyMac {
SettingsLocalAccountView()
}
if selectedAccountType == .feedbin {
//SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())
}
}
.navigationBarTitle(Text("Add Account"), displayMode: .inline)
}
}
struct SettingsAddAccountView_Previews: PreviewProvider {
static var previews: some View {
SettingsAddAccountView()
}
}

View File

@@ -0,0 +1,69 @@
//
// SettingsLocalAccountView.swift
// Multiplatform iOS
//
// Created by Rizwan on 07/07/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
struct SettingsLocalAccountView: View {
@Environment(\.presentationMode) var presentation
@State var name: String = ""
var body: some View {
NavigationView {
List {
Section {
imageView
HStack {
TextField("Name", text: $name)
}
}
Section {
HStack {
Spacer()
Button(action: { self.addAccount() }) {
Text("Add Account")
}
Spacer()
}
}
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitle(Text(verbatim: Account.defaultLocalAccountName), displayMode: .inline)
.navigationBarItems(leading: Button(action: { self.dismiss() }) { Text("Cancel") } )
}
}
var imageView: some View {
HStack {
Spacer()
Image(rsImage: AppAssets.image(for: .onMyMac)!)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(height: 48, alignment: .center)
.padding()
Spacer()
}
.listRowBackground(Color.clear)
}
private func addAccount() {
let account = AccountManager.shared.createAccount(type: .onMyMac)
account.name = name
dismiss()
}
private func dismiss() {
presentation.wrappedValue.dismiss()
}
}
struct SettingsLocalAccountView_Previews: PreviewProvider {
static var previews: some View {
SettingsLocalAccountView()
}
}

View File

@@ -67,7 +67,7 @@ struct SettingsView: View {
})
})
NavigationLink(
destination: EmptyView(),
destination: SettingsAddAccountView(),
label: {
Text("Add Account")
})