mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Show badge for channels subscriptions
This commit is contained in:
@@ -3,24 +3,29 @@ import SwiftUI
|
||||
|
||||
struct AppSidebarSubscriptions: View {
|
||||
@ObservedObject private var navigation = NavigationModel.shared
|
||||
@ObservedObject private var feed = FeedModel.shared
|
||||
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var body: some View {
|
||||
Section(header: Text("Subscriptions")) {
|
||||
ForEach(subscriptions.all) { channel in
|
||||
NavigationLink(tag: TabSelection.channel(channel.id), selection: $navigation.tabSelection) {
|
||||
LazyView(ChannelVideosView(channel: channel).modifier(PlayerOverlayModifier()))
|
||||
} label: {
|
||||
if channel.thumbnailURL != nil {
|
||||
HStack {
|
||||
HStack {
|
||||
if channel.thumbnailURL != nil {
|
||||
ChannelAvatarView(channel: channel, subscribedBadge: false)
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text(channel.name)
|
||||
} else {
|
||||
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
|
||||
}
|
||||
} else {
|
||||
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
|
||||
}
|
||||
.backport
|
||||
.badge(channelBadge(channel))
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Unsubscribe") {
|
||||
@@ -31,6 +36,14 @@ struct AppSidebarSubscriptions: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelBadge(_ channel: Channel) -> Text? {
|
||||
if let count = feed.unwatchedByChannel[accounts.current]?[channel.id] {
|
||||
return Text(String(count))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
struct AppSidebarSubscriptions_Previews: PreviewProvider {
|
||||
|
@@ -3,6 +3,7 @@ import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelsView: View {
|
||||
@ObservedObject private var feed = FeedModel.shared
|
||||
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
@@ -23,6 +24,8 @@ struct ChannelsView: View {
|
||||
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
|
||||
}
|
||||
}
|
||||
.backport
|
||||
.badge(channelBadge(channel))
|
||||
}
|
||||
.contextMenu {
|
||||
Button {
|
||||
@@ -78,6 +81,14 @@ struct ChannelsView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
func channelBadge(_ channel: Channel) -> Text? {
|
||||
if let count = feed.unwatchedByChannel[accounts.current]?[channel.id] {
|
||||
return Text(String(count))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var header: some View {
|
||||
HStack {
|
||||
#if os(tvOS)
|
||||
|
@@ -39,6 +39,10 @@ struct SubscriptionsView: View {
|
||||
ToolbarItem {
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
toggleWatchedButton
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -53,26 +57,12 @@ struct SubscriptionsView: View {
|
||||
|
||||
if subscriptionsViewPage == .feed {
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
|
||||
Button {
|
||||
feed.playUnwatchedFeed()
|
||||
} label: {
|
||||
Label("Play unwatched", systemImage: "play")
|
||||
}
|
||||
|
||||
Button {
|
||||
feed.markAllFeedAsWatched()
|
||||
} label: {
|
||||
Label("Mark all as watched", systemImage: "checkmark.circle.fill")
|
||||
}
|
||||
|
||||
Button {
|
||||
feed.markAllFeedAsUnwatched()
|
||||
} label: {
|
||||
Label("Mark all as unwatched", systemImage: "checkmark.circle")
|
||||
}
|
||||
}
|
||||
|
||||
playUnwatchedButton
|
||||
|
||||
toggleWatchedButton
|
||||
|
||||
Section {
|
||||
SettingsButtons()
|
||||
}
|
||||
@@ -98,6 +88,40 @@ struct SubscriptionsView: View {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
var playUnwatchedButton: some View {
|
||||
Button {
|
||||
feed.playUnwatchedFeed()
|
||||
} label: {
|
||||
Label("Play all unwatched", systemImage: "play")
|
||||
}
|
||||
.disabled(!feed.canPlayUnwatchedFeed)
|
||||
}
|
||||
|
||||
@ViewBuilder var toggleWatchedButton: some View {
|
||||
if feed.canMarkAllFeedAsWatched {
|
||||
markAllFeedAsWatchedButton
|
||||
} else {
|
||||
markAllFeedAsUnwatchedButton
|
||||
}
|
||||
}
|
||||
|
||||
var markAllFeedAsWatchedButton: some View {
|
||||
Button {
|
||||
feed.markAllFeedAsWatched()
|
||||
} label: {
|
||||
Label("Mark all as watched", systemImage: "checkmark.circle.fill")
|
||||
}
|
||||
.disabled(!feed.canMarkAllFeedAsWatched)
|
||||
}
|
||||
|
||||
var markAllFeedAsUnwatchedButton: some View {
|
||||
Button {
|
||||
feed.markAllFeedAsUnwatched()
|
||||
} label: {
|
||||
Label("Mark all as unwatched", systemImage: "checkmark.circle")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriptionsView_Previews: PreviewProvider {
|
||||
|
Reference in New Issue
Block a user