mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
@@ -102,6 +102,7 @@ struct ChannelPlaylistView: View {
|
||||
ToolbarItem(placement: playlistButtonsPlacement) {
|
||||
HStack {
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
ShareButton(contentItem: contentItem)
|
||||
|
||||
@@ -131,6 +132,7 @@ struct ChannelPlaylistView: View {
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
|
||||
Section {
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
|
@@ -137,6 +137,7 @@ struct ChannelVideosView: View {
|
||||
}
|
||||
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
contentTypePicker
|
||||
}
|
||||
@@ -281,6 +282,7 @@ struct ChannelVideosView: View {
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
|
||||
Section {
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
}
|
||||
|
@@ -256,6 +256,7 @@ extension Defaults.Keys {
|
||||
static let channelPlaylistListingStyle = Key<ListingStyle>("channelPlaylistListingStyle", default: .cells)
|
||||
static let searchListingStyle = Key<ListingStyle>("searchListingStyle", default: .cells)
|
||||
static let hideShorts = Key<Bool>("hideShorts", default: false)
|
||||
static let hideWatched = Key<Bool>("hideWatched", default: false)
|
||||
static let showInspector = Key<ShowInspectorSetting>("showInspector", default: .onlyLocal)
|
||||
}
|
||||
|
||||
|
@@ -7,22 +7,17 @@ struct PlayerQueueRow: View {
|
||||
let item: PlayerQueueItem
|
||||
var history = false
|
||||
var autoplay = false
|
||||
var watch: Watch?
|
||||
|
||||
private var player = PlayerModel.shared
|
||||
|
||||
@Default(.closePiPOnNavigation) var closePiPOnNavigation
|
||||
|
||||
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
||||
|
||||
init(item: PlayerQueueItem, history: Bool = false, autoplay: Bool = false) {
|
||||
init(item: PlayerQueueItem, history: Bool = false, autoplay: Bool = false, watch: Watch? = nil) {
|
||||
self.item = item
|
||||
self.history = history
|
||||
self.autoplay = autoplay
|
||||
_watchRequest = FetchRequest<Watch>(
|
||||
entity: Watch.entity(),
|
||||
sortDescriptors: [],
|
||||
predicate: NSPredicate(format: "videoID = %@", item.videoID)
|
||||
)
|
||||
self.watch = watch
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -80,10 +75,6 @@ struct PlayerQueueRow: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
private var watch: Watch? {
|
||||
watchRequest.first
|
||||
}
|
||||
|
||||
private var watchStoppedAt: CMTime? {
|
||||
guard let seconds = watch?.stoppedAt else {
|
||||
return nil
|
||||
|
@@ -145,6 +145,9 @@ struct PlaylistsView: View {
|
||||
ToolbarItem {
|
||||
ListingStyleButtons(listingStyle: $playlistListingStyle)
|
||||
}
|
||||
ToolbarItem {
|
||||
HideWatchedButtons()
|
||||
}
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
@@ -216,6 +219,7 @@ struct PlaylistsView: View {
|
||||
ListingStyleButtons(listingStyle: $playlistListingStyle)
|
||||
|
||||
Section {
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
@@ -386,6 +390,7 @@ struct PlaylistsView: View {
|
||||
Spacer()
|
||||
|
||||
ListingStyleButtons(listingStyle: $playlistListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
#else
|
||||
Spacer()
|
||||
|
@@ -76,6 +76,7 @@ struct SearchView: View {
|
||||
#if os(macOS)
|
||||
ToolbarItemGroup(placement: toolbarPlacement) {
|
||||
ListingStyleButtons(listingStyle: $searchListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
FavoriteButton(item: favoriteItem)
|
||||
.id(favoriteItem?.id)
|
||||
@@ -214,6 +215,7 @@ struct SearchView: View {
|
||||
ListingStyleButtons(listingStyle: $searchListingStyle)
|
||||
|
||||
Section {
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
@@ -571,6 +573,7 @@ struct SearchView: View {
|
||||
|
||||
Spacer()
|
||||
ListingStyleButtons(listingStyle: $searchListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
.labelStyle(.iconOnly)
|
||||
|
@@ -54,6 +54,7 @@ struct FeedView: View {
|
||||
#if os(tvOS)
|
||||
SubscriptionsPageButton()
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
#endif
|
||||
|
||||
|
@@ -46,6 +46,7 @@ struct SubscriptionsView: View {
|
||||
.toolbar {
|
||||
ToolbarItemGroup {
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
toggleWatchedButton
|
||||
.id(feed.watchedId)
|
||||
@@ -73,6 +74,7 @@ struct SubscriptionsView: View {
|
||||
}
|
||||
|
||||
Section {
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
|
@@ -123,6 +123,10 @@ struct TrendingView: View {
|
||||
ListingStyleButtons(listingStyle: $trendingListingStyle)
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
HideWatchedButtons()
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
@@ -174,6 +178,7 @@ struct TrendingView: View {
|
||||
ListingStyleButtons(listingStyle: $trendingListingStyle)
|
||||
|
||||
Section {
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
@@ -247,6 +252,7 @@ struct TrendingView: View {
|
||||
|
||||
Spacer()
|
||||
ListingStyleButtons(listingStyle: $trendingListingStyle)
|
||||
HideWatchedButtons()
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
|
||||
Button {
|
||||
|
@@ -6,6 +6,7 @@ import SwiftUI
|
||||
struct VideoCell: View {
|
||||
var id: String?
|
||||
private var video: Video
|
||||
private var watch: Watch?
|
||||
|
||||
@Environment(\.horizontalCells) private var horizontalCells
|
||||
@Environment(\.inChannelView) private var inChannelView
|
||||
@@ -27,12 +28,10 @@ struct VideoCell: View {
|
||||
private var navigation: NavigationModel { .shared }
|
||||
private var player: PlayerModel { .shared }
|
||||
|
||||
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
||||
|
||||
init(id: String? = nil, video: Video) {
|
||||
init(id: String? = nil, video: Video, watch: Watch? = nil) {
|
||||
self.id = id
|
||||
self.video = video
|
||||
_watchRequest = video.watchFetchRequest
|
||||
self.watch = watch
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -107,10 +106,6 @@ struct VideoCell: View {
|
||||
watchedVideoPlayNowBehavior == .continue
|
||||
}
|
||||
|
||||
private var watch: Watch? {
|
||||
watchRequest.first
|
||||
}
|
||||
|
||||
private var finished: Bool {
|
||||
watch?.finished ?? false
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
35
Shared/Views/HideWatchedButtons.swift
Normal file
35
Shared/Views/HideWatchedButtons.swift
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user