Unwatched videos in subscriptions

This commit is contained in:
Arkadiusz Fal
2022-12-13 00:39:50 +01:00
parent 02b30394ed
commit 8c1d900a63
8 changed files with 154 additions and 17 deletions

View File

@@ -12,7 +12,7 @@ struct AccountsView: View {
list
}
.frame(minWidth: 500, maxWidth: 800, minHeight: 350, maxHeight: 700)
.frame(minWidth: 500, maxWidth: 800, minHeight: 700, maxHeight: 1200)
#else
NavigationView {

View File

@@ -5,6 +5,7 @@ struct AppTabNavigation: View {
@ObservedObject private var accounts = AccountsModel.shared
@ObservedObject private var navigation = NavigationModel.shared
private var player = PlayerModel.shared
@ObservedObject private var feed = FeedModel.shared
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
@Default(.showHome) private var showHome
@@ -47,7 +48,12 @@ struct AppTabNavigation: View {
}
.overlay(ControlsBar(fullScreen: .constant(false)), alignment: .bottom)
}
.onAppear {
feed.calculateUnwatchedFeed()
}
.onChange(of: accounts.current) { _ in
feed.calculateUnwatchedFeed()
}
.id(accounts.current?.id ?? "")
.overlay(playlistView)
.overlay(channelView)
@@ -87,6 +93,19 @@ struct AppTabNavigation: View {
.accessibility(label: Text("Subscriptions"))
}
.tag(TabSelection.subscriptions)
.backport
.badge(subscriptionsBadge)
}
var subscriptionsBadge: Text? {
guard let account = accounts.current,
let unwatched = feed.unwatched[account],
unwatched > 0
else {
return nil
}
return Text("\(String(unwatched))")
}
private var subscriptionsVisible: Bool {

View File

@@ -4,6 +4,7 @@ import SwiftUI
struct Sidebar: View {
@ObservedObject private var accounts = AccountsModel.shared
@ObservedObject private var navigation = NavigationModel.shared
@ObservedObject private var feed = FeedModel.shared
@Default(.showHome) private var showHome
@Default(.visibleSections) private var visibleSections
@@ -36,6 +37,12 @@ struct Sidebar: View {
}
.listStyle(.sidebar)
}
.onAppear {
feed.calculateUnwatchedFeed()
}
.onChange(of: accounts.current) { _ in
feed.calculateUnwatchedFeed()
}
.navigationTitle("Yattee")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
@@ -70,6 +77,8 @@ struct Sidebar: View {
Label("Subscriptions", systemImage: "star.circle")
.accessibility(label: Text("Subscriptions"))
}
.backport
.badge(subscriptionsBadge)
.id("subscriptions")
}
@@ -99,6 +108,17 @@ struct Sidebar: View {
}
}
private var subscriptionsBadge: Text? {
guard let account = accounts.current,
let unwatched = feed.unwatched[account],
unwatched > 0
else {
return nil
}
return Text("\(String(unwatched))")
}
private func scrollScrollViewToItem(scrollView: ScrollViewProxy, for selection: TabSelection) {
if case .recentlyOpened = selection {
scrollView.scrollTo("recentlyOpened")

View File

@@ -90,7 +90,7 @@ struct PlayerQueueRow: View {
player.show()
} label: {
VideoBanner(video: item.video, playbackTime: watchStoppedAt, videoDuration: watch?.videoDuration)
VideoBanner(video: item.video, playbackTime: watchStoppedAt, videoDuration: watch?.videoDuration, watch: watch)
}
#if os(tvOS)
.buttonStyle(.card)

View File

@@ -10,6 +10,8 @@ struct SubscriptionsView: View {
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
@ObservedObject private var feed = FeedModel.shared
var body: some View {
SignInRequiredView(title: "Subscriptions".localized()) {
switch subscriptionsViewPage {
@@ -51,6 +53,24 @@ 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")
}
}
Section {

View File

@@ -149,6 +149,7 @@ struct VideoContextMenuView: View {
var markAsWatchedButton: some View {
Button {
Watch.markAsWatched(videoID: video.videoID, account: accounts.current, duration: video.length, context: backgroundContext)
FeedModel.shared.calculateUnwatchedFeed()
} label: {
Label("Mark as watched", systemImage: "checkmark.circle.fill")
}
@@ -156,11 +157,9 @@ struct VideoContextMenuView: View {
var removeFromHistoryButton: some View {
Button {
guard let watch else {
return
}
guard let watch else { return }
player.removeWatch(watch)
FeedModel.shared.calculateUnwatchedFeed()
} label: {
Label("Remove from history", systemImage: "delete.left.fill")
}