mirror of
https://github.com/yattee/yattee.git
synced 2025-11-25 10:48:17 +00:00
Channels search, add SDWebImage framework
This commit is contained in:
73
Shared/Views/ChannelCell.swift
Normal file
73
Shared/Views/ChannelCell.swift
Normal file
@@ -0,0 +1,73 @@
|
||||
import Foundation
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelCell: View {
|
||||
let channel: Channel
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
let recent = RecentItem(from: channel)
|
||||
recents.add(recent)
|
||||
navigation.isChannelOpen = true
|
||||
|
||||
if navigationStyle == .sidebar {
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
navigation.tabSelection = .recentlyOpened(recent.tag)
|
||||
}
|
||||
} label: {
|
||||
content
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
.contentShape(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
VStack {
|
||||
Text("Channel".uppercased())
|
||||
.foregroundColor(.secondary)
|
||||
.fontWeight(.light)
|
||||
.opacity(0.6)
|
||||
|
||||
WebImage(url: channel.thumbnailURL)
|
||||
.resizable()
|
||||
.placeholder {
|
||||
Rectangle().fill(Color("PlaceholderColor"))
|
||||
}
|
||||
.indicator(.progress)
|
||||
.frame(width: 88, height: 88)
|
||||
.clipShape(Circle())
|
||||
|
||||
Group {
|
||||
DetailBadge(text: channel.name, style: .prominent)
|
||||
|
||||
Group {
|
||||
if let subscriptions = channel.subscriptionsString {
|
||||
Text("\(subscriptions) subscribers")
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Text("")
|
||||
}
|
||||
}
|
||||
.frame(height: 20)
|
||||
}
|
||||
.offset(x: 0, y: -15)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelSearchItem_Preview: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
ChannelCell(channel: Video.fixture.channel)
|
||||
}
|
||||
.frame(maxWidth: 300, maxHeight: 200)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ struct ChannelVideosView: View {
|
||||
|
||||
@Namespace private var focusNamespace
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: store.item?.videos ?? [])
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
if inNavigationView {
|
||||
@@ -55,7 +59,7 @@ struct ChannelVideosView: View {
|
||||
.frame(maxWidth: .infinity)
|
||||
#endif
|
||||
|
||||
VideosCellsVertical(videos: store.item?.videos ?? [])
|
||||
VerticalCells(items: videos)
|
||||
|
||||
#if !os(iOS)
|
||||
.prefersDefaultFocus(in: focusNamespace)
|
||||
|
||||
19
Shared/Views/ContentItemView.swift
Normal file
19
Shared/Views/ContentItemView.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct ContentItemView: View {
|
||||
let item: ContentItem
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
switch item.contentType {
|
||||
case .playlist:
|
||||
VideoCell(video: item.video)
|
||||
case .channel:
|
||||
ChannelCell(channel: item.channel)
|
||||
default:
|
||||
VideoCell(video: item.video)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Shared/Views/DetailBadge.swift
Normal file
96
Shared/Views/DetailBadge.swift
Normal file
@@ -0,0 +1,96 @@
|
||||
import SwiftUI
|
||||
|
||||
struct DetailBadge: View {
|
||||
enum Style {
|
||||
case `default`, prominent, outstanding, informational
|
||||
}
|
||||
|
||||
struct StyleModifier: ViewModifier {
|
||||
let style: Style
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
Group {
|
||||
switch style {
|
||||
case .prominent:
|
||||
content.modifier(ProminentStyleModifier())
|
||||
case .outstanding:
|
||||
content.modifier(OutstandingStyleModifier())
|
||||
case .informational:
|
||||
content.modifier(InformationalStyleModifier())
|
||||
default:
|
||||
content.modifier(DefaultStyleModifier())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DefaultStyleModifier: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(.thinMaterial)
|
||||
}
|
||||
}
|
||||
|
||||
struct ProminentStyleModifier: ViewModifier {
|
||||
var font: Font {
|
||||
Font.system(.body).weight(.semibold)
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.font(font)
|
||||
.modifier(DefaultStyleModifier())
|
||||
}
|
||||
}
|
||||
|
||||
struct OutstandingStyleModifier: ViewModifier {
|
||||
var backgroundColor: Color {
|
||||
Color("DetailBadgeOutstandingStyleBackgroundColor")
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.textCase(.uppercase)
|
||||
.background(backgroundColor)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
|
||||
struct InformationalStyleModifier: ViewModifier {
|
||||
var backgroundColor: Color {
|
||||
Color("DetailBadgeInformationalStyleBackgroundColor")
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(backgroundColor)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
|
||||
var text: String
|
||||
var style: Style = .default
|
||||
|
||||
var body: some View {
|
||||
Text(text)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
.padding(10)
|
||||
.modifier(StyleModifier(style: style))
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
}
|
||||
|
||||
struct DetailBadge_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
DetailBadge(text: "Live", style: .outstanding)
|
||||
DetailBadge(text: "Premieres", style: .informational)
|
||||
DetailBadge(text: "Booyah", style: .prominent)
|
||||
DetailBadge(
|
||||
text: "Donec in neque mi. Phasellus quis sapien metus. Ut felis ante, posuere."
|
||||
)
|
||||
}
|
||||
.frame(maxWidth: 500)
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,17 @@ import SwiftUI
|
||||
struct PlaylistVideosView: View {
|
||||
let playlist: Playlist
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: playlist.videos)
|
||||
}
|
||||
|
||||
init(_ playlist: Playlist) {
|
||||
self.playlist = playlist
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
PlayerControlsView {
|
||||
VideosCellsVertical(videos: playlist.videos)
|
||||
VerticalCells(items: videos)
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
#endif
|
||||
|
||||
@@ -10,9 +10,13 @@ struct PopularView: View {
|
||||
accounts.api.popular
|
||||
}
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: store.collection)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
PlayerControlsView {
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
VerticalCells(items: videos)
|
||||
.onAppear {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
|
||||
@@ -42,11 +42,11 @@ struct SearchView: View {
|
||||
filtersHorizontalStack
|
||||
}
|
||||
|
||||
VideosCellsHorizontal(videos: state.store.collection)
|
||||
HorizontalCells(items: state.store.collection)
|
||||
}
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#else
|
||||
VideosCellsVertical(videos: state.store.collection)
|
||||
VerticalCells(items: state.store.collection)
|
||||
#endif
|
||||
|
||||
if noResults {
|
||||
@@ -95,7 +95,7 @@ struct SearchView: View {
|
||||
}
|
||||
|
||||
if !videos.isEmpty {
|
||||
state.store.replace(videos)
|
||||
state.store.replace(ContentItem.array(of: videos))
|
||||
}
|
||||
}
|
||||
.searchable(text: $state.queryText, placement: searchFieldPlacement) {
|
||||
|
||||
@@ -10,10 +10,14 @@ struct SubscriptionsView: View {
|
||||
accounts.api.feed
|
||||
}
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: store.collection)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
PlayerControlsView {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
VerticalCells(items: videos)
|
||||
.onAppear {
|
||||
loadResources()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ struct VideoContextMenuView: View {
|
||||
@Binding var playerNavigationLinkActive: Bool
|
||||
|
||||
@Environment(\.inNavigationView) private var inNavigationView
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@@ -85,8 +86,11 @@ struct VideoContextMenuView: View {
|
||||
let recent = RecentItem(from: video.channel)
|
||||
recents.add(recent)
|
||||
navigation.isChannelOpen = true
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
navigation.tabSelection = .recentlyOpened(recent.tag)
|
||||
|
||||
if navigationStyle == .sidebar {
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
navigation.tabSelection = .recentlyOpened(recent.tag)
|
||||
}
|
||||
} label: {
|
||||
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user