Finish ItemSeriesEpisodeIconView + make geo size globally available

This commit is contained in:
Shav Kinderlehrer 2024-02-21 14:45:48 -05:00
parent ed05643542
commit 2619848a70
7 changed files with 72 additions and 43 deletions

View File

@ -23,6 +23,7 @@
3D41D1FA2B2CAE0000E58234 /* ItemIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */; }; 3D41D1FA2B2CAE0000E58234 /* ItemIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */; };
3D4C15722B3CAA670035373E /* DashboardSectionTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */; }; 3D4C15722B3CAA670035373E /* DashboardSectionTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */; };
3D58F07E2B4DB19300DB2936 /* TextRatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D58F07D2B4DB19300DB2936 /* TextRatingView.swift */; }; 3D58F07E2B4DB19300DB2936 /* TextRatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D58F07D2B4DB19300DB2936 /* TextRatingView.swift */; };
3D6A0DC12B867B4C001FDA40 /* ScreenSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D6A0DC02B867B4C001FDA40 /* ScreenSize.swift */; };
3D6A7DB92B7C5D3900A5E31B /* ItemSeasonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D6A7DB82B7C5D3900A5E31B /* ItemSeasonView.swift */; }; 3D6A7DB92B7C5D3900A5E31B /* ItemSeasonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D6A7DB82B7C5D3900A5E31B /* ItemSeasonView.swift */; };
3D74AE122B7D4EB000C17F2E /* UIScreenWidthExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D74AE112B7D4EB000C17F2E /* UIScreenWidthExtension.swift */; }; 3D74AE122B7D4EB000C17F2E /* UIScreenWidthExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D74AE112B7D4EB000C17F2E /* UIScreenWidthExtension.swift */; };
3D7709392B29139700199889 /* Pulse in Frameworks */ = {isa = PBXBuildFile; productRef = 3D7709382B29139700199889 /* Pulse */; }; 3D7709392B29139700199889 /* Pulse in Frameworks */ = {isa = PBXBuildFile; productRef = 3D7709382B29139700199889 /* Pulse */; };
@ -83,6 +84,7 @@
3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemIconView.swift; sourceTree = "<group>"; }; 3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemIconView.swift; sourceTree = "<group>"; };
3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardSectionTitleView.swift; sourceTree = "<group>"; }; 3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardSectionTitleView.swift; sourceTree = "<group>"; };
3D58F07D2B4DB19300DB2936 /* TextRatingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRatingView.swift; sourceTree = "<group>"; }; 3D58F07D2B4DB19300DB2936 /* TextRatingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRatingView.swift; sourceTree = "<group>"; };
3D6A0DC02B867B4C001FDA40 /* ScreenSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenSize.swift; sourceTree = "<group>"; };
3D6A7DB82B7C5D3900A5E31B /* ItemSeasonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemSeasonView.swift; sourceTree = "<group>"; }; 3D6A7DB82B7C5D3900A5E31B /* ItemSeasonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemSeasonView.swift; sourceTree = "<group>"; };
3D74AE112B7D4EB000C17F2E /* UIScreenWidthExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIScreenWidthExtension.swift; sourceTree = "<group>"; }; 3D74AE112B7D4EB000C17F2E /* UIScreenWidthExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIScreenWidthExtension.swift; sourceTree = "<group>"; };
3D8AB2A42B36440D005BD7D0 /* BlurHashDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurHashDecode.swift; sourceTree = "<group>"; }; 3D8AB2A42B36440D005BD7D0 /* BlurHashDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurHashDecode.swift; sourceTree = "<group>"; };
@ -152,6 +154,7 @@
3D1015E32B28000E00F5C29A /* AuthStateController.swift */, 3D1015E32B28000E00F5C29A /* AuthStateController.swift */,
3DF1ED3D2B282836000AD8EA /* JellyfinClientController.swift */, 3DF1ED3D2B282836000AD8EA /* JellyfinClientController.swift */,
3DC6BA2C2B2A422300416B9F /* SettingsController.swift */, 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */,
3D6A0DC02B867B4C001FDA40 /* ScreenSize.swift */,
); );
path = Controllers; path = Controllers;
sourceTree = "<group>"; sourceTree = "<group>";
@ -386,6 +389,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
3D6A0DC12B867B4C001FDA40 /* ScreenSize.swift in Sources */,
3D9063CD2B279A310063DD2A /* ContentView.swift in Sources */, 3D9063CD2B279A310063DD2A /* ContentView.swift in Sources */,
3D13F96F2B38A32500E91913 /* StickyHeaderView.swift in Sources */, 3D13F96F2B38A32500E91913 /* StickyHeaderView.swift in Sources */,
3DF1ED3E2B282836000AD8EA /* JellyfinClientController.swift in Sources */, 3DF1ED3E2B282836000AD8EA /* JellyfinClientController.swift in Sources */,

View File

@ -0,0 +1,12 @@
//
// ScreenSize.swift
// Jel
//
// Created by zerocool on 2/21/24.
//
import Foundation
class ScreenSize: ObservableObject {
@Published var size: CGSize = CGSize(width: 0, height: 0)
}

View File

