summaryrefslogtreecommitdiff
path: root/Jel
diff options
context:
space:
mode:
Diffstat (limited to 'Jel')
-rw-r--r--Jel/Models/JellyfinKitExtensions.swift28
-rw-r--r--Jel/Models/ViewOffsetKey.swift17
-rw-r--r--Jel/Views/Library/Item/ItemHeaderView.swift42
-rw-r--r--Jel/Views/Library/Item/ItemInfoView.swift29
-rw-r--r--Jel/Views/Library/Item/ItemMovieView.swift82
-rw-r--r--Jel/Views/Library/LibraryDetailView.swift1
-rw-r--r--Jel/Views/Library/LibraryIconView.swift2
-rw-r--r--Jel/Views/Utility/StickyHeaderView.swift38
8 files changed, 175 insertions, 64 deletions
diff --git a/Jel/Models/JellyfinKitExtensions.swift b/Jel/Models/JellyfinKitExtensions.swift
new file mode 100644
index 0000000..197731c
--- /dev/null
+++ b/Jel/Models/JellyfinKitExtensions.swift
@@ -0,0 +1,28 @@
+//
+// JellyfinKitExtensions.swift
+// Jel
+//
+// Created by zerocool on 12/24/23.
+//
+
+import Foundation
+import JellyfinKit
+
+extension BaseItemDto {
+ func getRuntime() -> String? {
+ let formatter: DateComponentsFormatter = {
+ let localFormatter = DateComponentsFormatter()
+ localFormatter.unitsStyle = .brief
+ localFormatter.allowedUnits = [.hour, .minute]
+
+ return localFormatter
+ }()
+
+ if let runTimeTicks = self.runTimeTicks {
+ let text = formatter.string(from: Double(runTimeTicks / 10_000_000))
+ return text
+ }
+
+ return nil
+ }
+}
diff --git a/Jel/Models/ViewOffsetKey.swift b/Jel/Models/ViewOffsetKey.swift
new file mode 100644
index 0000000..b118478
--- /dev/null
+++ b/Jel/Models/ViewOffsetKey.swift
@@ -0,0 +1,17 @@
+//
+// ViewOffsetKey.swift
+// Jel
+//
+// Created by zerocool on 12/24/23.
+//
+
+import SwiftUI
+
+/// A preference key to store ScrollView offset
+public struct ViewOffsetKey: PreferenceKey {
+ public typealias Value = CGFloat
+ public static var defaultValue = CGFloat.zero
+ public static func reduce(value: inout Value, nextValue: () -> Value) {
+ value += nextValue()
+ }
+}
diff --git a/Jel/Views/Library/Item/ItemHeaderView.swift b/Jel/Views/Library/Item/ItemHeaderView.swift
index d694c13..2c11719 100644
--- a/Jel/Views/Library/Item/ItemHeaderView.swift
+++ b/Jel/Views/Library/Item/ItemHeaderView.swift
@@ -13,35 +13,43 @@ struct ItemHeaderView: View {
let overlayGradient = LinearGradient(gradient: Gradient(stops: [
.init(color: .clear, location: 0),
- .init(color: .black, location: 0.3),
- .init(color: .black, location: 0.7),
-
- .init(color: .clear, location: 1)
+ .init(color: .black, location: 0.5),
+ // .init(color: .black, location: 0.7),
+ // .init(color: .clear, location: 1)
]), startPoint: .bottom, endPoint: .top)
var body: some View {
ZStack(alignment: .bottom) {
- LibraryIconView(library: item, imageType: "Backdrop", contentMode: .fill)
- .hideCaption()
- .setCornerRadius(0)
- .mask(overlayGradient)
-// .padding(.top, 50)
- .background {
- LibraryIconView(library: item, imageType: "Backdrop", contentMode: .fill)
- .hideCaption()
- .setCornerRadius(0)
- .blur(radius: 50)
- }
+ StickyHeaderView(minHeight: 300) {
+ LibraryIconView(library: item, imageType: "Backdrop", contentMode: .fill)
+ .hideCaption()
+ .setCornerRadius(0)
+ .mask(overlayGradient)
+ .background {
+ LibraryIconView(library: item, imageType: "Backdrop", contentMode: .fill)
+ .hideCaption()
+ .setCornerRadius(0)
+ .blur(radius: 50)
+ }
+ }
HStack {
LibraryIconView(library: item, imageType: "Logo", width: 200, height: 100, placeHolder: AnyView(Text(item.name ?? "Unknown").font(.title).bold().truncationMode(.middle)))
.hideCaption()
.setCornerRadius(0)
.shadow(radius: 10)
+ .frame(alignment: .leading)
Spacer()
+ ItemInfoView(item: item)
+ .foregroundStyle(.white)
}
- .frame(alignment: .leading)
- .padding(.leading)
+ .padding([.leading, .trailing])
+ }
+ .scrollTransition {content, phase in
+ content
+ .scaleEffect(phase.isIdentity ? 1 : 2)
+ .opacity(phase.isIdentity ? 1 : 0.1)
+ .blur(radius: phase.isIdentity ? 0 : 50)
}
}
}
diff --git a/Jel/Views/Library/Item/ItemInfoView.swift b/Jel/Views/Library/Item/ItemInfoView.swift
new file mode 100644
index 0000000..d48dfef
--- /dev/null
+++ b/Jel/Views/Library/Item/ItemInfoView.swift
@@ -0,0 +1,29 @@
+//
+// ItemInfoView.swift
+// Jel
+//
+// Created by zerocool on 12/24/23.
+//
+
+import SwiftUI
+import JellyfinKit
+
+struct ItemInfoView: View {
+ @State var item: BaseItemDto
+
+ var body: some View {
+ VStack(alignment: .leading) {
+ HStack {
+ Text(item.genres?.first ?? "---")
+ Text("•")
+ Text((item.productionYear != nil) ? String(item.productionYear!) : "---")
+ }
+ Text(item.getRuntime() ?? "-:--")
+ }
+ .font(.caption)
+ }
+}
+
+//#Preview {
+// ItemInfoView()
+//}
diff --git a/Jel/Views/Library/Item/ItemMovieView.swift b/Jel/Views/Library/Item/ItemMovieView.swift
index 68ba1b2..be12696 100644
--- a/Jel/Views/Library/Item/ItemMovieView.swift
+++ b/Jel/Views/Library/Item/ItemMovieView.swift
@@ -18,59 +18,50 @@ struct ItemMovieView: View {
@State var navigationTitle: String = ""
var body: some View {
- ScrollView {
- // ItemHeaderView(item: item)
- // .scrollTransition {content, phase in
- // content
- // .scaleEffect(phase.isIdentity ? 1 : 2)
- // .opacity(phase.isIdentity ? 1 : 0.1)
- // .blur(radius: phase.isIdentity ? 0 : 50)
- // }
- ItemHeaderView(item: item)
- .opacity(0) // this is the jankiest thing in existence
- .background {
- GeometryReader {geo in
- ItemHeaderView(item: item)
- .onChange(of: geo.frame(in: .global).minY) {
- navigationTitle = geo.frame(in: .global).minY < 0 ? item.name ?? "Unknown" : ""
- }
- .scaleEffect(1 + (geo.frame(in: .global).minY > 0 ? geo.frame(in: .global).minY * 0.001 : 0))
- .offset(y: 1 + (geo.frame(in: .global).minY > 0 ? geo.frame(in: .global).minY * 0.001 : 0))
- .scrollTransition {content, phase in
- content
- .scaleEffect(phase.isIdentity ? 1 : 2)
- .opacity(phase.isIdentity ? 1 : 0.1)
- .blur(radius: phase.isIdentity ? 0 : 50)
+ VStack {
+ if loading {
+ ProgressView()
+ .progressViewStyle(.circular)
+ } else {
+ ScrollView {
+ ItemHeaderView(item: item)
+ .padding(.bottom)
+ .background {
+ GeometryReader {geo in
+ EmptyView()
+ .onChange(of: geo.frame(in: .global).minY) {
+ let minY = geo.frame(in: .global).minY
+ if minY < 0 {
+ navigationTitle = item.name ?? ""
+ } else {
+ navigationTitle = ""
+ }
+ }
}
+ }
+
+ VStack(alignment: .leading) {
+ Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
+ .font(.headline)
+ .frame(maxWidth: .infinity, alignment: .leading)
+
+ Text(item.overview ?? "---")
}
- }
-
- VStack {
- Text(item.taglines?[0] ?? "Unknown")
- .font(.headline)
- .padding(.top, 20)
-
- Text(item.overview ?? "Unknown")
- .padding()
- Text(item.overview ?? "Unknown")
- .padding()
- Text(item.overview ?? "Unknown")
- .padding()
- Text(item.overview ?? "Unknown")
.padding()
+ }
}
}
- .redacted(reason: loading ? .placeholder : [])
- .ignoresSafeArea(edges: .top)
- .scrollIndicators(.hidden)
.toolbarRole(.editor)
- .navigationTitle(navigationTitle)
.navigationBarTitleDisplayMode(.inline)
+ .navigationTitle(navigationTitle)
+ .ignoresSafeArea(edges: .bottom)
+ .scrollIndicators(.hidden)
.onAppear {
Task {
do {
let request = Paths.getItem(userID: authState.userId ?? "", itemID: item.id ?? "")
- item = try await jellyfinClient.send(request).value
+ let response = try await jellyfinClient.send(request)
+ item = response.value
loading = false
} catch {
}
@@ -79,6 +70,7 @@ struct ItemMovieView: View {
}
}
-#Preview {
- ItemMovieView(item: BaseItemDto())
-}
+//#Preview {
+// ItemMovieView(item: BaseItemDto())
+
+//}
diff --git a/Jel/Views/Library/LibraryDetailView.swift b/Jel/Views/Library/LibraryDetailView.swift
index 4b140df..f4ff93c 100644
--- a/Jel/Views/Library/LibraryDetailView.swift
+++ b/Jel/Views/Library/LibraryDetailView.swift
@@ -47,6 +47,7 @@ struct LibraryDetailView: View {
do {
let res = try await jellyfinClient.send(request)
items = res.value.items
+ items?.sort(by: {$0.name?.lowercased() ?? "" < $1.name?.lowercased() ?? ""})
loading = false
} catch {
}
diff --git a/Jel/Views/Library/LibraryIconView.swift b/Jel/Views/Library/LibraryIconView.swift
index a3f5b55..a849446 100644
--- a/Jel/Views/Library/LibraryIconView.swift
+++ b/Jel/Views/Library/LibraryIconView.swift
@@ -32,8 +32,6 @@ struct LibraryIconView: View {
if let image = state.image {
image
.resizable()
- } else if state.error != nil {
- Color.red
} else {
if let content = placeHolder {
content
diff --git a/Jel/Views/Utility/StickyHeaderView.swift b/Jel/Views/Utility/StickyHeaderView.swift
new file mode 100644
index 0000000..52dc26d
--- /dev/null
+++ b/Jel/Views/Utility/StickyHeaderView.swift
@@ -0,0 +1,38 @@
+//
+// StickyHeaderView.swift
+// Jel
+//
+// Created by zerocool on 12/24/23.
+//
+
+import SwiftUI
+
+struct StickyHeaderView<Content: View>: View {
+
+ var minHeight: CGFloat
+ var content: Content
+
+ init(minHeight: CGFloat = 200, @ViewBuilder content: () -> Content) {
+ self.minHeight = minHeight
+ self.content = content()
+ }
+
+ var body: some View {
+ GeometryReader { geo in
+ if(geo.frame(in: .global).minY <= 0) {
+ content
+ .frame(width: geo.size.width, height: geo.size.height, alignment: .center)
+ } else {
+ content
+ .offset(y: -geo.frame(in: .global).minY)
+ .frame(width: geo.size.width, height: geo.size.height + geo.frame(in: .global).minY)
+ }
+ }.frame(minHeight: minHeight)
+ }
+}
+
+#Preview {
+ StickyHeaderView {
+ Text("Test")
+ }
+}