Add hiding short videos

This commit is contained in:
Arkadiusz Fal
2023-02-25 16:42:18 +01:00
parent ef401168ec
commit 2b18f0cffa
18 changed files with 163 additions and 20 deletions

View File

@@ -5,21 +5,32 @@ struct ContentItemView: View {
let item: ContentItem
@Environment(\.listingStyle) private var listingStyle
@Environment(\.noListingDividers) private var noListingDividers
@Environment(\.hideShorts) private var hideShorts
var body: some View {
Group {
switch item.contentType {
case .video:
videoItem(item.video)
case .channel:
channelItem(item.channel)
case .playlist:
playlistItem(item.playlist)
default:
placeholderItem()
@ViewBuilder var body: some View {
if itemVisible {
Group {
switch item.contentType {
case .video:
videoItem(item.video)
case .channel:
channelItem(item.channel)
case .playlist:
playlistItem(item.playlist)
default:
placeholderItem()
}
}
.id(item.cacheKey)
}
.id(item.cacheKey)
}
var itemVisible: Bool {
guard hideShorts, item.contentType == .video, let video = item.video else {
return true
}
return !video.short
}
@ViewBuilder func videoItem(_ video: Video) -> some View {

View File

@@ -0,0 +1,33 @@
import SwiftUI
struct HideShortsButtons: View {
@Binding var hide: Bool
var body: some View {
Button {
hide.toggle()
} label: {
Group {
if hide {
Label("Short videos: hidden", systemImage: "bolt.slash.fill")
.help("Short videos: hidden")
} else {
Label("Short videos: visible", systemImage: "bolt.fill")
.help("Short videos: visible")
}
}
#if os(tvOS)
.font(.caption2)
.imageScale(.small)
#endif
}
}
}
struct HideShortsButtons_Previews: PreviewProvider {
static var previews: some View {
VStack {
HideShortsButtons(hide: .constant(true))
}
}
}

View File

@@ -10,6 +10,7 @@ struct PopularView: View {
@State private var error: RequestError?
@Default(.popularListingStyle) private var popularListingStyle
@Default(.hideShorts) private var hideShorts
var resource: Resource? {
accounts.api.popular
@@ -69,6 +70,10 @@ struct PopularView: View {
ToolbarItem {
ListingStyleButtons(listingStyle: $popularListingStyle)
}
ToolbarItem {
HideShortsButtons(hide: $hideShorts)
}
}
#else
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
@@ -84,6 +89,10 @@ struct PopularView: View {
Menu {
ListingStyleButtons(listingStyle: $popularListingStyle)
Section {
HideShortsButtons(hide: $hideShorts)
}
Section {
SettingsButtons()
}