mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add search
This commit is contained in:
@@ -1,30 +1,14 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@ObservedObject private var popular = PopluarVideosProvider()
|
||||
|
||||
var items: [GridItem] {
|
||||
Array(repeating: .init(.flexible()), count: 4)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
TabView {
|
||||
Group {
|
||||
List {
|
||||
ForEach(popular.videos) { video in
|
||||
VideoThumbnailView(video: video)
|
||||
.listRowInsets(EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30))
|
||||
}
|
||||
}
|
||||
.listStyle(GroupedListStyle())
|
||||
}
|
||||
.tabItem { Text("Popular") }
|
||||
}
|
||||
}
|
||||
.task {
|
||||
async {
|
||||
popular.load()
|
||||
PopularVideosView()
|
||||
.tabItem { Text("Popular") }
|
||||
|
||||
SearchView()
|
||||
.tabItem { Image(systemName: "magnifyingglass") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,68 +0,0 @@
|
||||
import AVKit
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct PlayerView: View {
|
||||
@ObservedObject private var provider: VideoDetailsProvider
|
||||
|
||||
private var id: String
|
||||
|
||||
init(id: String) {
|
||||
self.id = id
|
||||
provider = VideoDetailsProvider(id)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let video = provider.video {
|
||||
if video.url != nil {
|
||||
PlayerViewController(video)
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
}
|
||||
|
||||
if video.error {
|
||||
Text("Video can not be loaded")
|
||||
}
|
||||
}
|
||||
}
|
||||
.task {
|
||||
async {
|
||||
provider.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PlayerViewController: UIViewControllerRepresentable {
|
||||
var video: Video
|
||||
|
||||
init(_ video: Video) {
|
||||
self.video = video
|
||||
}
|
||||
|
||||
private var player: AVPlayer {
|
||||
let item = AVPlayerItem(url: video.url!)
|
||||
item.externalMetadata = [makeMetadataItem(.commonIdentifierTitle, value: video.title)]
|
||||
|
||||
return AVPlayer(playerItem: item)
|
||||
}
|
||||
|
||||
private func makeMetadataItem(_ identifier: AVMetadataIdentifier, value: Any) -> AVMetadataItem {
|
||||
let item = AVMutableMetadataItem()
|
||||
item.identifier = identifier
|
||||
item.value = value as? NSCopying & NSObjectProtocol
|
||||
item.extendedLanguageTag = "und"
|
||||
return item.copy() as! AVMetadataItem
|
||||
}
|
||||
|
||||
func makeUIViewController(context _: Context) -> AVPlayerViewController {
|
||||
let controller = AVPlayerViewController()
|
||||
controller.modalPresentationStyle = .fullScreen
|
||||
controller.player = player
|
||||
controller.title = video.title
|
||||
controller.player?.play()
|
||||
return controller
|
||||
}
|
||||
|
||||
func updateUIViewController(_: AVPlayerViewController, context _: Context) {}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
import SwiftUI
|
||||
import URLImage
|
||||
import URLImageStore
|
||||
|
||||
struct VideoThumbnailView: View {
|
||||
@Environment(\.isFocused) private var focused: Bool
|
||||
|
||||
var video: Video
|
||||
|
||||
var body: some View {
|
||||
NavigationLink(destination: PlayerView(id: video.id)) {
|
||||
HStack(alignment: .top, spacing: 2) {
|
||||
// to replace with AsyncImage when it is fixed with lazy views
|
||||
URLImage(video.thumbnailURL) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: 320, height: 180)
|
||||
}
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.frame(width: 320, height: 180)
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Text(video.title)
|
||||
.foregroundColor(.primary)
|
||||
.bold()
|
||||
.lineLimit(1)
|
||||
|
||||
Text("\(video.author)")
|
||||
.foregroundColor(.secondary)
|
||||
.bold()
|
||||
.lineLimit(1)
|
||||
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "calendar")
|
||||
Text(video.published)
|
||||
|
||||
Image(systemName: "eye")
|
||||
Text(video.viewsCount)
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
.padding(.top)
|
||||
}
|
||||
.padding()
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "clock")
|
||||
|
||||
Text(video.playTime ?? "-")
|
||||
.fontWeight(.bold)
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.frame(minHeight: 180)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoThumbnailView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideoThumbnailView(video: Video(
|
||||
id: "A",
|
||||
title: "A very very long text which",
|
||||
thumbnailURL: URL(string: "https://invidious.home.arekf.net/vi/yXohcxCKqvo/maxres.jpg")!,
|
||||
author: "Bear",
|
||||
length: 240,
|
||||
published: "2 days ago"
|
||||
)).frame(maxWidth: 350)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user