1
0
mirror of https://github.com/yattee/yattee.git synced 2025-01-10 11:30:32 +05:30

New channel navigation

This commit is contained in:
Arkadiusz Fal 2022-05-29 20:26:56 +02:00
parent 44e6c28fd4
commit 124a48812a
8 changed files with 114 additions and 53 deletions

View File

@ -78,6 +78,8 @@ final class NavigationModel: ObservableObject {
return return
} }
navigation.presentingChannel = false
let recent = RecentItem(from: channel) let recent = RecentItem(from: channel)
#if os(macOS) #if os(macOS)
Windows.main.open() Windows.main.open()

View File

@ -549,4 +549,8 @@ final class PlayerModel: ObservableObject {
} }
#endif #endif
} }
func setNeedsDrawing(_ needsDrawing: Bool) {
backends.forEach { $0.setNeedsDrawing(needsDrawing) }
}
} }

View File

@ -4,6 +4,7 @@ import Foundation
final class RecentsModel: ObservableObject { final class RecentsModel: ObservableObject {
@Default(.recentlyOpened) var items @Default(.recentlyOpened) var items
@Default(.saveRecents) var saveRecents @Default(.saveRecents) var saveRecents
func clear() { func clear() {
items = [] items = []
} }

View File

@ -44,22 +44,8 @@ struct AppTabNavigation: View {
} }
.id(accounts.current?.id ?? "") .id(accounts.current?.id ?? "")
.environment(\.navigationStyle, .tab) .environment(\.navigationStyle, .tab)
.background( .overlay(channelView)
EmptyView().sheet(isPresented: $navigation.presentingChannel) {
if let channel = recents.presentedChannel {
NavigationView {
ChannelVideosView(channel: channel)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.environment(\.inChannelView, true)
.environmentObject(accounts)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
}
}
}
)
.background( .background(
EmptyView().sheet(isPresented: $navigation.presentingPlaylist) { EmptyView().sheet(isPresented: $navigation.presentingPlaylist) {
if let playlist = recents.presentedPlaylist { if let playlist = recents.presentedPlaylist {
@ -188,4 +174,16 @@ struct AppTabNavigation: View {
} }
#endif #endif
} }
private var channelView: some View {
ChannelVideosView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.environment(\.inChannelView, true)
.environment(\.navigationStyle, .tab)
.environmentObject(accounts)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
}
} }

View File

@ -26,6 +26,8 @@ struct ContentView: View {
@Environment(\.horizontalSizeClass) private var horizontalSizeClass @Environment(\.horizontalSizeClass) private var horizontalSizeClass
#endif #endif
let persistenceController = PersistenceController.shared
var body: some View { var body: some View {
Group { Group {
#if os(iOS) #if os(iOS)

View File

@ -179,6 +179,7 @@ extension AppleAVPlayerViewController: AVPlayerViewControllerDelegate {
) { ) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.playerModel.show() self.playerModel.show()
self.playerModel.setNeedsDrawing(true)
#if os(tvOS) #if os(tvOS)
if self.playerModel.playingInPictureInPicture { if self.playerModel.playingInPictureInPicture {

View File

@ -7,6 +7,7 @@ struct VideoCell: View {
private var video: Video private var video: Video
@Environment(\.navigationStyle) private var navigationStyle @Environment(\.navigationStyle) private var navigationStyle
@Environment(\.inChannelView) private var inChannelView
#if os(iOS) #if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass @Environment(\.verticalSizeClass) private var verticalSizeClass
@ -294,6 +295,10 @@ struct VideoCell: View {
private func channelButton(badge: Bool = true) -> some View { private func channelButton(badge: Bool = true) -> some View {
Button { Button {
guard !inChannelView else {
return
}
NavigationModel.openChannel( NavigationModel.openChannel(
video.channel, video.channel,
player: player, player: player,

View File

@ -2,15 +2,23 @@ import Siesta
import SwiftUI import SwiftUI
struct ChannelVideosView: View { struct ChannelVideosView: View {
let channel: Channel #if os(iOS)
static let hiddenOffset = max(UIScreen.main.bounds.height, UIScreen.main.bounds.width) + 100
#endif
var channel: Channel?
@State private var presentingShareSheet = false @State private var presentingShareSheet = false
@State private var shareURL: URL? @State private var shareURL: URL?
@State private var subscriptionToggleButtonDisabled = false @State private var subscriptionToggleButtonDisabled = false
#if os(iOS)
@State private var viewVerticalOffset = Self.hiddenOffset
#endif
@StateObject private var store = Store<Channel>() @StateObject private var store = Store<Channel>()
@Environment(\.colorScheme) private var colorScheme @Environment(\.colorScheme) private var colorScheme
@Environment(\.navigationStyle) private var navigationStyle
#if os(iOS) #if os(iOS)
@Environment(\.horizontalSizeClass) private var horizontalSizeClass @Environment(\.horizontalSizeClass) private var horizontalSizeClass
@ -19,19 +27,44 @@ struct ChannelVideosView: View {
@EnvironmentObject<AccountsModel> private var accounts @EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation @EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SubscriptionsModel> private var subscriptions @EnvironmentObject<SubscriptionsModel> private var subscriptions
@Namespace private var focusNamespace @Namespace private var focusNamespace
var presentedChannel: Channel? {
recents.presentedChannel ?? channel
}
var videos: [ContentItem] { var videos: [ContentItem] {
ContentItem.array(of: store.item?.videos ?? []) ContentItem.array(of: store.item?.videos ?? [])
} }
var body: some View { var body: some View {
if navigationStyle == .tab {
NavigationView {
BrowserPlayerControls { BrowserPlayerControls {
content content
} }
} }
#if os(iOS)
.onChange(of: navigation.presentingChannel) { newValue in
if newValue {
resource?.load()
viewVerticalOffset = 0
} else {
viewVerticalOffset = Self.hiddenOffset
}
}
.offset(y: viewVerticalOffset)
.animation(.easeIn(duration: 0.2), value: viewVerticalOffset)
#endif
} else {
BrowserPlayerControls {
content
}
}
}
var content: some View { var content: some View {
let content = VStack { let content = VStack {
@ -43,8 +76,10 @@ struct ChannelVideosView: View {
Spacer() Spacer()
if let channel = presentedChannel {
FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name))) FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name)))
.labelStyle(.iconOnly) .labelStyle(.iconOnly)
}
if let subscribers = store.item?.subscriptionsString { if let subscribers = store.item?.subscriptionsString {
Text("**\(subscribers)** subscribers") Text("**\(subscribers)** subscribers")
@ -66,11 +101,11 @@ struct ChannelVideosView: View {
#if !os(tvOS) #if !os(tvOS)
.toolbar { .toolbar {
ToolbarItem(placement: .navigation) { ToolbarItem(placement: .navigation) {
ShareButton( if navigationStyle == .tab {
contentItem: contentItem, Button("Done") {
presentingShareSheet: $presentingShareSheet, navigation.presentingChannel = false
shareURL: $shareURL }
) }
} }
ToolbarItem { ToolbarItem {
@ -79,17 +114,25 @@ struct ChannelVideosView: View {
Text("\(store.item?.subscriptionsString ?? "loading")") Text("\(store.item?.subscriptionsString ?? "loading")")
.fontWeight(.bold) .fontWeight(.bold)
Text(" subscribers") Text(" subscribers")
}
.allowsTightening(true) .allowsTightening(true)
.foregroundColor(.secondary) .foregroundColor(.secondary)
.opacity(store.item?.subscriptionsString != nil ? 1 : 0) .opacity(store.item?.subscriptionsString != nil ? 1 : 0)
}
ShareButton(
contentItem: contentItem,
presentingShareSheet: $presentingShareSheet,
shareURL: $shareURL
)
subscriptionToggleButton subscriptionToggleButton
if let channel = presentedChannel {
FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name))) FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name)))
} }
} }
} }
}
#endif #endif
#if os(iOS) #if os(iOS)
.sheet(isPresented: $presentingShareSheet) { .sheet(isPresented: $presentingShareSheet) {
@ -99,12 +142,11 @@ struct ChannelVideosView: View {
} }
#endif #endif
.onAppear { .onAppear {
if store.item.isNil { resource?.loadIfNeeded()
resource.addObserver(store)
resource.load()
}
} }
#if !os(tvOS)
.navigationTitle(navigationTitle) .navigationTitle(navigationTitle)
#endif
return Group { return Group {
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
@ -121,14 +163,19 @@ struct ChannelVideosView: View {
} }
} }
private var resource: Resource { private var resource: Resource? {
guard let channel = presentedChannel else {
return nil
}
let resource = accounts.api.channel(channel.id) let resource = accounts.api.channel(channel.id)
resource.addObserver(store) resource.addObserver(store)
return resource return resource
} }
private var subscriptionToggleButton: some View { @ViewBuilder private var subscriptionToggleButton: some View {
if let channel = presentedChannel {
Group { Group {
if accounts.app.supportsSubscriptions && accounts.signedIn { if accounts.app.supportsSubscriptions && accounts.signedIn {
if subscriptions.isSubscribing(channel.id) { if subscriptions.isSubscribing(channel.id) {
@ -153,12 +200,13 @@ struct ChannelVideosView: View {
} }
.disabled(subscriptionToggleButtonDisabled) .disabled(subscriptionToggleButtonDisabled)
} }
}
private var contentItem: ContentItem { private var contentItem: ContentItem {
ContentItem(channel: channel) ContentItem(channel: presentedChannel)
} }
private var navigationTitle: String { private var navigationTitle: String {
store.item?.name ?? channel.name presentedChannel?.name ?? store.item?.name ?? "No channel"
} }
} }