From f8d79bb08c16463aaf9ac565342ebc85254a3af5 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 28 Feb 2023 21:17:12 +0100 Subject: [PATCH] Add browsing setting for unwatched feed Fix #383 --- Model/FeedModel.swift | 2 +- Shared/Defaults.swift | 1 + Shared/Navigation/AppSidebarSubscriptions.swift | 4 +++- Shared/Navigation/AppTabNavigation.swift | 3 ++- Shared/Navigation/Sidebar.swift | 3 ++- Shared/Settings/BrowsingSettings.swift | 7 +++++++ Shared/Settings/SettingsView.swift | 2 +- Shared/Subscriptions/ChannelsView.swift | 3 ++- 8 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Model/FeedModel.swift b/Model/FeedModel.swift index e68a79a9..db7e2cf2 100644 --- a/Model/FeedModel.swift +++ b/Model/FeedModel.swift @@ -115,7 +115,7 @@ final class FeedModel: ObservableObject, CacheModel { } func calculateUnwatchedFeed() { - guard let account = accounts.current, accounts.signedIn else { return } + guard let account = accounts.current, accounts.signedIn, Defaults[.showUnwatchedFeedBadges] else { return } let feed = cacheModel.retrieveFeed(account: account) backgroundContext.perform { [weak self] in guard let self else { return } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index ad3ca554..f7b6a51b 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -51,6 +51,7 @@ extension Defaults.Keys { #if os(iOS) static let lockPortraitWhenBrowsing = Key("lockPortraitWhenBrowsing", default: UIDevice.current.userInterfaceIdiom == .phone) #endif + static let showUnwatchedFeedBadges = Key("showUnwatchedFeedBadges", default: false) static let expandChannelDescription = Key("expandChannelDescription", default: false) static let channelOnThumbnail = Key("channelOnThumbnail", default: false) static let timeOnThumbnail = Key("timeOnThumbnail", default: true) diff --git a/Shared/Navigation/AppSidebarSubscriptions.swift b/Shared/Navigation/AppSidebarSubscriptions.swift index bc5a8262..e1d8e52c 100644 --- a/Shared/Navigation/AppSidebarSubscriptions.swift +++ b/Shared/Navigation/AppSidebarSubscriptions.swift @@ -8,6 +8,8 @@ struct AppSidebarSubscriptions: View { @ObservedObject private var subscriptions = SubscribedChannelsModel.shared @ObservedObject private var accounts = AccountsModel.shared + @Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges + var body: some View { Section(header: Text("Subscriptions")) { ForEach(subscriptions.all) { channel in @@ -26,7 +28,7 @@ struct AppSidebarSubscriptions: View { Spacer() } .backport - .badge(feedCount.unwatchedByChannelText(channel)) + .badge(showUnwatchedFeedBadges ? feedCount.unwatchedByChannelText(channel) : nil) } .contextMenu { if subscriptions.isSubscribing(channel.id) { diff --git a/Shared/Navigation/AppTabNavigation.swift b/Shared/Navigation/AppTabNavigation.swift index d527b32b..986e6b7f 100644 --- a/Shared/Navigation/AppTabNavigation.swift +++ b/Shared/Navigation/AppTabNavigation.swift @@ -13,6 +13,7 @@ struct AppTabNavigation: View { @Default(.showDocuments) private var showDocuments @Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem @Default(.visibleSections) private var visibleSections + @Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges let persistenceController = PersistenceController.shared @@ -95,7 +96,7 @@ struct AppTabNavigation: View { } .tag(TabSelection.subscriptions) .backport - .badge(feedCount.unwatchedText) + .badge(showUnwatchedFeedBadges ? feedCount.unwatchedText : nil) } private var subscriptionsVisible: Bool { diff --git a/Shared/Navigation/Sidebar.swift b/Shared/Navigation/Sidebar.swift index 99a54760..63eb2c72 100644 --- a/Shared/Navigation/Sidebar.swift +++ b/Shared/Navigation/Sidebar.swift @@ -12,6 +12,7 @@ struct Sidebar: View { #if os(iOS) @Default(.showDocuments) private var showDocuments #endif + @Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges var body: some View { ScrollViewReader { scrollView in @@ -79,7 +80,7 @@ struct Sidebar: View { .accessibility(label: Text("Subscriptions")) } .backport - .badge(feedCount.unwatchedText) + .badge(showUnwatchedFeedBadges ? feedCount.unwatchedText : nil) .contextMenu { playUnwatchedButton toggleWatchedButton diff --git a/Shared/Settings/BrowsingSettings.swift b/Shared/Settings/BrowsingSettings.swift index 8ca3779d..70d32b1a 100644 --- a/Shared/Settings/BrowsingSettings.swift +++ b/Shared/Settings/BrowsingSettings.swift @@ -7,6 +7,7 @@ struct BrowsingSettings: View { @Default(.roundedThumbnails) private var roundedThumbnails #endif @Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts + @Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges #if os(iOS) @Default(.homeRecentDocumentsItems) private var homeRecentDocumentsItems @Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing @@ -223,6 +224,12 @@ struct BrowsingSettings: View { #endif Toggle("Show anonymous accounts", isOn: $accountPickerDisplaysAnonymousAccounts) + Toggle("Show unwatched feed badges", isOn: $showUnwatchedFeedBadges) + .onChange(of: showUnwatchedFeedBadges) { newValue in + if newValue { + FeedModel.shared.calculateUnwatchedFeed() + } + } } Toggle("Open channels with description expanded", isOn: $expandChannelDescription) diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index d3034562..fedc0f29 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -243,7 +243,7 @@ struct SettingsView: View { private var windowHeight: Double { switch selection { case .browsing: - return 820 + return 840 case .player: return 450 case .controls: diff --git a/Shared/Subscriptions/ChannelsView.swift b/Shared/Subscriptions/ChannelsView.swift index 4e2f1311..ef3a87e1 100644 --- a/Shared/Subscriptions/ChannelsView.swift +++ b/Shared/Subscriptions/ChannelsView.swift @@ -9,6 +9,7 @@ struct ChannelsView: View { @ObservedObject private var feedCount = UnwatchedFeedCountModel.shared @Default(.showCacheStatus) private var showCacheStatus + @Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges var body: some View { List { @@ -26,7 +27,7 @@ struct ChannelsView: View { } } .backport - .badge(feedCount.unwatchedByChannelText(channel)) + .badge(showUnwatchedFeedBadges ? feedCount.unwatchedByChannelText(channel) : nil) } .contextMenu { if subscriptions.isSubscribing(channel.id) {