gif previews + handle apple wallpapers

This commit is contained in:
leminlimez committed 2025-07-15 15:13:28 -04:00
1 parent 4d6b093ffd
commit ad280b1a6b
4 files changed
+82 -21

No files matched your search

@@ -7,13 +7,13 @@
class DownloadableWallpaper: Identifiable, Codable {
var name: String
var description: String
var description: String?
var url: String
var preview: String
var authors: String
var authors: String?
var type: WallpaperType?
init(name: String, description: String, authors: String, preview: String, url: String, version: String) {
init(name: String, description: String?, authors: String?, preview: String, url: String, version: String) {
self.name = name
self.description = description
self.authors = authors
@@ -24,4 +24,8 @@ class DownloadableWallpaper: Identifiable, Codable {
enum WallpaperType: String, Codable {
case custom, apple, template
}
func previewIsGif() -> Bool {
return preview.hasSuffix(".gif")
}
}
@@ -7,6 +7,7 @@
import SwiftUI
import CachedAsyncImage
import Giffy
let MIN_SIZE: CGFloat = 165
@@ -50,21 +51,40 @@ struct ExploreView: View {
} else {
LazyVGrid(columns: gridItemLayout) {
ForEach(wallpapers) { wallpaper in
if searchTerm == "" || wallpaper.name.lowercased().contains(searchTerm.lowercased()) || wallpaper.authors.lowercased().contains(searchTerm.lowercased()) {
if searchTerm == "" || wallpaper.name.lowercased().contains(searchTerm.lowercased()) || (wallpaper.authors ?? "").lowercased().contains(searchTerm.lowercased()) {
Button(action: {
DownloadManager.shared.startTendiesDownload(for: cowabungaAPI.getDownloadURLForWallpaper(wallpaper: wallpaper))
}) {
VStack(spacing: 0) {
CachedAsyncImage(url: cowabungaAPI.getPreviewURLForWallpaper(wallpaper: wallpaper), urlCache: .imageCache) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: .infinity)
.cornerRadius(10, corners: .topLeft)
.cornerRadius(10, corners: .topRight)
} placeholder: {
Color.gray
.frame(height: MIN_SIZE)
if wallpaper.previewIsGif() {
AsyncGiffy(url: cowabungaAPI.getPreviewURLForWallpaper(wallpaper: wallpaper)) { phase in
switch phase {
case .loading:
Color.gray
.frame(height: MIN_SIZE)
case .error:
Color.red
.frame(height: MIN_SIZE)
case .success(let giffy):
giffy
.aspectRatio(contentMode: .fill)
.frame(maxWidth: .infinity)
.cornerRadius(10, corners: .topLeft)
.cornerRadius(10, corners: .topRight)
}
}
} else {
CachedAsyncImage(url: cowabungaAPI.getPreviewURLForWallpaper(wallpaper: wallpaper), urlCache: .imageCache) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: .infinity)
.cornerRadius(10, corners: .topLeft)
.cornerRadius(10, corners: .topRight)
} placeholder: {
Color.gray
.frame(height: MIN_SIZE)
}
}
HStack {
VStack(spacing: 4) {
@@ -74,12 +94,14 @@ struct ExploreView: View {
.minimumScaleFactor(0.5)
Spacer()
}
HStack {
Text(wallpaper.authors)
.foregroundColor(.secondary)
.font(.caption)
.minimumScaleFactor(0.5)
Spacer()
if let authors = wallpaper.authors {
HStack {
Text(authors)
.foregroundColor(.secondary)
.font(.caption)
.minimumScaleFactor(0.5)
Spacer()
}
}
}
.lineLimit(1)