summaryrefslogtreecommitdiff
path: root/Jel/Views/Library/ItemIconView.swift
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-01-11 20:44:49 -0500
committerShav Kinderlehrer <[email protected]>2024-01-11 20:44:49 -0500
commit6b8d3372d21149ed0efb4d43bf0cab44bd24f9a4 (patch)
treea6c393738b67dd753efe839aff59193da94b7bb3 /Jel/Views/Library/ItemIconView.swift
parent6edc39791a577a500c92f32361cf1e7d2590ec37 (diff)
downloadjel-6b8d3372d21149ed0efb4d43bf0cab44bd24f9a4.tar.gz
jel-6b8d3372d21149ed0efb4d43bf0cab44bd24f9a4.zip
Implement peopleView
Diffstat (limited to 'Jel/Views/Library/ItemIconView.swift')
-rw-r--r--Jel/Views/Library/ItemIconView.swift106
1 files changed, 0 insertions, 106 deletions
diff --git a/Jel/Views/Library/ItemIconView.swift b/Jel/Views/Library/ItemIconView.swift
deleted file mode 100644
index c2006cc..0000000
--- a/Jel/Views/Library/ItemIconView.swift
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// ItemIconView.swift
-// Jel
-//
-// Created by zerocool on 12/15/23.
-//
-
-import SwiftUI
-import JellyfinKit
-import NukeUI
-
-struct ItemIconView: View {
- @EnvironmentObject var jellyfinClient: JellyfinClientController
-
- var item: BaseItemDto
-
- var imageType: String = "Primary"
- var width: CGFloat?
- var height: CGFloat?
-
- @State var blurHashImage: UIImage = UIImage()
- @State var imageUrl: URL?
- @State var contentMode: ContentMode = .fit
-
- var placeHolder: AnyView?
-
- var shouldShowCaption: Bool = false
- var imageCornerRadius: CGFloat = 5
- var body: some View {
- VStack(alignment: .leading) {
- LazyImage(url: imageUrl) {state in
- if let image = state.image {
- image
- .resizable()
- .aspectRatio(contentMode: contentMode)
- } else {
- if let content = placeHolder {
- content
- } else {
- Image(uiImage: blurHashImage)
- .resizable()
- .aspectRatio(contentMode: .fill)
- }
- }
- }
- .frame(width: width, height: height)
- .clipShape(RoundedRectangle(cornerRadius: imageCornerRadius))
- .onAppear {
- let blurhash = getBlurHash(imageType: imageType)
- blurHashImage = UIImage(blurHash: blurhash, size: CGSize(width: 32, height: 32)) ?? UIImage()
-
- let imageId = item.id ?? ""
- let request = Paths.getItemImage(itemID: imageId, imageType: imageType)
- imageUrl = jellyfinClient.getUrl()?.appending(path: request.url?.absoluteString ?? "")
- }
-
- if shouldShowCaption {
- Text(item.name ?? "Unknown")
- .font(.subheadline)
- }
- }
- }
-
- private func getBlurHash(imageType: String) -> String {
- switch imageType {
- case "Primary":
- return item.imageBlurHashes?.primary?[item.imageTags?[imageType] ?? ""] ?? ""
- case "Backdrop":
- return item.imageBlurHashes?.backdrop?[item.backdropImageTags?[0] ?? ""] ?? ""
- default:
- return ""
- }
- }
-
- func showCaption(_ showCaption: Bool = true) -> Self {
- var copy = self
- copy.shouldShowCaption = showCaption
- return copy
- }
-
- func setCornerRadius(_ cornerRadius: CGFloat = 5) -> Self {
- var copy = self
- copy.imageCornerRadius = cornerRadius
- return copy
- }
-
- func setAspectRatio(_ aspectRatio: Double?) -> Self {
- var copy = self
- if aspectRatio == nil {
- return copy
- }
-
- if let newWidth = copy.width {
- copy.height = newWidth / aspectRatio!
- }
- if let newHeight = copy.height {
- copy.width = newHeight * aspectRatio!
- }
-
- return copy
- }
-}
-
-//#Preview {
-// LibraryIconView(library: BaseItemDto())
-//}