From 5aa329bf1cead9f97247221afa4c6ad02d79b948 Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Tue, 7 Jul 2020 22:45:12 +0530 Subject: [PATCH] Adds Account settings and New Local account addition --- .../Accounts/SettingsAccountLabelView.swift | 36 ++++++++++ .../Accounts/SettingsAddAccountView.swift | 54 +++++++++++++++ .../Accounts/SettingsLocalAccountView.swift | 69 +++++++++++++++++++ Multiplatform/iOS/Settings/SettingsView.swift | 2 +- NetNewsWire.xcodeproj/project.pbxproj | 20 ++++++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 Multiplatform/iOS/Settings/Accounts/SettingsAccountLabelView.swift create mode 100644 Multiplatform/iOS/Settings/Accounts/SettingsAddAccountView.swift create mode 100644 Multiplatform/iOS/Settings/Accounts/SettingsLocalAccountView.swift diff --git a/Multiplatform/iOS/Settings/Accounts/SettingsAccountLabelView.swift b/Multiplatform/iOS/Settings/Accounts/SettingsAccountLabelView.swift new file mode 100644 index 000000000..39c963480 --- /dev/null +++ b/Multiplatform/iOS/Settings/Accounts/SettingsAccountLabelView.swift @@ -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)) + } +} diff --git a/Multiplatform/iOS/Settings/Accounts/SettingsAddAccountView.swift b/Multiplatform/iOS/Settings/Accounts/SettingsAddAccountView.swift new file mode 100644 index 000000000..6bd475367 --- /dev/null +++ b/Multiplatform/iOS/Settings/Accounts/SettingsAddAccountView.swift @@ -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() + } +} diff --git a/Multiplatform/iOS/Settings/Accounts/SettingsLocalAccountView.swift b/Multiplatform/iOS/Settings/Accounts/SettingsLocalAccountView.swift new file mode 100644 index 000000000..40d1dc9a6 --- /dev/null +++ b/Multiplatform/iOS/Settings/Accounts/SettingsLocalAccountView.swift @@ -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() + } +} diff --git a/Multiplatform/iOS/Settings/SettingsView.swift b/Multiplatform/iOS/Settings/SettingsView.swift index 5494b83d8..8f501dec0 100644 --- a/Multiplatform/iOS/Settings/SettingsView.swift +++ b/Multiplatform/iOS/Settings/SettingsView.swift @@ -67,7 +67,7 @@ struct SettingsView: View { }) }) NavigationLink( - destination: EmptyView(), + destination: SettingsAddAccountView(), label: { Text("Add Account") }) diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index a8be3d0c1..be30735dc 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -670,6 +670,9 @@ 6581C74020CED60100F4AD34 /* netnewswire-subscribe-to-feed.js in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73F20CED60100F4AD34 /* netnewswire-subscribe-to-feed.js */; }; 6581C74220CED60100F4AD34 /* ToolbarItemIcon.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 6581C74120CED60100F4AD34 /* ToolbarItemIcon.pdf */; }; 6594CA3B24AF6F2A005C7D7C /* OPMLExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8444C8F11FED81840051386C /* OPMLExporter.swift */; }; + 65ACE48424B4779B003AE06A /* SettingsAddAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65ACE48324B4779B003AE06A /* SettingsAddAccountView.swift */; }; + 65ACE48624B477C9003AE06A /* SettingsAccountLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65ACE48524B477C9003AE06A /* SettingsAccountLabelView.swift */; }; + 65ACE48824B48020003AE06A /* SettingsLocalAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65ACE48724B48020003AE06A /* SettingsLocalAccountView.swift */; }; 65C2E40124B05D8A000AFDF6 /* FeedsSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C2E40024B05D8A000AFDF6 /* FeedsSettingsModel.swift */; }; 65CBAD5A24AE03C20006DD91 /* ColorPaletteContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65CBAD5924AE03C20006DD91 /* ColorPaletteContainerView.swift */; }; 65ED3FB7235DEF6C0081F399 /* ArticleArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F204DF1FAACBB30076E152 /* ArticleArray.swift */; }; @@ -2079,6 +2082,9 @@ 6581C73F20CED60100F4AD34 /* netnewswire-subscribe-to-feed.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = "netnewswire-subscribe-to-feed.js"; sourceTree = ""; }; 6581C74120CED60100F4AD34 /* ToolbarItemIcon.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = ToolbarItemIcon.pdf; sourceTree = ""; }; 6581C74320CED60100F4AD34 /* Subscribe_to_Feed.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Subscribe_to_Feed.entitlements; sourceTree = ""; }; + 65ACE48324B4779B003AE06A /* SettingsAddAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAddAccountView.swift; sourceTree = ""; }; + 65ACE48524B477C9003AE06A /* SettingsAccountLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAccountLabelView.swift; sourceTree = ""; }; + 65ACE48724B48020003AE06A /* SettingsLocalAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsLocalAccountView.swift; sourceTree = ""; }; 65C2E40024B05D8A000AFDF6 /* FeedsSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedsSettingsModel.swift; sourceTree = ""; }; 65CBAD5924AE03C20006DD91 /* ColorPaletteContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPaletteContainerView.swift; sourceTree = ""; }; 65ED4083235DEF6C0081F399 /* NetNewsWire.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetNewsWire.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2466,6 +2472,7 @@ 5181C66124B0C326002E0F70 /* SettingsModel.swift */, 172199C824AB228900A31D04 /* SettingsView.swift */, 17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */, + 65ACE46124B47770003AE06A /* Accounts */, 5177475724B399B500EB0F74 /* About */, ); path = Settings; @@ -3126,6 +3133,16 @@ path = SafariExtension; sourceTree = ""; }; + 65ACE46124B47770003AE06A /* Accounts */ = { + isa = PBXGroup; + children = ( + 65ACE48324B4779B003AE06A /* SettingsAddAccountView.swift */, + 65ACE48524B477C9003AE06A /* SettingsAccountLabelView.swift */, + 65ACE48724B48020003AE06A /* SettingsLocalAccountView.swift */, + ); + path = Accounts; + sourceTree = ""; + }; 65ED429A235E71B40081F399 /* Products */ = { isa = PBXGroup; children = ( @@ -4984,6 +5001,7 @@ 51E4996924A8760C00B667CB /* ArticleStylesManager.swift in Sources */, 5177471E24B387E100EB0F74 /* ImageTransition.swift in Sources */, 51E498F324A8085D00B667CB /* PseudoFeed.swift in Sources */, + 65ACE48424B4779B003AE06A /* SettingsAddAccountView.swift in Sources */, 51A5769624AE617200078888 /* ArticleContainerView.swift in Sources */, 5181C5AD24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift in Sources */, 51E4996B24A8762D00B667CB /* ArticleExtractor.swift in Sources */, @@ -5027,6 +5045,7 @@ 51E4993C24A8709900B667CB /* AppDelegate.swift in Sources */, 51E498F924A8085D00B667CB /* SmartFeed.swift in Sources */, 51A576BB24AE621800078888 /* ArticleModel.swift in Sources */, + 65ACE48824B48020003AE06A /* SettingsLocalAccountView.swift in Sources */, 17930ED424AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */, 51E4995124A8734D00B667CB /* ExtensionPointManager.swift in Sources */, 51E4990C24A808C500B667CB /* AuthorAvatarDownloader.swift in Sources */, @@ -5035,6 +5054,7 @@ 51E4992124A8095000B667CB /* RSImage-Extensions.swift in Sources */, 51E4990324A808BB00B667CB /* FaviconDownloader.swift in Sources */, 172199ED24AB2E0100A31D04 /* SafariView.swift in Sources */, + 65ACE48624B477C9003AE06A /* SettingsAccountLabelView.swift in Sources */, 51E4990224A808BB00B667CB /* ColorHash.swift in Sources */, 51919FAC24AA8CCA00541E64 /* UnreadCountView.swift in Sources */, 5177476224B3BC4700EB0F74 /* SettingsAboutView.swift in Sources */,