This commit is contained in:
anlicheng 2025-04-14 14:43:41 +08:00
parent 5083375194
commit 2f56bc7e74
6 changed files with 96 additions and 108 deletions

View File

@ -95,19 +95,21 @@ final class DetailModel {
print(code)
print(message)
case .result(let detail):
preloadImages(channels: detail.channels)
await MainActor.run {
self.name = detail.name
self.summary = Utils.converHtmlToString(html: detail.summary) ?? ""
self.thumb = detail.thumb
self.statuses = detail.status.flatMap({ s in
self.statuses = detail.status.flatMap { s in
if let status = DramaStatus(s) {
return [status]
} else {
return []
}
})
self.channels = detail.channels
}
self.channels = detail.channels
self.selectedChannelIdx = 0
self.selectedEpisodes = detail.channels[0].episodes
}
@ -136,4 +138,15 @@ final class DetailModel {
}
}
//
private func preloadImages(channels: [Channel]) {
let cacheManager = CacheManager.shared
channels.forEach { channel in
let urls = channel.episodes.map { $0.thumb }
Task.detached {
try? await cacheManager.preloadImages(urls: urls)
}
}
}
}

View File

@ -168,25 +168,7 @@ extension DetailView {
var body: some View {
VStack(alignment: .center) {
AsyncImage(url: URL(string: episode.thumb)) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 90, height: 70)
.clipped()
default:
Image("ph_img_small")
.resizable()
.aspectRatio(contentMode: .fill)
.clipped()
}
}
FlexImage(urlString: episode.thumb, width: 90, height: 70, placeholder: "ph_img_small")
.frame(width: 90, height: 70)
.overlay(alignment: .topLeading) {
if !episode.num_name.isEmpty {

View File

@ -45,9 +45,23 @@ final class FollowListModel {
case .error(let code, let message):
print("index load data get error_code: \(code), message: \(message)")
case .result(let result):
self.preloadImages(dramas: result.dramas)
await MainActor.run {
self.dramas = result.dramas
}
}
}
private func preloadImages(dramas: [DramaItem]) {
let cacheManager = CacheManager.shared
dramas.forEach { dramaItem in
let urls = dramaItem.episodes.map { $0.thumb }
if urls.count > 0 {
Task.detached(priority: .medium) {
try? await cacheManager.preloadImages(urls: urls)
}
}
}
}
}

View File

@ -83,26 +83,10 @@ extension FollowListView {
var body: some View {
VStack(alignment: .center) {
GeometryReader { geometry in
let width = geometry.frame(in: .local).width
AsyncImage(url: URL(string: item.thumb)) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: geometry.frame(in: .local).width, height: 80)
.clipped()
default:
Image("ph_img_medium")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: geometry.frame(in: .local).width, height: 80)
.clipped()
}
}
.frame(width: geometry.frame(in: .local).width, height: 80)
FlexImage(urlString: item.thumb, width: width, height: 80, placeholder: "ph_img_medium")
.frame(width: width, height: 80)
.overlay(alignment: .topLeading) {
if !item.num_name.isEmpty {
HStack(alignment: .center) {

View File

@ -52,6 +52,8 @@ final class ListModel {
print(code)
print(message)
case .result(let detail):
self.preloadImages(channels: detail.channels)
await MainActor.run {
self.name = detail.name
self.summary = Utils.converHtmlToString(html: detail.summary) ?? ""
@ -69,4 +71,14 @@ final class ListModel {
self.selectedEpisodes = self.channels[channelIdx].episodes
}
private func preloadImages(channels: [Channel]) {
let cacheManager = CacheManager.shared
channels.forEach { channel in
let urls = channel.episodes.map { $0.thumb }
Task.detached {
try? await cacheManager.preloadImages(urls: urls)
}
}
}
}

View File

@ -12,27 +12,10 @@ struct SearchDramaGroupView: View {
let group: SearchModel.DramaGroup
var body: some View {
VStack(alignment: .center, spacing: 10) {
LazyVStack(alignment: .center, spacing: 10) {
ForEach(group.items, id: \.id) { item in
NavigationLink(destination: DetailView(id: item.id)) {
AsyncImage(url: URL(string: item.thumb)) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 180)
.clipped()
default:
Image("ph_img_big")
.resizable()
.aspectRatio(contentMode: .fill)
.clipped()
}
}
FlexImage(urlString: item.thumb, width: 370, height: 180, placeholder: "ph_img_big")
.frame(width: 370, height: 180)
.overlay(alignment: .topLeading) {
VStack(alignment: .leading, spacing: 8) {