From 86b929743bb1f788f003a3dab880fe36e624adc2 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 29 Jun 2020 06:16:48 -0500 Subject: [PATCH] Add SmartFeeds to outline --- Multiplatform/Shared/SceneModel.swift | 5 ++ .../Shared/Sidebar/SidebarItem.swift | 56 +++++++++++++++++++ .../Shared/Sidebar/SidebarModel.swift | 16 ++++++ .../Shared/Sidebar/SidebarView.swift | 31 +++++----- NetNewsWire.xcodeproj/project.pbxproj | 6 ++ 5 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 Multiplatform/Shared/Sidebar/SidebarItem.swift diff --git a/Multiplatform/Shared/SceneModel.swift b/Multiplatform/Shared/SceneModel.swift index 28f8e290d..1aeec3a43 100644 --- a/Multiplatform/Shared/SceneModel.swift +++ b/Multiplatform/Shared/SceneModel.swift @@ -23,4 +23,9 @@ extension SceneModel: SidebarModelDelegate { print("**** sidebar selection changed ***") } + func unreadCount(for feed: Feed) -> Int { + // TODO: Get the count from the timeline if Feed is the current timeline + return feed.unreadCount + } + } diff --git a/Multiplatform/Shared/Sidebar/SidebarItem.swift b/Multiplatform/Shared/Sidebar/SidebarItem.swift new file mode 100644 index 000000000..f2b9abe40 --- /dev/null +++ b/Multiplatform/Shared/Sidebar/SidebarItem.swift @@ -0,0 +1,56 @@ +// +// SidebarItem.swift +// NetNewsWire +// +// Created by Maurice Parker on 6/29/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import Foundation +import RSCore +import Account + +public enum SidebarItemIdentifier: Hashable, Equatable { + case smartFeedController + case account(String) + case feed(FeedIdentifier) +} + +struct SidebarItem: Identifiable { + + var id: SidebarItemIdentifier + var represented: Any + var children: [SidebarItem]? + + var unreadCount: Int + + var nameForDisplay: String { + guard let displayNameProvider = represented as? DisplayNameProvider else { return "" } + return displayNameProvider.nameForDisplay + } + + init(_ smartFeedsController: SmartFeedsController) { + self.id = .smartFeedController + self.represented = smartFeedsController + self.children = [SidebarItem]() + self.unreadCount = 0 + } + + init(_ account: Account) { + self.id = .account(account.accountID) + self.represented = account + self.children = [SidebarItem]() + self.unreadCount = account.unreadCount + } + + init(_ feed: Feed, unreadCount: Int) { + self.id = .feed(feed.feedID!) + self.represented = feed + self.unreadCount = unreadCount + } + + mutating func addChild(_ sidebarItem: SidebarItem) { + children?.append(sidebarItem) + } + +} diff --git a/Multiplatform/Shared/Sidebar/SidebarModel.swift b/Multiplatform/Shared/Sidebar/SidebarModel.swift index a3957a4f1..1375ab87a 100644 --- a/Multiplatform/Shared/Sidebar/SidebarModel.swift +++ b/Multiplatform/Shared/Sidebar/SidebarModel.swift @@ -11,10 +11,26 @@ import Account protocol SidebarModelDelegate: class { func sidebarSelectionDidChange(_: SidebarModel, feeds: [Feed]?) + func unreadCount(for: Feed) -> Int } class SidebarModel: ObservableObject { weak var delegate: SidebarModelDelegate? + @Published var sidebarItems = [SidebarItem]() + + func rebuildSidebarItems() { + guard let delegate = delegate else { return } + var items = [SidebarItem]() + + var smartFeedControllerItem = SidebarItem(SmartFeedsController.shared) + for feed in SmartFeedsController.shared.smartFeeds { + smartFeedControllerItem.addChild(SidebarItem(feed, unreadCount: delegate.unreadCount(for: feed))) + } + items.append(smartFeedControllerItem) + + sidebarItems = items + } + } diff --git a/Multiplatform/Shared/Sidebar/SidebarView.swift b/Multiplatform/Shared/Sidebar/SidebarView.swift index bbee7b717..c6c4357ba 100644 --- a/Multiplatform/Shared/Sidebar/SidebarView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarView.swift @@ -14,23 +14,24 @@ struct SidebarView: View { @StateObject private var sidebarModel = SidebarModel() var body: some View { - Text("Sidebar") - .onAppear { - sceneModel.sidebarModel = sidebarModel - sidebarModel.delegate = sceneModel + List { + ForEach(sidebarModel.sidebarItems) { section in + Section(header: Text(section.nameForDisplay)) { + ForEach(section.children ?? [SidebarItem]()) { topItem in + OutlineGroup(topItem, children: \.children) { sidebarItem in + Text(sidebarItem.nameForDisplay) + } + } + } } + } + .navigationTitle(Text("Feeds")) + .onAppear { + sceneModel.sidebarModel = sidebarModel + sidebarModel.delegate = sceneModel + sidebarModel.rebuildSidebarItems() + } -// List { -// ForEach(canvases) { canvas in -// Section(header: Text(canvas.name)) { -// OutlineGroup(canvas.graphics, children: \.children) -// { graphic in -// GraphicRow(graphic) -// } -// } -// } -// } - } } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index c2cb8a790..fb3f19ba1 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -110,6 +110,8 @@ 513C5D0C232574DA003D4054 /* RSTree.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84C37F9520DD8CFE00CA8CF5 /* RSTree.framework */; }; 513C5D0E232574E4003D4054 /* SyncDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51554C01228B6EB50055115A /* SyncDatabase.framework */; }; 513CCF2524880C1500C55709 /* MasterFeedTableViewIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 513CCF08248808BA00C55709 /* MasterFeedTableViewIdentifier.swift */; }; + 51408B7E24A9EC6F0073CF4E /* SidebarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */; }; + 51408B7F24A9EC6F0073CF4E /* SidebarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */; }; 5141E7392373C18B0013FF27 /* WebFeedInspectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5141E7382373C18B0013FF27 /* WebFeedInspectorViewController.swift */; }; 5142192A23522B5500E07E2C /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5142192923522B5500E07E2C /* ImageViewController.swift */; }; 514219372352510100E07E2C /* ImageScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 514219362352510100E07E2C /* ImageScrollView.swift */; }; @@ -1715,6 +1717,7 @@ 513C5CEB232571C2003D4054 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; 513C5CED232571C2003D4054 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 513CCF08248808BA00C55709 /* MasterFeedTableViewIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterFeedTableViewIdentifier.swift; sourceTree = ""; }; + 51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarItem.swift; sourceTree = ""; }; 5141E7382373C18B0013FF27 /* WebFeedInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebFeedInspectorViewController.swift; sourceTree = ""; }; 5141E7552374A2890013FF27 /* DetailIconSchemeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailIconSchemeHandler.swift; sourceTree = ""; }; 5142192923522B5500E07E2C /* ImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = ""; }; @@ -2757,6 +2760,7 @@ children = ( 51E499FC24A9137600B667CB /* SidebarModel.swift */, 51E499FF24A91FC100B667CB /* SidebarView.swift */, + 51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */, ); path = Sidebar; sourceTree = ""; @@ -4607,6 +4611,7 @@ 51E4990B24A808C500B667CB /* ImageDownloader.swift in Sources */, 51E498F424A8085D00B667CB /* SmartFeedDelegate.swift in Sources */, 51E4993024A8676400B667CB /* ArticleSorter.swift in Sources */, + 51408B7E24A9EC6F0073CF4E /* SidebarItem.swift in Sources */, 51E4990A24A808C500B667CB /* FeaturedImageDownloader.swift in Sources */, 51E4993824A8680E00B667CB /* Reachability.swift in Sources */, 51E4993224A8676400B667CB /* FetchRequestQueue.swift in Sources */, @@ -4703,6 +4708,7 @@ 51E4990E24A808CC00B667CB /* HTMLMetadataDownloader.swift in Sources */, 51E498FB24A808BA00B667CB /* FaviconGenerator.swift in Sources */, 51E4996724A8760B00B667CB /* ArticleStylesManager.swift in Sources */, + 51408B7F24A9EC6F0073CF4E /* SidebarItem.swift in Sources */, 51E4996E24A8764C00B667CB /* ActivityManager.swift in Sources */, 51E4995A24A873F900B667CB /* ErrorHandler.swift in Sources */, 51E4991F24A8094300B667CB /* RSImage-AppIcons.swift in Sources */,