Don't reload broken thumbnails

This commit is contained in:
Arkadiusz Fal
2021-10-25 00:26:25 +02:00
parent 1ca7b04e89
commit 3a092fc411
7 changed files with 82 additions and 27 deletions

View File

@@ -15,6 +15,7 @@ struct ContentView: View {
@StateObject private var recents = RecentsModel()
@StateObject private var search = SearchModel()
@StateObject private var subscriptions = SubscriptionsModel()
@StateObject private var thumbnailsModel = ThumbnailsModel()
#if os(iOS)
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@@ -44,6 +45,8 @@ struct ContentView: View {
.environmentObject(recents)
.environmentObject(search)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
.sheet(isPresented: $navigation.presentingWelcomeScreen) {
WelcomeScreen()
.environmentObject(accounts)
@@ -57,6 +60,7 @@ struct ContentView: View {
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
}
#elseif os(macOS)
.sheet(isPresented: $player.presentingPlayer) {
@@ -67,6 +71,7 @@ struct ContentView: View {
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
}
#endif
#if !os(tvOS)

View File

@@ -23,5 +23,7 @@ struct Player: UIViewControllerRepresentable {
return controller
}
func updateUIViewController(_: PlayerViewController, context _: Context) {}
func updateUIViewController(_: PlayerViewController, context _: Context) {
player.rebuildTVMenu()
}
}

View File

@@ -15,7 +15,7 @@ struct HorizontalCells: View {
.padding(.trailing, 20)
.padding(.bottom, 40)
#else
.frame(width: 300)
.frame(width: 285)
#endif
}
}

View File

@@ -4,7 +4,7 @@ import SwiftUI
struct VideoCell: View {
var video: Video
@State private var lowQualityThumbnail = false
@State private var mediumQualityThumbnail = false
@Environment(\.inNavigationView) private var inNavigationView
@@ -14,6 +14,7 @@ struct VideoCell: View {
#endif
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<ThumbnailsModel> private var thumbnails
var body: some View {
Group {
@@ -175,7 +176,7 @@ struct VideoCell: View {
var thumbnail: some View {
ZStack(alignment: .leading) {
thumbnailImage(quality: lowQualityThumbnail ? .medium : .maxresdefault)
thumbnailImage(quality: mediumQualityThumbnail ? .medium : .maxresdefault)
VStack {
HStack(alignment: .top) {
@@ -207,20 +208,38 @@ struct VideoCell: View {
}
func thumbnailImage(quality: Thumbnail.Quality) -> some View {
WebImage(url: video.thumbnailURL(quality: quality))
.resizable()
.placeholder {
Rectangle().fill(Color("PlaceholderColor"))
Group {
if let url = thumbnails.loadableURL(video.thumbnailURL(quality: quality)) {
WebImage(url: url)
.resizable()
.placeholder {
Rectangle().fill(Color("PlaceholderColor"))
}
.retryOnAppear(false)
.onFailure { _ in
if let url = video.thumbnailURL(quality: quality) {
thumbnails.insertUnloadable(url)
}
if !thumbnails.isUnloadable(video.thumbnailURL(quality: .medium)) {
mediumQualityThumbnail = true
}
}
.indicator(.activity)
#if os(tvOS)
.frame(minHeight: 320)
#endif
} else {
ZStack {
Color("PlaceholderColor")
Image(systemName: "exclamationmark.triangle")
}
.font(.system(size: 30))
}
.onFailure { _ in
lowQualityThumbnail = true
}
.indicator(.activity)
.mask(RoundedRectangle(cornerRadius: 12))
.modifier(AspectRatioModifier())
#if os(tvOS)
.frame(minHeight: 320)
#endif
}
.mask(RoundedRectangle(cornerRadius: 12))
.modifier(AspectRatioModifier())
}
func videoDetail(_ text: String, lineLimit: Int = 1) -> some View {