mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Channels search, add SDWebImage framework
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "display-p3",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.781",
|
||||
"green" : "0.781",
|
||||
"red" : "0.781"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "display-p3",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.311",
|
||||
"green" : "0.311",
|
||||
"red" : "0.311"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@@ -73,6 +73,7 @@ struct RecentNavigationLink<DestinationContent: View>: View {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
.opacity(0.5)
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,7 @@
|
||||
import Defaults
|
||||
import SDWebImage
|
||||
import SDWebImagePINPlugin
|
||||
import SDWebImageWebPCoder
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
@@ -83,6 +86,8 @@ struct ContentView: View {
|
||||
|
||||
func configure() {
|
||||
SiestaLog.Category.enabled = .common
|
||||
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
|
||||
SDWebImageManager.defaultImageCache = PINCache(name: "net.yattee.app")
|
||||
|
||||
// TODO: Remove when piped supports videos information
|
||||
if let account = accounts.lastUsed ??
|
||||
|
@@ -14,8 +14,8 @@ struct PlaylistsView: View {
|
||||
|
||||
@Namespace private var focusNamespace
|
||||
|
||||
var videos: [Video] {
|
||||
model.currentPlaylist?.videos ?? []
|
||||
var items: [ContentItem] {
|
||||
ContentItem.array(of: model.currentPlaylist?.videos ?? [])
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -26,17 +26,17 @@ struct PlaylistsView: View {
|
||||
toolbar
|
||||
#endif
|
||||
|
||||
if model.currentPlaylist != nil, videos.isEmpty {
|
||||
if model.currentPlaylist != nil, items.isEmpty {
|
||||
hintText("Playlist is empty\n\nTap and hold on a video and then tap \"Add to Playlist\"")
|
||||
} else if model.all.isEmpty {
|
||||
hintText("You have no playlists\n\nTap on \"New Playlist\" to create one")
|
||||
} else {
|
||||
#if os(tvOS)
|
||||
VideosCellsHorizontal(videos: videos)
|
||||
HorizontalCells(items: items)
|
||||
.padding(.top, 40)
|
||||
Spacer()
|
||||
#else
|
||||
VideosCellsVertical(videos: videos)
|
||||
VerticalCells(items: items)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ struct PlaylistsView: View {
|
||||
}
|
||||
|
||||
Button {
|
||||
player.playAll(videos)
|
||||
player.playAll(items.compactMap(\.video))
|
||||
player.presentPlayer()
|
||||
} label: {
|
||||
HStack(spacing: 15) {
|
||||
|
@@ -13,6 +13,10 @@ struct TrendingView: View {
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
|
||||
var popular: [ContentItem] {
|
||||
ContentItem.array(of: store.collection)
|
||||
}
|
||||
|
||||
init(_ videos: [Video] = [Video]()) {
|
||||
self.videos = videos
|
||||
}
|
||||
@@ -32,12 +36,12 @@ struct TrendingView: View {
|
||||
VStack(alignment: .center, spacing: 0) {
|
||||
#if os(tvOS)
|
||||
toolbar
|
||||
VideosCellsHorizontal(videos: store.collection)
|
||||
HorizontalCells(items: popular)
|
||||
.padding(.top, 40)
|
||||
|
||||
Spacer()
|
||||
#else
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
VerticalCells(items: popular)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,18 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosCellsHorizontal: View {
|
||||
struct HorizontalCells: View {
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
|
||||
var videos = [Video]()
|
||||
var items = [ContentItem]()
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(spacing: 20) {
|
||||
ForEach(videos) { video in
|
||||
VideoView(video: video)
|
||||
ForEach(items) { item in
|
||||
ContentItemView(item: item)
|
||||
.environment(\.horizontalCells, true)
|
||||
#if os(tvOS)
|
||||
.frame(width: 580)
|
||||
@@ -42,9 +42,9 @@ struct VideosCellsHorizontal: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoCellsHorizontal_Previews: PreviewProvider {
|
||||
struct HorizontalCells_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideosCellsHorizontal(videos: Video.allFixtures)
|
||||
HorizontalCells(items: ContentItem.array(of: Video.allFixtures))
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -1,29 +1,23 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosCellsVertical: View {
|
||||
struct VerticalCells: View {
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
|
||||
var videos = [Video]()
|
||||
var items = [ContentItem]()
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
|
||||
LazyVGrid(columns: items, alignment: .center) {
|
||||
ForEach(videos) { video in
|
||||
VideoView(video: video)
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal)
|
||||
#endif
|
||||
LazyVGrid(columns: columns, alignment: .center) {
|
||||
ForEach(items.sorted { $0 < $1 }) { item in
|
||||
ContentItemView(item: item)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.id(UUID())
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 10)
|
||||
#endif
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#if os(macOS)
|
||||
.background()
|
||||
@@ -31,9 +25,9 @@ struct VideosCellsVertical: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
var items: [GridItem] {
|
||||
var columns: [GridItem] {
|
||||
#if os(tvOS)
|
||||
videos.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [videos.count, 1].max()!) : adaptiveItem
|
||||
items.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [items.count, 1].max()!) : adaptiveItem
|
||||
#else
|
||||
adaptiveItem
|
||||
#endif
|
||||
@@ -64,7 +58,7 @@ struct VideosCellsVertical: View {
|
||||
|
||||
struct VideoCellsVertical_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideosCellsVertical(videos: Video.allFixtures)
|
||||
VerticalCells(items: ContentItem.array(of: Video.allFixtures))
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct VideoBanner: View {
|
||||
@@ -35,22 +36,12 @@ struct VideoBanner: View {
|
||||
}
|
||||
|
||||
var smallThumbnail: some View {
|
||||
Group {
|
||||
if let url = video.thumbnailURL(quality: .medium) {
|
||||
AsyncImage(url: url) { image in
|
||||
image
|
||||
.resizable()
|
||||
} placeholder: {
|
||||
HStack {
|
||||
ProgressView()
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.square")
|
||||
WebImage(url: video.thumbnailURL(quality: .medium))
|
||||
.resizable()
|
||||
.placeholder {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.background(.gray)
|
||||
.indicator(.activity)
|
||||
#if os(tvOS)
|
||||
.frame(width: 177, height: 100)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
|
@@ -1,10 +1,12 @@
|
||||
import Defaults
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct VideoView: View {
|
||||
struct VideoCell: View {
|
||||
var video: Video
|
||||
|
||||
@State private var playerNavigationLinkActive = false
|
||||
@State private var lowQualityThumbnail = false
|
||||
|
||||
@Environment(\.inNavigationView) private var inNavigationView
|
||||
|
||||
@@ -181,7 +183,7 @@ struct VideoView: View {
|
||||
|
||||
var thumbnail: some View {
|
||||
ZStack(alignment: .leading) {
|
||||
thumbnailImage(quality: .maxresdefault)
|
||||
thumbnailImage(quality: lowQualityThumbnail ? .medium : .maxresdefault)
|
||||
|
||||
VStack {
|
||||
HStack(alignment: .top) {
|
||||
@@ -212,27 +214,20 @@ struct VideoView: View {
|
||||
}
|
||||
|
||||
func thumbnailImage(quality: Thumbnail.Quality) -> some View {
|
||||
Group {
|
||||
if let url = video.thumbnailURL(quality: quality) {
|
||||
AsyncImage(url: url) { image in
|
||||
image
|
||||
.resizable()
|
||||
} placeholder: {
|
||||
HStack {
|
||||
ProgressView()
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.square")
|
||||
WebImage(url: video.thumbnailURL(quality: quality))
|
||||
.resizable()
|
||||
.placeholder {
|
||||
Rectangle().fill(Color("PlaceholderColor"))
|
||||
}
|
||||
}
|
||||
.background(.gray)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.onFailure { _ in
|
||||
lowQualityThumbnail = true
|
||||
}
|
||||
.indicator(.progress)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.modifier(AspectRatioModifier())
|
||||
#if os(tvOS)
|
||||
.frame(minHeight: 320)
|
||||
#endif
|
||||
.modifier(AspectRatioModifier())
|
||||
}
|
||||
|
||||
func videoDetail(_ text: String, lineLimit: Int = 1) -> some View {
|
||||
@@ -257,3 +252,13 @@ struct VideoView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoView_Preview: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
VideoCell(video: Video.fixture)
|
||||
}
|
||||
.frame(maxWidth: 300, maxHeight: 200)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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")
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ struct WatchNowSectionBody: View {
|
||||
.padding(.leading, 15)
|
||||
#endif
|
||||
|
||||
VideosCellsHorizontal(videos: videos)
|
||||
HorizontalCells(items: ContentItem.array(of: videos))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user