2021-08-22 19:13:33 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoDetails: View {
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
2021-08-25 22:12:59 +00:00
|
|
|
|
|
|
|
@State private var subscribed = false
|
|
|
|
@State private var confirmationShown = false
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
var video: Video
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video.title)
|
|
|
|
.font(.title2.bold())
|
2021-08-25 22:12:59 +00:00
|
|
|
.padding(.bottom, 0)
|
|
|
|
|
|
|
|
Divider()
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
HStack(alignment: .center) {
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
if subscribed {
|
|
|
|
Image(systemName: "star.circle.fill")
|
|
|
|
}
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video.channel.name)
|
|
|
|
.font(.system(size: 13))
|
|
|
|
.bold()
|
2021-08-31 21:17:50 +00:00
|
|
|
if let subscribers = video.channel.subscriptionsString {
|
|
|
|
Text("\(subscribers) subscribers")
|
2021-08-25 22:12:59 +00:00
|
|
|
.font(.caption2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Section {
|
|
|
|
if subscribed {
|
|
|
|
Button("Unsubscribe") {
|
|
|
|
confirmationShown = true
|
|
|
|
}
|
|
|
|
#if os(iOS)
|
|
|
|
.tint(.gray)
|
|
|
|
#endif
|
|
|
|
.confirmationDialog("Are you you want to unsubscribe from \(video.channel.name)?", isPresented: $confirmationShown) {
|
|
|
|
Button("Unsubscribe") {
|
|
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
|
|
|
|
|
|
withAnimation {
|
|
|
|
subscribed.toggle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button("Subscribe") {
|
|
|
|
subscriptions.subscribe(video.channel.id)
|
|
|
|
|
|
|
|
withAnimation {
|
|
|
|
subscribed.toggle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.tint(.blue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.font(.system(size: 13))
|
|
|
|
.buttonStyle(.borderless)
|
|
|
|
.buttonBorderShape(.roundedRectangle)
|
|
|
|
}
|
|
|
|
.padding(.bottom, -1)
|
|
|
|
|
|
|
|
Divider()
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
HStack(spacing: 4) {
|
|
|
|
if let published = video.publishedDate {
|
|
|
|
Text(published)
|
|
|
|
}
|
|
|
|
|
|
|
|
if let publishedAt = video.publishedAt {
|
|
|
|
if video.publishedDate != nil {
|
|
|
|
Text("•")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.opacity(0.3)
|
|
|
|
}
|
|
|
|
Text(publishedAt.formatted(date: .abbreviated, time: .omitted))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.font(.system(size: 12))
|
2021-08-25 22:12:59 +00:00
|
|
|
.padding(.bottom, -1)
|
2021-08-22 19:13:33 +00:00
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
Divider()
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
HStack {
|
2021-08-25 22:12:59 +00:00
|
|
|
Spacer()
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
if let views = video.viewsCount {
|
2021-08-25 22:12:59 +00:00
|
|
|
videoDetail(label: "Views", value: views, symbol: "eye.fill")
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let likes = video.likesCount {
|
2021-08-25 22:12:59 +00:00
|
|
|
Divider()
|
|
|
|
|
|
|
|
videoDetail(label: "Likes", value: likes, symbol: "hand.thumbsup.circle.fill")
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let dislikes = video.dislikesCount {
|
2021-08-25 22:12:59 +00:00
|
|
|
Divider()
|
|
|
|
|
|
|
|
videoDetail(label: "Dislikes", value: dislikes, symbol: "hand.thumbsdown.circle.fill")
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
|
|
|
|
Spacer()
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
.frame(maxHeight: 35)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
|
|
|
Divider()
|
2021-08-22 19:13:33 +00:00
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
ScrollView(.vertical) {
|
|
|
|
Text(video.description)
|
|
|
|
.font(.caption)
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 100, alignment: .leading)
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Text(video.description)
|
|
|
|
.font(.caption)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ScrollView(.horizontal, showsIndicators: showScrollIndicators) {
|
|
|
|
HStack {
|
|
|
|
ForEach(video.keywords, id: \.self) { keyword in
|
|
|
|
HStack(alignment: .center, spacing: 0) {
|
|
|
|
Text("#")
|
|
|
|
.font(.system(size: 11).bold())
|
|
|
|
|
|
|
|
Text(keyword)
|
|
|
|
.frame(maxWidth: 500)
|
|
|
|
}.foregroundColor(.white)
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
.padding(.horizontal, 8)
|
|
|
|
|
|
|
|
.background(Color("VideoDetailLikesSymbolColor"))
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 3))
|
|
|
|
|
|
|
|
.font(.caption)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.bottom, 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
|
|
|
.padding([.horizontal, .bottom])
|
2021-08-25 22:12:59 +00:00
|
|
|
.onAppear {
|
2021-08-31 21:17:50 +00:00
|
|
|
subscribed = subscriptions.isSubscribing(video.channel.id)
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func videoDetail(label: String, value: String, symbol: String) -> some View {
|
|
|
|
VStack(spacing: 4) {
|
|
|
|
HStack(spacing: 2) {
|
|
|
|
Image(systemName: symbol)
|
|
|
|
|
|
|
|
Text(label.uppercased())
|
|
|
|
}
|
|
|
|
.font(.system(size: 9))
|
|
|
|
.opacity(0.6)
|
|
|
|
|
|
|
|
Text(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
.frame(maxWidth: 100)
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var showScrollIndicators: Bool {
|
|
|
|
#if os(macOS)
|
|
|
|
false
|
|
|
|
#else
|
|
|
|
true
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
struct VideoDetails_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VideoDetails(video: Video.fixture)
|
2021-09-29 11:45:00 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
}
|