mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add hiding short videos
This commit is contained in:
@@ -14,6 +14,7 @@ struct ChannelPlaylistView: View {
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
@Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
var player = PlayerModel.shared
|
||||
@@ -104,6 +105,7 @@ struct ChannelPlaylistView: View {
|
||||
ToolbarItem(placement: playlistButtonsPlacement) {
|
||||
HStack {
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
ShareButton(contentItem: contentItem)
|
||||
|
||||
favoriteButton
|
||||
@@ -131,6 +133,10 @@ struct ChannelPlaylistView: View {
|
||||
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
Section {
|
||||
SettingsButtons()
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ struct ChannelVideosView: View {
|
||||
|
||||
@Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle
|
||||
@Default(.expandChannelDescription) private var expandChannelDescription
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
var presentedChannel: Channel? {
|
||||
store.item ?? channel ?? recents.presentedChannel
|
||||
@@ -100,6 +101,7 @@ struct ChannelVideosView: View {
|
||||
}
|
||||
.environment(\.inChannelView, true)
|
||||
.environment(\.listingStyle, channelPlaylistListingStyle)
|
||||
.environment(\.hideShorts, hideShorts)
|
||||
#if os(tvOS)
|
||||
.prefersDefaultFocus(in: focusNamespace)
|
||||
#endif
|
||||
@@ -131,6 +133,9 @@ struct ChannelVideosView: View {
|
||||
ToolbarItem {
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
}
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
ToolbarItem {
|
||||
contentTypePicker
|
||||
}
|
||||
@@ -271,6 +276,10 @@ struct ChannelVideosView: View {
|
||||
}
|
||||
|
||||
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 12) {
|
||||
|
@@ -238,6 +238,8 @@ extension Defaults.Keys {
|
||||
static let openWatchNextOnFinishedWatching = Key<Bool>("openWatchNextOnFinishedWatching", default: true)
|
||||
static let openWatchNextOnClose = Key<Bool>("openWatchNextOnClose", default: false)
|
||||
static let openWatchNextOnFinishedWatchingDelay = Key<String>("openWatchNextOnFinishedWatchingDelay", default: "5")
|
||||
|
||||
static let hideShorts = Key<Bool>("hideShorts", default: false)
|
||||
}
|
||||
|
||||
enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {
|
||||
|
@@ -66,6 +66,10 @@ private struct ScrollViewBottomPaddingKey: EnvironmentKey {
|
||||
static let defaultValue: Double = 30
|
||||
}
|
||||
|
||||
private struct HideShortsKey: EnvironmentKey {
|
||||
static let defaultValue = false
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
var inChannelView: Bool {
|
||||
get { self[InChannelViewKey.self] }
|
||||
@@ -121,4 +125,9 @@ extension EnvironmentValues {
|
||||
get { self[NoListingDividersKey.self] }
|
||||
set { self[NoListingDividersKey.self] = newValue }
|
||||
}
|
||||
|
||||
var hideShorts: Bool {
|
||||
get { self[HideShortsKey.self] }
|
||||
set { self[HideShortsKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ struct PlaylistsView: View {
|
||||
|
||||
@Default(.playlistListingStyle) private var playlistListingStyle
|
||||
@Default(.showCacheStatus) private var showCacheStatus
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
var items: [ContentItem] {
|
||||
var videos = currentPlaylist?.videos ?? []
|
||||
@@ -95,6 +96,7 @@ struct PlaylistsView: View {
|
||||
}
|
||||
.environment(\.currentPlaylistID, currentPlaylist?.id)
|
||||
.environment(\.listingStyle, playlistListingStyle)
|
||||
.environment(\.hideShorts, hideShorts)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,6 +169,9 @@ struct PlaylistsView: View {
|
||||
ToolbarItem {
|
||||
ListingStyleButtons(listingStyle: $playlistListingStyle)
|
||||
}
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
}
|
||||
#else
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
@@ -234,6 +239,10 @@ struct PlaylistsView: View {
|
||||
|
||||
ListingStyleButtons(listingStyle: $playlistListingStyle)
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
Section {
|
||||
SettingsButtons()
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ struct SearchView: View {
|
||||
@Default(.saveRecents) private var saveRecents
|
||||
@Default(.showHome) private var showHome
|
||||
@Default(.searchListingStyle) private var searchListingStyle
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
private var videos = [Video]()
|
||||
|
||||
@@ -70,10 +71,12 @@ struct SearchView: View {
|
||||
#endif
|
||||
}
|
||||
.environment(\.listingStyle, searchListingStyle)
|
||||
.environment(\.hideShorts, hideShorts)
|
||||
.toolbar {
|
||||
#if os(macOS)
|
||||
ToolbarItemGroup(placement: toolbarPlacement) {
|
||||
ListingStyleButtons(listingStyle: $searchListingStyle)
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
FavoriteButton(item: favoriteItem)
|
||||
.id(favoriteItem?.id)
|
||||
|
||||
@@ -210,6 +213,10 @@ struct SearchView: View {
|
||||
|
||||
ListingStyleButtons(listingStyle: $searchListingStyle)
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
Section {
|
||||
SettingsButtons()
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ struct FeedView: View {
|
||||
|
||||
#if os(tvOS)
|
||||
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
#endif
|
||||
|
||||
var videos: [ContentItem] {
|
||||
@@ -54,6 +55,7 @@ struct FeedView: View {
|
||||
#if os(tvOS)
|
||||
SubscriptionsPageButton()
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
#endif
|
||||
|
||||
if showCacheStatus {
|
||||
@@ -82,6 +84,7 @@ struct FeedView: View {
|
||||
.padding(.leading, 30)
|
||||
#if os(tvOS)
|
||||
.padding(.bottom, 15)
|
||||
.padding(.trailing, 30)
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -94,7 +97,7 @@ struct FeedView: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriptonsView_Previews: PreviewProvider {
|
||||
struct FeedView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
FeedView()
|
||||
|
@@ -10,6 +10,7 @@ struct SubscriptionsView: View {
|
||||
|
||||
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
|
||||
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
@ObservedObject private var feed = FeedModel.shared
|
||||
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
||||
@@ -27,6 +28,7 @@ struct SubscriptionsView: View {
|
||||
}
|
||||
}
|
||||
.environment(\.listingStyle, subscriptionsListingStyle)
|
||||
.environment(\.hideShorts, hideShorts)
|
||||
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@@ -46,6 +48,10 @@ struct SubscriptionsView: View {
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
toggleWatchedButton
|
||||
}
|
||||
@@ -73,6 +79,10 @@ struct SubscriptionsView: View {
|
||||
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
||||
}
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
playUnwatchedButton
|
||||
|
||||
toggleWatchedButton
|
||||
|
@@ -10,6 +10,7 @@ struct TrendingView: View {
|
||||
@Default(.trendingCountry) private var country
|
||||
|
||||
@Default(.trendingListingStyle) private var trendingListingStyle
|
||||
@Default(.hideShorts) private var hideShorts
|
||||
|
||||
@State private var presentingCountrySelection = false
|
||||
|
||||
@@ -51,6 +52,7 @@ struct TrendingView: View {
|
||||
#endif
|
||||
}
|
||||
.environment(\.listingStyle, trendingListingStyle)
|
||||
.environment(\.hideShorts, hideShorts)
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
@@ -133,6 +135,10 @@ struct TrendingView: View {
|
||||
ToolbarItem {
|
||||
ListingStyleButtons(listingStyle: $trendingListingStyle)
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
}
|
||||
#else
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
@@ -182,6 +188,10 @@ struct TrendingView: View {
|
||||
|
||||
ListingStyleButtons(listingStyle: $trendingListingStyle)
|
||||
|
||||
Section {
|
||||
HideShortsButtons(hide: $hideShorts)
|
||||
}
|
||||
|
||||
Section {
|
||||
SettingsButtons()
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
33
Shared/Views/HideShortsButtons.swift
Normal file
33
Shared/Views/HideShortsButtons.swift
Normal 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))
|
||||
}
|
||||
}
|
||||
}
|
@@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user