2021-10-22 04:59:10 +05:30
|
|
|
import Foundation
|
|
|
|
import SDWebImageSwiftUI
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChannelCell: View {
|
|
|
|
let channel: Channel
|
|
|
|
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
|
|
|
|
var body: some View {
|
2022-12-11 17:08:57 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
button
|
|
|
|
#else
|
|
|
|
if navigationStyle == .tab {
|
|
|
|
navigationLink
|
|
|
|
} else {
|
|
|
|
button
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var navigationLink: some View {
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: ChannelVideosView(channel: channel)) {
|
2022-12-11 17:08:57 +05:30
|
|
|
labelContent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var button: some View {
|
2021-10-22 04:59:10 +05:30
|
|
|
Button {
|
2022-11-25 02:06:05 +05:30
|
|
|
NavigationModel.shared.openChannel(
|
2021-12-17 22:04:55 +05:30
|
|
|
channel,
|
2022-06-30 13:35:32 +05:30
|
|
|
navigationStyle: navigationStyle
|
2021-12-17 22:04:55 +05:30
|
|
|
)
|
2021-10-22 04:59:10 +05:30
|
|
|
} label: {
|
2022-12-11 17:08:57 +05:30
|
|
|
labelContent
|
2021-10-22 04:59:10 +05:30
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
|
2022-12-11 17:08:57 +05:30
|
|
|
var labelContent: some View {
|
2021-10-22 04:59:10 +05:30
|
|
|
VStack {
|
2022-11-10 23:41:19 +05:30
|
|
|
WebImage(url: channel.thumbnailURL, options: [.lowPriority])
|
2022-09-12 01:03:08 +05:30
|
|
|
.resizable()
|
|
|
|
.placeholder {
|
|
|
|
Rectangle().fill(Color("PlaceholderColor"))
|
2021-10-22 04:59:10 +05:30
|
|
|
}
|
2022-09-12 01:03:08 +05:30
|
|
|
.indicator(.activity)
|
|
|
|
.frame(width: 88, height: 88)
|
|
|
|
.clipShape(Circle())
|
2021-10-22 04:59:10 +05:30
|
|
|
|
2021-10-23 04:34:03 +05:30
|
|
|
DetailBadge(text: channel.name, style: .prominent)
|
2021-10-22 04:59:10 +05:30
|
|
|
|
2021-10-23 04:34:03 +05:30
|
|
|
Group {
|
|
|
|
if let subscriptions = channel.subscriptionsString {
|
|
|
|
Text("\(subscriptions) subscribers")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
} else {
|
|
|
|
Text("")
|
2021-10-22 04:59:10 +05:30
|
|
|
}
|
|
|
|
}
|
2021-10-23 04:34:03 +05:30
|
|
|
.frame(height: 20)
|
2021-10-22 04:59:10 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ChannelSearchItem_Preview: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
Group {
|
|
|
|
ChannelCell(channel: Video.fixture.channel)
|
|
|
|
}
|
|
|
|
.frame(maxWidth: 300, maxHeight: 200)
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|