mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
@@ -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