yattee/Shared/Channels/ChannelAvatarView.swift

81 lines
2.6 KiB
Swift
Raw Permalink Normal View History

import SwiftUI
struct ChannelAvatarView: View {
var channel: Channel?
var video: Video?
2022-12-11 17:11:56 +00:00
var subscribedBadge = true
@ObservedObject private var accounts = AccountsModel.shared
@ObservedObject private var subscribedChannels = SubscribedChannelsModel.shared
@State private var url: URL?
2023-07-25 11:20:20 +00:00
@State private var loaded = false
var body: some View {
ZStack(alignment: .bottomTrailing) {
Group {
Group {
if let url {
ThumbnailView(url: url)
} else {
ZStack {
2023-07-25 11:20:20 +00:00
if loaded {
Image(systemName: "person.circle")
.imageScale(.large)
.foregroundColor(.accentColor)
} else {
Color("PlaceholderColor")
}
if let video, video.isLocal {
Image(systemName: video.localStreamImageSystemName)
.foregroundColor(.accentColor)
.font(.system(size: 20))
.contentShape(Rectangle())
2023-07-25 11:20:20 +00:00
.imageScale(.small)
}
}
.onAppear(perform: updateURL)
}
}
.clipShape(Circle())
2022-12-11 17:11:56 +00:00
if subscribedBadge,
accounts.app.supportsSubscriptions,
accounts.signedIn,
let channel,
subscribedChannels.isSubscribing(channel.id)
{
Image(systemName: "star.circle.fill")
2022-12-11 17:11:56 +00:00
#if os(tvOS)
.background(Color.black)
2022-12-11 17:11:56 +00:00
#else
.background(Color.background)
#endif
.clipShape(Circle())
.foregroundColor(.secondary)
2023-07-25 11:20:20 +00:00
.imageScale(.small)
}
}
}
}
func updateURL() {
DispatchQueue.global(qos: .userInitiated).async {
if let url = channel?.thumbnailURLOrCached {
DispatchQueue.main.async {
self.url = url
}
}
2023-07-25 11:20:20 +00:00
self.loaded = true
}
}
}
struct ChannelAvatarView_Previews: PreviewProvider {
static var previews: some View {
ChannelAvatarView(channel: Video.fixture.channel)
}
}