Refactor hide shorts

This commit is contained in:
Arkadiusz Fal 2023-05-23 18:54:53 +02:00
parent 1e23809359
commit 50e1491990
11 changed files with 25 additions and 47 deletions

View File

@ -10,7 +10,6 @@ struct ChannelPlaylistView: View {
@Environment(\.colorScheme) private var colorScheme @Environment(\.colorScheme) private var colorScheme
@Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle @Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle
@Default(.hideShorts) private var hideShorts
@ObservedObject private var accounts = AccountsModel.shared @ObservedObject private var accounts = AccountsModel.shared
var player = PlayerModel.shared var player = PlayerModel.shared
@ -103,7 +102,7 @@ struct ChannelPlaylistView: View {
HStack { HStack {
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle) ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
ShareButton(contentItem: contentItem) ShareButton(contentItem: contentItem)
favoriteButton favoriteButton
@ -133,7 +132,7 @@ struct ChannelPlaylistView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
Section { Section {

View File

@ -30,7 +30,6 @@ struct ChannelVideosView: View {
@Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle @Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle
@Default(.expandChannelDescription) private var expandChannelDescription @Default(.expandChannelDescription) private var expandChannelDescription
@Default(.hideShorts) private var hideShorts
var presentedChannel: Channel? { var presentedChannel: Channel? {
store.item?.channel ?? channel ?? recents.presentedChannel store.item?.channel ?? channel ?? recents.presentedChannel
@ -98,7 +97,6 @@ struct ChannelVideosView: View {
.environment(\.loadMoreContentHandler) { loadNextPage() } .environment(\.loadMoreContentHandler) { loadNextPage() }
.environment(\.inChannelView, true) .environment(\.inChannelView, true)
.environment(\.listingStyle, channelPlaylistListingStyle) .environment(\.listingStyle, channelPlaylistListingStyle)
.environment(\.hideShorts, hideShorts)
#if os(tvOS) #if os(tvOS)
.prefersDefaultFocus(in: focusNamespace) .prefersDefaultFocus(in: focusNamespace)
#endif #endif
@ -138,7 +136,7 @@ struct ChannelVideosView: View {
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle) ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
contentTypePicker contentTypePicker
} }
@ -283,7 +281,7 @@ struct ChannelVideosView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
} }
} label: { } label: {

View File

@ -66,10 +66,6 @@ private struct ScrollViewBottomPaddingKey: EnvironmentKey {
static let defaultValue: Double = 30 static let defaultValue: Double = 30
} }
private struct HideShortsKey: EnvironmentKey {
static let defaultValue = false
}
extension EnvironmentValues { extension EnvironmentValues {
var inChannelView: Bool { var inChannelView: Bool {
get { self[InChannelViewKey.self] } get { self[InChannelViewKey.self] }
@ -125,9 +121,4 @@ extension EnvironmentValues {
get { self[NoListingDividersKey.self] } get { self[NoListingDividersKey.self] }
set { self[NoListingDividersKey.self] = newValue } set { self[NoListingDividersKey.self] = newValue }
} }
var hideShorts: Bool {
get { self[HideShortsKey.self] }
set { self[HideShortsKey.self] = newValue }
}
} }

View File

@ -24,7 +24,6 @@ struct PlaylistsView: View {
@Default(.playlistListingStyle) private var playlistListingStyle @Default(.playlistListingStyle) private var playlistListingStyle
@Default(.showCacheStatus) private var showCacheStatus @Default(.showCacheStatus) private var showCacheStatus
@Default(.hideShorts) private var hideShorts
var items: [ContentItem] { var items: [ContentItem] {
var videos = currentPlaylist?.videos ?? [] var videos = currentPlaylist?.videos ?? []
@ -68,7 +67,6 @@ struct PlaylistsView: View {
.environment(\.scrollViewBottomPadding, 70) .environment(\.scrollViewBottomPadding, 70)
.environment(\.currentPlaylistID, currentPlaylist?.id) .environment(\.currentPlaylistID, currentPlaylist?.id)
.environment(\.listingStyle, playlistListingStyle) .environment(\.listingStyle, playlistListingStyle)
.environment(\.hideShorts, hideShorts)
if currentPlaylist != nil, items.isEmpty { if currentPlaylist != nil, items.isEmpty {
hintText("Playlist is empty\n\nTap and hold on a video and then \n\"Add to Playlist\"".localized()) hintText("Playlist is empty\n\nTap and hold on a video and then \n\"Add to Playlist\"".localized())
@ -149,7 +147,7 @@ struct PlaylistsView: View {
HideWatchedButtons() HideWatchedButtons()
} }
ToolbarItem { ToolbarItem {
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
} }
#else #else
@ -220,7 +218,7 @@ struct PlaylistsView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
Section { Section {
@ -391,7 +389,7 @@ struct PlaylistsView: View {
ListingStyleButtons(listingStyle: $playlistListingStyle) ListingStyleButtons(listingStyle: $playlistListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
#else #else
Spacer() Spacer()
#endif #endif

View File

@ -30,7 +30,6 @@ struct SearchView: View {
@Default(.saveRecents) private var saveRecents @Default(.saveRecents) private var saveRecents
@Default(.showHome) private var showHome @Default(.showHome) private var showHome
@Default(.searchListingStyle) private var searchListingStyle @Default(.searchListingStyle) private var searchListingStyle
@Default(.hideShorts) private var hideShorts
private var videos = [Video]() private var videos = [Video]()
@ -71,13 +70,12 @@ struct SearchView: View {
#endif #endif
} }
.environment(\.listingStyle, searchListingStyle) .environment(\.listingStyle, searchListingStyle)
.environment(\.hideShorts, hideShorts)
.toolbar { .toolbar {
#if os(macOS) #if os(macOS)
ToolbarItemGroup(placement: toolbarPlacement) { ToolbarItemGroup(placement: toolbarPlacement) {
ListingStyleButtons(listingStyle: $searchListingStyle) ListingStyleButtons(listingStyle: $searchListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
FavoriteButton(item: favoriteItem) FavoriteButton(item: favoriteItem)
.id(favoriteItem?.id) .id(favoriteItem?.id)
@ -216,7 +214,7 @@ struct SearchView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
Section { Section {
@ -574,7 +572,7 @@ struct SearchView: View {
Spacer() Spacer()
ListingStyleButtons(listingStyle: $searchListingStyle) ListingStyleButtons(listingStyle: $searchListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
.labelStyle(.iconOnly) .labelStyle(.iconOnly)
.padding(.leading, 30) .padding(.leading, 30)

View File

@ -9,7 +9,6 @@ struct FeedView: View {
#if os(tvOS) #if os(tvOS)
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle @Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
@Default(.hideShorts) private var hideShorts
#endif #endif
var videos: [ContentItem] { var videos: [ContentItem] {
@ -55,7 +54,7 @@ struct FeedView: View {
SubscriptionsPageButton() SubscriptionsPageButton()
ListingStyleButtons(listingStyle: $subscriptionsListingStyle) ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
#endif #endif
if showCacheStatus { if showCacheStatus {

View File

@ -10,7 +10,6 @@ struct SubscriptionsView: View {
@Default(.subscriptionsViewPage) private var subscriptionsViewPage @Default(.subscriptionsViewPage) private var subscriptionsViewPage
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle @Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
@Default(.hideShorts) private var hideShorts
@ObservedObject private var feed = FeedModel.shared @ObservedObject private var feed = FeedModel.shared
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared @ObservedObject private var subscriptions = SubscribedChannelsModel.shared
@ -28,8 +27,6 @@ struct SubscriptionsView: View {
} }
} }
.environment(\.listingStyle, subscriptionsListingStyle) .environment(\.listingStyle, subscriptionsListingStyle)
.environment(\.hideShorts, hideShorts)
#if os(iOS) #if os(iOS)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
@ -47,7 +44,7 @@ struct SubscriptionsView: View {
ToolbarItemGroup { ToolbarItemGroup {
ListingStyleButtons(listingStyle: $subscriptionsListingStyle) ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
toggleWatchedButton toggleWatchedButton
.id(feed.watchedId) .id(feed.watchedId)
playUnwatchedButton playUnwatchedButton
@ -75,7 +72,7 @@ struct SubscriptionsView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
playUnwatchedButton playUnwatchedButton

View File

@ -10,7 +10,6 @@ struct TrendingView: View {
@Default(.trendingCountry) private var country @Default(.trendingCountry) private var country
@Default(.trendingListingStyle) private var trendingListingStyle @Default(.trendingListingStyle) private var trendingListingStyle
@Default(.hideShorts) private var hideShorts
@State private var presentingCountrySelection = false @State private var presentingCountrySelection = false
@ -41,7 +40,6 @@ struct TrendingView: View {
Section { Section {
VerticalCells(items: trending) { if shouldDisplayHeader { header } } VerticalCells(items: trending) { if shouldDisplayHeader { header } }
.environment(\.listingStyle, trendingListingStyle) .environment(\.listingStyle, trendingListingStyle)
.environment(\.hideShorts, hideShorts)
} }
.toolbar { .toolbar {
@ -128,7 +126,7 @@ struct TrendingView: View {
} }
ToolbarItem { ToolbarItem {
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
} }
#else #else
@ -179,7 +177,7 @@ struct TrendingView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
Section { Section {
@ -253,7 +251,7 @@ struct TrendingView: View {
Spacer() Spacer()
ListingStyleButtons(listingStyle: $trendingListingStyle) ListingStyleButtons(listingStyle: $trendingListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
Button { Button {
resource.load() resource.load()

View File

@ -6,7 +6,7 @@ struct ContentItemView: View {
let item: ContentItem let item: ContentItem
@Environment(\.listingStyle) private var listingStyle @Environment(\.listingStyle) private var listingStyle
@Environment(\.noListingDividers) private var noListingDividers @Environment(\.noListingDividers) private var noListingDividers
@Environment(\.hideShorts) private var hideShorts @Default(.hideShorts) private var hideShorts
@Default(.hideWatched) private var hideWatched @Default(.hideWatched) private var hideWatched
@FetchRequest private var watchRequest: FetchedResults<Watch> @FetchRequest private var watchRequest: FetchedResults<Watch>

View File

@ -1,14 +1,15 @@
import Defaults
import SwiftUI import SwiftUI
struct HideShortsButtons: View { struct HideShortsButtons: View {
@Binding var hide: Bool @Default(.hideShorts) private var hideShorts
var body: some View { var body: some View {
Button { Button {
hide.toggle() hideShorts.toggle()
} label: { } label: {
Group { Group {
if hide { if hideShorts {
Label("Short videos: hidden", systemImage: "bolt.slash.fill") Label("Short videos: hidden", systemImage: "bolt.slash.fill")
.help("Short videos: hidden") .help("Short videos: hidden")
} else { } else {
@ -27,7 +28,7 @@ struct HideShortsButtons: View {
struct HideShortsButtons_Previews: PreviewProvider { struct HideShortsButtons_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
VStack { VStack {
HideShortsButtons(hide: .constant(true)) HideShortsButtons()
} }
} }
} }

View File

@ -10,7 +10,6 @@ struct PopularView: View {
@State private var error: RequestError? @State private var error: RequestError?
@Default(.popularListingStyle) private var popularListingStyle @Default(.popularListingStyle) private var popularListingStyle
@Default(.hideShorts) private var hideShorts
var resource: Resource? { var resource: Resource? {
accounts.api.popular accounts.api.popular
@ -76,7 +75,7 @@ struct PopularView: View {
} }
ToolbarItem { ToolbarItem {
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
} }
#else #else
@ -95,7 +94,7 @@ struct PopularView: View {
Section { Section {
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
} }
Section { Section {
@ -135,7 +134,7 @@ struct PopularView: View {
Spacer() Spacer()
ListingStyleButtons(listingStyle: $popularListingStyle) ListingStyleButtons(listingStyle: $popularListingStyle)
HideWatchedButtons() HideWatchedButtons()
HideShortsButtons(hide: $hideShorts) HideShortsButtons()
Button { Button {
resource?.load() resource?.load()