Add unread counts to Sidebar
This commit is contained in:
parent
29b5f426fd
commit
61ad0fbfa4
@ -18,7 +18,7 @@ struct SceneNavigationView: View {
|
|||||||
NavigationView {
|
NavigationView {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
RegularSidebarContainerView()
|
RegularSidebarContainerView()
|
||||||
.frame(minWidth: 100, idealWidth: 150, maxWidth: 200, maxHeight: .infinity)
|
.frame(minWidth: 100, idealWidth: 150, maxHeight: .infinity)
|
||||||
#else
|
#else
|
||||||
if horizontalSizeClass == .compact {
|
if horizontalSizeClass == .compact {
|
||||||
CompactSidebarContainerView()
|
CompactSidebarContainerView()
|
||||||
|
@ -47,6 +47,9 @@ struct SidebarItem: Identifiable {
|
|||||||
self.id = .feed(feed.feedID!)
|
self.id = .feed(feed.feedID!)
|
||||||
self.represented = feed
|
self.represented = feed
|
||||||
self.unreadCount = unreadCount
|
self.unreadCount = unreadCount
|
||||||
|
if let container = feed as? Container, container.hasAtLeastOneWebFeed() {
|
||||||
|
self.children = [SidebarItem]()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func addChild(_ sidebarItem: SidebarItem) {
|
mutating func addChild(_ sidebarItem: SidebarItem) {
|
||||||
|
25
Multiplatform/Shared/Sidebar/SidebarItemView.swift
Normal file
25
Multiplatform/Shared/Sidebar/SidebarItemView.swift
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// SidebarItemView.swift
|
||||||
|
// NetNewsWire
|
||||||
|
//
|
||||||
|
// Created by Maurice Parker on 6/29/20.
|
||||||
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct SidebarItemView: View {
|
||||||
|
|
||||||
|
var sidebarItem: SidebarItem
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
Text(verbatim: sidebarItem.nameForDisplay)
|
||||||
|
Spacer()
|
||||||
|
if sidebarItem.unreadCount > 0 {
|
||||||
|
UnreadCountView(count: sidebarItem.unreadCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import RSCore
|
||||||
import Account
|
import Account
|
||||||
|
|
||||||
protocol SidebarModelDelegate: class {
|
protocol SidebarModelDelegate: class {
|
||||||
@ -20,6 +21,12 @@ class SidebarModel: ObservableObject {
|
|||||||
|
|
||||||
@Published var sidebarItems = [SidebarItem]()
|
@Published var sidebarItems = [SidebarItem]()
|
||||||
|
|
||||||
|
init() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: API
|
||||||
|
|
||||||
func rebuildSidebarItems() {
|
func rebuildSidebarItems() {
|
||||||
guard let delegate = delegate else { return }
|
guard let delegate = delegate else { return }
|
||||||
var items = [SidebarItem]()
|
var items = [SidebarItem]()
|
||||||
@ -33,13 +40,13 @@ class SidebarModel: ObservableObject {
|
|||||||
for account in AccountManager.shared.sortedActiveAccounts {
|
for account in AccountManager.shared.sortedActiveAccounts {
|
||||||
var accountItem = SidebarItem(account)
|
var accountItem = SidebarItem(account)
|
||||||
|
|
||||||
for webFeed in account.topLevelWebFeeds {
|
for webFeed in sort(account.topLevelWebFeeds) {
|
||||||
accountItem.addChild(SidebarItem(webFeed, unreadCount: delegate.unreadCount(for: webFeed)))
|
accountItem.addChild(SidebarItem(webFeed, unreadCount: delegate.unreadCount(for: webFeed)))
|
||||||
}
|
}
|
||||||
|
|
||||||
for folder in account.folders ?? Set<Folder>() {
|
for folder in sort(account.folders ?? Set<Folder>()) {
|
||||||
var folderItem = SidebarItem(folder, unreadCount: delegate.unreadCount(for: folder))
|
var folderItem = SidebarItem(folder, unreadCount: delegate.unreadCount(for: folder))
|
||||||
for webFeed in folder.topLevelWebFeeds {
|
for webFeed in sort(folder.topLevelWebFeeds) {
|
||||||
folderItem.addChild(SidebarItem(webFeed, unreadCount: delegate.unreadCount(for: webFeed)))
|
folderItem.addChild(SidebarItem(webFeed, unreadCount: delegate.unreadCount(for: webFeed)))
|
||||||
}
|
}
|
||||||
accountItem.addChild(folderItem)
|
accountItem.addChild(folderItem)
|
||||||
@ -52,3 +59,23 @@ class SidebarModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Private
|
||||||
|
private extension SidebarModel {
|
||||||
|
|
||||||
|
@objc func unreadCountDidInitialize(_ notification: Notification) {
|
||||||
|
guard notification.object is AccountManager else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rebuildSidebarItems()
|
||||||
|
}
|
||||||
|
|
||||||
|
func sort(_ folders: Set<Folder>) -> [Folder] {
|
||||||
|
return folders.sorted(by: { $0.nameForDisplay.localizedStandardCompare($1.nameForDisplay) == .orderedAscending })
|
||||||
|
}
|
||||||
|
|
||||||
|
func sort(_ feeds: Set<WebFeed>) -> [Feed] {
|
||||||
|
return feeds.sorted(by: { $0.nameForDisplay.localizedStandardCompare($1.nameForDisplay) == .orderedAscending })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ struct SidebarView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
OutlineGroup(sidebarModel.sidebarItems, children: \.children) { sidebarItem in
|
OutlineGroup(sidebarModel.sidebarItems, children: \.children) { sidebarItem in
|
||||||
Text(sidebarItem.nameForDisplay)
|
SidebarItemView(sidebarItem: sidebarItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
Multiplatform/Shared/Sidebar/UnreadCountView.swift
Normal file
27
Multiplatform/Shared/Sidebar/UnreadCountView.swift
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// UnreadCountView.swift
|
||||||
|
// NetNewsWire
|
||||||
|
//
|
||||||
|
// Created by Maurice Parker on 6/29/20.
|
||||||
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct UnreadCountView: View {
|
||||||
|
|
||||||
|
var count: Int
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Text(verbatim: String(count))
|
||||||
|
.padding(.horizontal, 7)
|
||||||
|
.background(SwiftUI.Color.gray.opacity(0.5))
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UnreadCountView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
UnreadCountView(count: 123)
|
||||||
|
}
|
||||||
|
}
|
@ -208,6 +208,10 @@
|
|||||||
518ED21D23D0F26000E0A862 /* UIViewController-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518ED21C23D0F26000E0A862 /* UIViewController-Extensions.swift */; };
|
518ED21D23D0F26000E0A862 /* UIViewController-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518ED21C23D0F26000E0A862 /* UIViewController-Extensions.swift */; };
|
||||||
51919FA624AA64B000541E64 /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FA524AA64B000541E64 /* SidebarView.swift */; };
|
51919FA624AA64B000541E64 /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FA524AA64B000541E64 /* SidebarView.swift */; };
|
||||||
51919FA724AA64B000541E64 /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FA524AA64B000541E64 /* SidebarView.swift */; };
|
51919FA724AA64B000541E64 /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FA524AA64B000541E64 /* SidebarView.swift */; };
|
||||||
|
51919FAC24AA8CCA00541E64 /* UnreadCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */; };
|
||||||
|
51919FAD24AA8CCA00541E64 /* UnreadCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */; };
|
||||||
|
51919FAF24AA8EFA00541E64 /* SidebarItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */; };
|
||||||
|
51919FB024AA8EFA00541E64 /* SidebarItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */; };
|
||||||
51934CCB230F599B006127BE /* InteractiveNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CC1230F5963006127BE /* InteractiveNavigationController.swift */; };
|
51934CCB230F599B006127BE /* InteractiveNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CC1230F5963006127BE /* InteractiveNavigationController.swift */; };
|
||||||
51934CCE2310792F006127BE /* ActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CCD2310792F006127BE /* ActivityManager.swift */; };
|
51934CCE2310792F006127BE /* ActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CCD2310792F006127BE /* ActivityManager.swift */; };
|
||||||
51938DF2231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51938DF1231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift */; };
|
51938DF2231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51938DF1231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift */; };
|
||||||
@ -1797,6 +1801,8 @@
|
|||||||
518B2EE92351B4C200400001 /* NetNewsWire_iOSTests_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_iOSTests_target.xcconfig; sourceTree = "<group>"; };
|
518B2EE92351B4C200400001 /* NetNewsWire_iOSTests_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_iOSTests_target.xcconfig; sourceTree = "<group>"; };
|
||||||
518ED21C23D0F26000E0A862 /* UIViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController-Extensions.swift"; sourceTree = "<group>"; };
|
518ED21C23D0F26000E0A862 /* UIViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController-Extensions.swift"; sourceTree = "<group>"; };
|
||||||
51919FA524AA64B000541E64 /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
|
51919FA524AA64B000541E64 /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
|
||||||
|
51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnreadCountView.swift; sourceTree = "<group>"; };
|
||||||
|
51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarItemView.swift; sourceTree = "<group>"; };
|
||||||
51934CC1230F5963006127BE /* InteractiveNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InteractiveNavigationController.swift; sourceTree = "<group>"; };
|
51934CC1230F5963006127BE /* InteractiveNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InteractiveNavigationController.swift; sourceTree = "<group>"; };
|
||||||
51934CCD2310792F006127BE /* ActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityManager.swift; sourceTree = "<group>"; };
|
51934CCD2310792F006127BE /* ActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityManager.swift; sourceTree = "<group>"; };
|
||||||
51938DF1231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchTimelineFeedDelegate.swift; sourceTree = "<group>"; };
|
51938DF1231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchTimelineFeedDelegate.swift; sourceTree = "<group>"; };
|
||||||
@ -2810,6 +2816,8 @@
|
|||||||
51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */,
|
51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */,
|
||||||
51E499FC24A9137600B667CB /* SidebarModel.swift */,
|
51E499FC24A9137600B667CB /* SidebarModel.swift */,
|
||||||
51919FA524AA64B000541E64 /* SidebarView.swift */,
|
51919FA524AA64B000541E64 /* SidebarView.swift */,
|
||||||
|
51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */,
|
||||||
|
51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */,
|
||||||
);
|
);
|
||||||
path = Sidebar;
|
path = Sidebar;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -4650,6 +4658,7 @@
|
|||||||
51E498F124A8085D00B667CB /* StarredFeedDelegate.swift in Sources */,
|
51E498F124A8085D00B667CB /* StarredFeedDelegate.swift in Sources */,
|
||||||
51E498FF24A808BB00B667CB /* SingleFaviconDownloader.swift in Sources */,
|
51E498FF24A808BB00B667CB /* SingleFaviconDownloader.swift in Sources */,
|
||||||
51E4997224A8784300B667CB /* DefaultFeedsImporter.swift in Sources */,
|
51E4997224A8784300B667CB /* DefaultFeedsImporter.swift in Sources */,
|
||||||
|
51919FAF24AA8EFA00541E64 /* SidebarItemView.swift in Sources */,
|
||||||
51E4990D24A808C500B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
|
51E4990D24A808C500B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
|
||||||
51E49A0024A91FC100B667CB /* RegularSidebarContainerView.swift in Sources */,
|
51E49A0024A91FC100B667CB /* RegularSidebarContainerView.swift in Sources */,
|
||||||
51E4995C24A875F300B667CB /* ArticleRenderer.swift in Sources */,
|
51E4995C24A875F300B667CB /* ArticleRenderer.swift in Sources */,
|
||||||
@ -4699,6 +4708,7 @@
|
|||||||
51E4992124A8095000B667CB /* RSImage-Extensions.swift in Sources */,
|
51E4992124A8095000B667CB /* RSImage-Extensions.swift in Sources */,
|
||||||
51E4990324A808BB00B667CB /* FaviconDownloader.swift in Sources */,
|
51E4990324A808BB00B667CB /* FaviconDownloader.swift in Sources */,
|
||||||
51E4990224A808BB00B667CB /* ColorHash.swift in Sources */,
|
51E4990224A808BB00B667CB /* ColorHash.swift in Sources */,
|
||||||
|
51919FAC24AA8CCA00541E64 /* UnreadCountView.swift in Sources */,
|
||||||
51E4991924A8090A00B667CB /* CacheCleaner.swift in Sources */,
|
51E4991924A8090A00B667CB /* CacheCleaner.swift in Sources */,
|
||||||
51E498F724A8085D00B667CB /* SearchTimelineFeedDelegate.swift in Sources */,
|
51E498F724A8085D00B667CB /* SearchTimelineFeedDelegate.swift in Sources */,
|
||||||
51E4993524A867E800B667CB /* AppNotifications.swift in Sources */,
|
51E4993524A867E800B667CB /* AppNotifications.swift in Sources */,
|
||||||
@ -4723,6 +4733,7 @@
|
|||||||
51E4994B24A8734C00B667CB /* SendToMicroBlogCommand.swift in Sources */,
|
51E4994B24A8734C00B667CB /* SendToMicroBlogCommand.swift in Sources */,
|
||||||
51E4996F24A8764C00B667CB /* ActivityType.swift in Sources */,
|
51E4996F24A8764C00B667CB /* ActivityType.swift in Sources */,
|
||||||
51E4994E24A8734C00B667CB /* SendToMarsEditCommand.swift in Sources */,
|
51E4994E24A8734C00B667CB /* SendToMarsEditCommand.swift in Sources */,
|
||||||
|
51919FB024AA8EFA00541E64 /* SidebarItemView.swift in Sources */,
|
||||||
51E4996624A8760B00B667CB /* ArticleStyle.swift in Sources */,
|
51E4996624A8760B00B667CB /* ArticleStyle.swift in Sources */,
|
||||||
51E4996C24A8762D00B667CB /* ExtractedArticle.swift in Sources */,
|
51E4996C24A8762D00B667CB /* ExtractedArticle.swift in Sources */,
|
||||||
51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
|
51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
|
||||||
@ -4745,6 +4756,7 @@
|
|||||||
1729529724AA1CD000D65E66 /* MacPreferencesView.swift in Sources */,
|
1729529724AA1CD000D65E66 /* MacPreferencesView.swift in Sources */,
|
||||||
51E4994C24A8734C00B667CB /* RedditFeedProvider-Extensions.swift in Sources */,
|
51E4994C24A8734C00B667CB /* RedditFeedProvider-Extensions.swift in Sources */,
|
||||||
1729529324AA1CAA00D65E66 /* AccountsPreferencesView.swift in Sources */,
|
1729529324AA1CAA00D65E66 /* AccountsPreferencesView.swift in Sources */,
|
||||||
|
51919FAD24AA8CCA00541E64 /* UnreadCountView.swift in Sources */,
|
||||||
51E4994124A8713B00B667CB /* RefreshInterval.swift in Sources */,
|
51E4994124A8713B00B667CB /* RefreshInterval.swift in Sources */,
|
||||||
51E498C924A8085D00B667CB /* PseudoFeed.swift in Sources */,
|
51E498C924A8085D00B667CB /* PseudoFeed.swift in Sources */,
|
||||||
51E498FC24A808BA00B667CB /* FaviconURLFinder.swift in Sources */,
|
51E498FC24A808BA00B667CB /* FaviconURLFinder.swift in Sources */,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user