1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30

Improve thumbnails model

This commit is contained in:
Arkadiusz Fal 2021-11-05 21:53:43 +01:00
parent a7d9efdd9d
commit ef9143263f
3 changed files with 14 additions and 15 deletions

View File

@ -15,11 +15,16 @@ final class ThumbnailsModel: ObservableObject {
return unloadable.contains(url)
}
func loadableURL(_ url: URL!) -> URL? {
guard !url.isNil else {
return nil
func best(_ video: Video) -> URL? {
let qualities = [Thumbnail.Quality.maxresdefault, .medium, .default]
for quality in qualities {
let url = video.thumbnailURL(quality: quality)
if !isUnloadable(url) {
return url
}
}
return isUnloadable(url) ? nil : url
return nil
}
}

View File

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

View File

@ -65,7 +65,7 @@ struct VideoCell: View {
HStack(alignment: .top, spacing: 2) {
Section {
#if os(tvOS)
thumbnailImage(quality: .medium)
thumbnailImage
#else
thumbnail
#endif
@ -224,7 +224,7 @@ struct VideoCell: View {
var thumbnail: some View {
ZStack(alignment: .leading) {
thumbnailImage(quality: mediumQualityThumbnail ? .medium : .maxresdefault)
thumbnailImage
VStack {
HStack(alignment: .top) {
@ -257,9 +257,9 @@ struct VideoCell: View {
}
}
func thumbnailImage(quality: Thumbnail.Quality) -> some View {
var thumbnailImage: some View {
Group {
if let url = thumbnails.loadableURL(video.thumbnailURL(quality: quality)) {
if let url = thumbnails.best(video) {
WebImage(url: url)
.resizable()
.placeholder {
@ -267,14 +267,8 @@ struct VideoCell: View {
}
.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)