@ -16,16 +16,27 @@ struct JelApp: App {
Version: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0.0.0", Version: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0.0.0",
Token: "")) Token: ""))
@StateObject var size: ScreenSize = ScreenSize()
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ContentView() GeometryReader {geo in
.environmentObject(jellyfinClientController) ContentView()
.task { .environmentObject(jellyfinClientController)
AuthStateController.shared.load() .environmentObject(size)
SettingsController.shared.load() .onChange(of: geo.size) {
jellyfinClientController.setUrl(url: AuthStateController.shared.serverUrl) size.size = geo.size
jellyfinClientController.setToken(token: AuthStateController.shared.authToken ?? "") }
} .onAppear {
size.size = geo.size
}
.task {
AuthStateController.shared.load()
SettingsController.shared.load()
jellyfinClientController.setUrl(url: AuthStateController.shared.serverUrl)
jellyfinClientController.setToken(token: AuthStateController.shared.authToken ?? "")
}
}
} }
} }
} }

View File

@ -10,8 +10,7 @@ import JellyfinKit
struct DashboardView: View { struct DashboardView: View {
@State var showingSettingsSheet: Bool = false @State var showingSettingsSheet: Bool = false
@ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var refresh: Bool = true
var body: some View { var body: some View {
ScrollView { ScrollView {
@ -25,23 +24,20 @@ struct DashboardView: View {
.padding([.top, .leading]) .padding([.top, .leading])
} }
} }
} .navigationTitle("Home")
.navigationTitle("Home") .toolbar {
.toolbar { ToolbarItem(placement: .topBarTrailing) {
ToolbarItem(placement: .topBarTrailing) { Button {
Button { showingSettingsSheet.toggle()
showingSettingsSheet.toggle() } label: {
} label: { Label("Settings", systemImage: "gear")
Label("Settings", systemImage: "gear") }
} }
} }
.sheet(isPresented: $showingSettingsSheet) {
SettingsView(showingSettingsView: $showingSettingsSheet)
}
} }
.sheet(isPresented: $showingSettingsSheet) {
SettingsView(showingSettingsView: $showingSettingsSheet)
}
.onChange(of: authState.loggedIn, {
refresh = !authState.loggedIn
})
} }
} }

View File

@ -12,23 +12,30 @@ import ExpandableText
struct ItemSeriesEpisodeIconView: View { struct ItemSeriesEpisodeIconView: View {
var item: BaseItemDto var item: BaseItemDto
@EnvironmentObject var size: ScreenSize
var iconWidthMultiplier: CGFloat = 0.35
var body: some View { var body: some View {
HStack(alignment: .top) { VStack(alignment: .leading) {
VStack(alignment: .leading) { HStack(alignment: .top) {
Text("Episode \(item.indexNumber ?? 0)") ItemIconView(item: item, width: (size.size.width * iconWidthMultiplier), height: (size.size.width * iconWidthMultiplier) / 1.7)
.foregroundStyle(Color.secondary)
.font(.callout) VStack(alignment: .leading) {
ItemIconView(item: item, width: UIScreen.screenWidth * 0.5, contentMode: .fill) Text("Episode \(item.indexNumber ?? 0)")
.setAspectRatio(item.primaryImageAspectRatio ?? 1.7) .foregroundStyle(Color.secondary)
} .font(.caption)
.frame(width: UIScreen.screenWidth * 0.5) Text(item.name ?? "---")
.bold()
VStack(alignment: .leading) { .lineLimit(nil)
Text(item.name ?? "Episode \(item.indexNumber ?? 0)")
.font(.callout) Text(item.overview ?? "")
.bold() .foregroundStyle(Color.secondary)
Text(item.overview ?? "") .font(.callout)
.frame(height: (UIScreen.screenWidth * 0.5) / (item.primaryImageAspectRatio ?? 1.7)) // Calculate optimal amount of lines based on episode image
Spacer()
}
.frame(height: (size.size.width * iconWidthMultiplier) / 1.7)
} }
} }
} }

View File

@ -17,7 +17,7 @@ struct ItemSeriesEpisodesView: View {
@State var episodeItems: [BaseItemDto] = [] @State var episodeItems: [BaseItemDto] = []
var body: some View { var body: some View {
VStack { VStack(alignment: .leading) {
ForEach(episodeItems) {episode in ForEach(episodeItems) {episode in
ItemSeriesEpisodeIconView(item: episode) ItemSeriesEpisodeIconView(item: episode)
} }

View File

@ -8,7 +8,6 @@
import SwiftUI import SwiftUI
struct StickyHeaderView<Content: View>: View { struct StickyHeaderView<Content: View>: View {
var minHeight: CGFloat var minHeight: CGFloat
var content: Content var content: Content
@ -28,7 +27,7 @@ struct StickyHeaderView<Content: View>: View {
.frame(width: geo.size.width, height: geo.size.height + geo.frame(in: .global).minY) .frame(width: geo.size.width, height: geo.size.height + geo.frame(in: .global).minY)
} }
} }
.frame(minWidth: UIScreen.current?.bounds.width ?? 200, minHeight: minHeight) .frame(minWidth: UIScreen.screenWidth, minHeight: minHeight)
} }
} }