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
@Default(.channelPlaylistListingStyle) private var channelPlaylistListingStyle
@Default(.hideShorts) private var hideShorts
@ObservedObject private var accounts = AccountsModel.shared
var player = PlayerModel.shared
@ -103,7 +102,7 @@ struct ChannelPlaylistView: View {
HStack {
ListingStyleButtons(listingStyle: $channelPlaylistListingStyle)
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
ShareButton(contentItem: contentItem)
favoriteButton
@ -133,7 +132,7 @@ struct ChannelPlaylistView: View {
Section {
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
}
Section {

View File

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

View File

@ -66,10 +66,6 @@ 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] }
@ -125,9 +121,4 @@ extension EnvironmentValues {
get { self[NoListingDividersKey.self] }
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(.showCacheStatus) private var showCacheStatus
@Default(.hideShorts) private var hideShorts
var items: [ContentItem] {
var videos = currentPlaylist?.videos ?? []
@ -68,7 +67,6 @@ struct PlaylistsView: View {
.environment(\.scrollViewBottomPadding, 70)
.environment(\.currentPlaylistID, currentPlaylist?.id)
.environment(\.listingStyle, playlistListingStyle)
.environment(\.hideShorts, hideShorts)
if currentPlaylist != nil, items.isEmpty {
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()
}
ToolbarItem {
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
}
}
#else
@ -220,7 +218,7 @@ struct PlaylistsView: View {
Section {
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
}
Section {
@ -391,7 +389,7 @@ struct PlaylistsView: View {
ListingStyleButtons(listingStyle: $playlistListingStyle)
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
#else
Spacer()
#endif

View File

@ -30,7 +30,6 @@ 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]()
@ -71,13 +70,12 @@ struct SearchView: View {
#endif
}
.environment(\.listingStyle, searchListingStyle)
.environment(\.hideShorts, hideShorts)
.toolbar {
#if os(macOS)
ToolbarItemGroup(placement: toolbarPlacement) {
ListingStyleButtons(listingStyle: $searchListingStyle)
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
FavoriteButton(item: favoriteItem)
.id(favoriteItem?.id)
@ -216,7 +214,7 @@ struct SearchView: View {
Section {
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
}
Section {
@ -574,7 +572,7 @@ struct SearchView: View {
Spacer()
ListingStyleButtons(listingStyle: $searchListingStyle)
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
}
.labelStyle(.iconOnly)
.padding(.leading, 30)

View File

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

View File

@ -10,7 +10,6 @@ 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
@ -28,8 +27,6 @@ struct SubscriptionsView: View {
}
}
.environment(\.listingStyle, subscriptionsListingStyle)
.environment(\.hideShorts, hideShorts)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
@ -47,7 +44,7 @@ struct SubscriptionsView: View {
ToolbarItemGroup {
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
toggleWatchedButton
.id(feed.watchedId)
playUnwatchedButton
@ -75,7 +72,7 @@ struct SubscriptionsView: View {
Section {
HideWatchedButtons()
HideShortsButtons(hide: $hideShorts)
HideShortsButtons()
}
playUnwatchedButton

View File

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

View File

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

View File

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

View File

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