Add buttons for hiding watched videos

Fix #448
This commit is contained in:
Arkadiusz Fal
2023-05-23 18:48:39 +02:00
parent 1e2d6cf72f
commit eed9330c0c
14 changed files with 100 additions and 22 deletions

View File

@@ -1,3 +1,4 @@
import Defaults
import Foundation
import SwiftUI
@@ -6,6 +7,18 @@ struct ContentItemView: View {
@Environment(\.listingStyle) private var listingStyle
@Environment(\.noListingDividers) private var noListingDividers
@Environment(\.hideShorts) private var hideShorts
@Default(.hideWatched) private var hideWatched
@FetchRequest private var watchRequest: FetchedResults<Watch>
init(item: ContentItem) {
self.item = item
if item.contentType == .video, let video = item.video {
_watchRequest = video.watchFetchRequest
} else {
_watchRequest = Video.fixture.watchFetchRequest
}
}
@ViewBuilder var body: some View {
if itemVisible {
@@ -26,6 +39,10 @@ struct ContentItemView: View {
}
var itemVisible: Bool {
if hideWatched, watch?.finished ?? false {
return false
}
guard hideShorts, item.contentType == .video, let video = item.video else {
return true
}
@@ -35,10 +52,10 @@ struct ContentItemView: View {
@ViewBuilder func videoItem(_ video: Video) -> some View {
if listingStyle == .cells {
VideoCell(video: video)
VideoCell(video: video, watch: watch)
} else {
let item = PlayerQueueItem(video)
PlayerQueueRow(item: item)
PlayerQueueRow(item: item, watch: watch)
.contextMenu {
VideoContextMenuView(video: video)
}
@@ -99,4 +116,8 @@ struct ContentItemView: View {
#endif
}
}
private var watch: Watch? {
watchRequest.first
}
}

View File

@@ -0,0 +1,35 @@
import Defaults
import SwiftUI
struct HideWatchedButtons: View {
@Default(.hideWatched) private var hideWatched
var body: some View {
Button {
hideWatched.toggle()
} label: {
Group {
if hideWatched {
Label("Watched: hidden", systemImage: "clock")
.help("Watched: hidden")
} else {
Label("Watched: visible", systemImage: "clock.fill")
.help("Watched: visible")
}
}
#if os(tvOS)
.font(.caption)
.imageScale(.small)
#endif
}
.transaction { t in t.disablesAnimations = true }
}
}
struct HideWatchedButtons_Previews: PreviewProvider {
static var previews: some View {
VStack {
HideWatchedButtons()
}
}
}

View File

@@ -71,6 +71,10 @@ struct PopularView: View {
ListingStyleButtons(listingStyle: $popularListingStyle)
}
ToolbarItem {
HideWatchedButtons()
}
ToolbarItem {
HideShortsButtons(hide: $hideShorts)
}
@@ -90,6 +94,7 @@ struct PopularView: View {
ListingStyleButtons(listingStyle: $popularListingStyle)
Section {
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
}
@@ -129,6 +134,7 @@ struct PopularView: View {
HStack {
Spacer()
ListingStyleButtons(listingStyle: $popularListingStyle)
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
Button {