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:
parent
a7d9efdd9d
commit
ef9143263f
@ -15,11 +15,16 @@ final class ThumbnailsModel: ObservableObject {
|
|||||||
return unloadable.contains(url)
|
return unloadable.contains(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadableURL(_ url: URL!) -> URL? {
|
func best(_ video: Video) -> URL? {
|
||||||
guard !url.isNil else {
|
let qualities = [Thumbnail.Quality.maxresdefault, .medium, .default]
|
||||||
return nil
|
|
||||||
|
for quality in qualities {
|
||||||
|
let url = video.thumbnailURL(quality: quality)
|
||||||
|
if !isUnloadable(url) {
|
||||||
|
return url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return isUnloadable(url) ? nil : url
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ struct HorizontalCells: View {
|
|||||||
.padding(.trailing, 20)
|
.padding(.trailing, 20)
|
||||||
.padding(.bottom, 40)
|
.padding(.bottom, 40)
|
||||||
#else
|
#else
|
||||||
.frame(width: 285)
|
.frame(width: 295)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ struct VideoCell: View {
|
|||||||
HStack(alignment: .top, spacing: 2) {
|
HStack(alignment: .top, spacing: 2) {
|
||||||
Section {
|
Section {
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
thumbnailImage(quality: .medium)
|
thumbnailImage
|
||||||
#else
|
#else
|
||||||
thumbnail
|
thumbnail
|
||||||
#endif
|
#endif
|
||||||
@ -224,7 +224,7 @@ struct VideoCell: View {
|
|||||||
|
|
||||||
var thumbnail: some View {
|
var thumbnail: some View {
|
||||||
ZStack(alignment: .leading) {
|
ZStack(alignment: .leading) {
|
||||||
thumbnailImage(quality: mediumQualityThumbnail ? .medium : .maxresdefault)
|
thumbnailImage
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
HStack(alignment: .top) {
|
HStack(alignment: .top) {
|
||||||
@ -257,9 +257,9 @@ struct VideoCell: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func thumbnailImage(quality: Thumbnail.Quality) -> some View {
|
var thumbnailImage: some View {
|
||||||
Group {
|
Group {
|
||||||
if let url = thumbnails.loadableURL(video.thumbnailURL(quality: quality)) {
|
if let url = thumbnails.best(video) {
|
||||||
WebImage(url: url)
|
WebImage(url: url)
|
||||||
.resizable()
|
.resizable()
|
||||||
.placeholder {
|
.placeholder {
|
||||||
@ -267,14 +267,8 @@ struct VideoCell: View {
|
|||||||
}
|
}
|
||||||
.retryOnAppear(false)
|
.retryOnAppear(false)
|
||||||
.onFailure { _ in
|
.onFailure { _ in
|
||||||
if let url = video.thumbnailURL(quality: quality) {
|
|
||||||
thumbnails.insertUnloadable(url)
|
thumbnails.insertUnloadable(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !thumbnails.isUnloadable(video.thumbnailURL(quality: .medium)) {
|
|
||||||
mediumQualityThumbnail = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.indicator(.activity)
|
.indicator(.activity)
|
||||||
|
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
|
Loading…
Reference in New Issue
Block a user