From ebfa26a65af60e86e7990f28d94400ca1cbec58b Mon Sep 17 00:00:00 2001 From: Aiden Vigue Date: Thu, 20 May 2021 21:36:26 -0400 Subject: [PATCH] Episode dependents --- JellyfinPlayer.xcodeproj/project.pbxproj | 4 + JellyfinPlayer/EpisodeItemView.swift | 591 ++++++++++++++++++++++- JellyfinPlayer/ItemView.swift | 2 + JellyfinPlayer/MovieItemView.swift | 4 +- JellyfinPlayer/SeasonItemView.swift | 187 +++---- 5 files changed, 696 insertions(+), 92 deletions(-) diff --git a/JellyfinPlayer.xcodeproj/project.pbxproj b/JellyfinPlayer.xcodeproj/project.pbxproj index e0838de8..31fb1f7f 100644 --- a/JellyfinPlayer.xcodeproj/project.pbxproj +++ b/JellyfinPlayer.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 538CD957263E441500BB5AF0 /* ExyteGrid in Frameworks */ = {isa = PBXBuildFile; productRef = 538CD956263E441500BB5AF0 /* ExyteGrid */; }; 53987CA426572C1300E7EA70 /* SeasonItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53987CA326572C1300E7EA70 /* SeasonItemView.swift */; }; 53987CA626572F0700E7EA70 /* SeriesItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53987CA526572F0700E7EA70 /* SeriesItemView.swift */; }; + 53987CA82657424A00E7EA70 /* EpisodeItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53987CA72657424A00E7EA70 /* EpisodeItemView.swift */; }; 539B2DA5263BA5B8007FF1A4 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539B2DA4263BA5B8007FF1A4 /* SettingsView.swift */; }; 53A089D0264DA9DA00D57806 /* MovieItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A089CF264DA9DA00D57806 /* MovieItemView.swift */; }; 53D2F74A264C69F6005792BB /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 53D2F749264C69F6005792BB /* Introspect */; }; @@ -78,6 +79,7 @@ 5389277B263CC3DB0035E14B /* BlurHashDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurHashDecode.swift; sourceTree = ""; }; 53987CA326572C1300E7EA70 /* SeasonItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeasonItemView.swift; sourceTree = ""; }; 53987CA526572F0700E7EA70 /* SeriesItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeriesItemView.swift; sourceTree = ""; }; + 53987CA72657424A00E7EA70 /* EpisodeItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EpisodeItemView.swift; sourceTree = ""; }; 539B2DA4263BA5B8007FF1A4 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; 53A089CF264DA9DA00D57806 /* MovieItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieItemView.swift; sourceTree = ""; }; 53D5E3DA264B460200BADDC8 /* Cartfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile; sourceTree = ""; }; @@ -156,6 +158,7 @@ 53EE24E5265060780068F029 /* LibrarySearchView.swift */, 53987CA326572C1300E7EA70 /* SeasonItemView.swift */, 53987CA526572F0700E7EA70 /* SeriesItemView.swift */, + 53987CA72657424A00E7EA70 /* EpisodeItemView.swift */, ); path = JellyfinPlayer; sourceTree = ""; @@ -283,6 +286,7 @@ 53E4E647263F6CF100F67C6B /* LibraryFilterView.swift in Sources */, 53892777263CBB000035E14B /* JellyApiTypings.swift in Sources */, 5377CBF7263B596A003A4E83 /* ContentView.swift in Sources */, + 53987CA82657424A00E7EA70 /* EpisodeItemView.swift in Sources */, 5389277C263CC3DB0035E14B /* BlurHashDecode.swift in Sources */, 53987CA626572F0700E7EA70 /* SeriesItemView.swift in Sources */, 539B2DA5263BA5B8007FF1A4 /* SettingsView.swift in Sources */, diff --git a/JellyfinPlayer/EpisodeItemView.swift b/JellyfinPlayer/EpisodeItemView.swift index 020cba35..58692caa 100644 --- a/JellyfinPlayer/EpisodeItemView.swift +++ b/JellyfinPlayer/EpisodeItemView.swift @@ -2,19 +2,596 @@ // EpisodeItemView.swift // JellyfinPlayer // -// Created by Aiden Vigue on 5/20/21. +// Created by Aiden Vigue on 5/13/21. // import SwiftUI +import SwiftyRequest +import SwiftyJSON +import Introspect +import SDWebImageSwiftUI struct EpisodeItemView: View { - var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + @EnvironmentObject var globalData: GlobalData + @State private var isLoading: Bool = true; + var item: ResumeItem; + var fullItem: DetailItem; + @State private var playing: Bool = false; + @State private var vc: PreferenceUIHostingController? = nil; + @State private var progressString: String = ""; + @State private var watched: Bool = false { + didSet { + if(watched == true) { + let date = Date() + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + print((globalData.server?.baseURI ?? "") + "/Users/\(globalData.user?.user_id ?? "")/PlayedItems/\(fullItem.Id)?DatePlayed=\(formatter.string(from: date).replacingOccurrences(of: ":", with: "%3A"))") + let request = RestRequest(method: .post, url: (globalData.server?.baseURI ?? "") + "/Users/\(globalData.user?.user_id ?? "")/PlayedItems/\(fullItem.Id)?DatePlayed=\(formatter.string(from: date).replacingOccurrences(of: ":", with: "%3A"))") + request.headerParameters["X-Emby-Authorization"] = globalData.authHeader + request.contentType = "application/json" + request.acceptType = "application/json" + + request.responseData() { (result: Result, RestError>) in + } + } else { + let request = RestRequest(method: .delete, url: (globalData.server?.baseURI ?? "") + "/Users/\(globalData.user?.user_id ?? "")/PlayedItems/\(fullItem.Id)") + request.headerParameters["X-Emby-Authorization"] = globalData.authHeader + request.contentType = "application/json" + request.acceptType = "application/json" + + request.responseData() { (result: Result, RestError>) in + } + } + } + }; + + @State private var favorite: Bool = false { + didSet { + if(favorite == true) { + let request = RestRequest(method: .post, url: (globalData.server?.baseURI ?? "") + "/Users/\(globalData.user?.user_id ?? "")/FavoriteItems/\(fullItem.Id)") + request.headerParameters["X-Emby-Authorization"] = globalData.authHeader + request.contentType = "application/json" + request.acceptType = "application/json" + + request.responseData() { (result: Result, RestError>) in + } + } else { + let request = RestRequest(method: .delete, url: (globalData.server?.baseURI ?? "") + "/Users/\(globalData.user?.user_id ?? "")/FavoriteItems/\(fullItem.Id)") + request.headerParameters["X-Emby-Authorization"] = globalData.authHeader + request.contentType = "application/json" + request.acceptType = "application/json" + + request.responseData() { (result: Result, RestError>) in + } + } + } + }; + + init(item: ResumeItem) { + self.item = item; + self.fullItem = DetailItem(); } -} + + func lockOrientations() { + if(_vc.wrappedValue != nil) { + _vc.wrappedValue?._prefersHomeIndicatorAutoHidden = true; + _vc.wrappedValue?._orientations = .landscapeRight; + _vc.wrappedValue?._viewPreference = .dark; + } + } + + func loadData() { + if(_vc.wrappedValue != nil) { + _vc.wrappedValue?._prefersHomeIndicatorAutoHidden = false; + _vc.wrappedValue?._orientations = .allButUpsideDown; + _vc.wrappedValue?._viewPreference = .unspecified; + } + let url = "/Users/\(globalData.user?.user_id ?? "")/Items/\(item.Id)" + + let request = RestRequest(method: .get, url: (globalData.server?.baseURI ?? "") + url) + request.headerParameters["X-Emby-Authorization"] = globalData.authHeader + request.contentType = "application/json" + request.acceptType = "application/json" + + request.responseData() { (result: Result, RestError>) in + switch result { + case .success(let response): + let body = response.body + do { + let json = try JSON(data: body) + fullItem.ProductionYear = json["ProductionYear"].int ?? 0 + fullItem.Poster = json["SeriesPrimaryImageTag"].string ?? "" + fullItem.PosterBlurHash = json["ImageBlurHashes"]["Primary"][fullItem.Poster].string ?? "" + fullItem.Backdrop = json["ParentBackdropImageTags"][0].string ?? "" + fullItem.BackdropBlurHash = json["ImageBlurHashes"]["Backdrop"][fullItem.Backdrop].string ?? "" + fullItem.Name = json["Name"].string ?? "" + fullItem.Type = json["Type"].string ?? "" + fullItem.IndexNumber = json["IndexNumber"].int ?? nil + fullItem.Id = json["Id"].string ?? "" + fullItem.ParentIndexNumber = json["ParentIndexNumber"].int ?? nil + fullItem.SeasonId = json["SeasonId"].string ?? nil + fullItem.SeriesId = json["SeriesId"].string ?? nil + fullItem.Overview = json["Overview"].string ?? "" + fullItem.Tagline = json["Taglines"][0].string ?? "" + fullItem.SeriesName = json["SeriesName"].string ?? nil + fullItem.Progress = Double(json["UserData"]["PlaybackPositionTicks"].int ?? 0) + fullItem.OfficialRating = json["OfficialRating"].string ?? "PG-13" + fullItem.Watched = json["UserData"]["Played"].bool ?? false; + fullItem.CommunityRating = String(json["CommunityRating"].float ?? 0.0); + fullItem.CriticRating = String(json["CriticRating"].int ?? 0); + fullItem.ParentId = json["ParentId"].string ?? "" + fullItem.ParentBackdropItemId = json["ParentBackdropItemId"].string ?? "" + //People + fullItem.Directors = [] + fullItem.Studios = [] + fullItem.Writers = [] + fullItem.Cast = [] + fullItem.Genres = [] + + for (_,person):(String, JSON) in json["People"] { + if(person["Type"].stringValue == "Director") { + fullItem.Directors.append(person["Name"].string ?? ""); + } else if(person["Type"].stringValue == "Writer") { + fullItem.Writers.append(person["Name"].string ?? ""); + } else if(person["Type"].stringValue == "Actor") { + let cast = CastMember(); + cast.Name = person["Name"].string ?? ""; + cast.Id = person["Id"].string ?? ""; + let imageTag = person["PrimaryImageTag"].string ?? ""; + cast.ImageBlurHash = person["ImageBlurHashes"]["Primary"][imageTag].string ?? ""; + cast.Role = person["Role"].string ?? ""; + cast.Image = URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(cast.Id)/Images/Primary?fillHeight=744&fillWidth=496&quality=96&tag=\(imageTag)")! + fullItem.Cast.append(cast); + } + } + + //Studios + for (_,studio):(String, JSON) in json["Studios"] { + fullItem.Studios.append(studio["Name"].string ?? ""); + } + + //Genres + for (_,genre):(String, JSON) in json["GenreItems"] { + let tmpGenre = IVGenre() + tmpGenre.Id = genre["Id"].string ?? ""; + tmpGenre.Name = genre["Name"].string ?? ""; + fullItem.Genres.append(tmpGenre); + } + + _watched.wrappedValue = fullItem.Watched + _favorite.wrappedValue = json["UserData"]["IsFavorite"].bool ?? false; + + //Process runtime + let seconds: Int = ((json["RunTimeTicks"].int ?? 0)/10000000) + fullItem.RuntimeTicks = json["RunTimeTicks"].int ?? 0; + let hours = (seconds/3600) + let minutes = ((seconds - (hours * 3600))/60) + if(hours != 0) { + fullItem.Runtime = "\(hours):\(String(minutes).leftPad(toWidth: 2, withString: "0"))" + } else { + fullItem.Runtime = "\(String(minutes).leftPad(toWidth: 2, withString: "0"))m" + } + + if(fullItem.Progress != 0) { + let remainingSecs = (Double(json["RunTimeTicks"].int ?? 0) - fullItem.Progress)/10000000 + let proghours = Int(remainingSecs/3600) + let progminutes = Int((Int(remainingSecs) - (proghours * 3600))/60) + if(proghours != 0) { + _progressString.wrappedValue = "\(proghours):\(String(progminutes).leftPad(toWidth: 2, withString: "0"))" + } else { + _progressString.wrappedValue = "\(String(progminutes).leftPad(toWidth: 2, withString: "0"))m" + } + } + } catch { + + } + break + case .failure(let error): + debugPrint(error) + break + } + _isLoading.wrappedValue = false; + } + } + + @Environment(\.verticalSizeClass) var verticalSizeClass: UserInterfaceSizeClass? + @Environment(\.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass? -struct EpisodeItemView_Previews: PreviewProvider { - static var previews: some View { - EpisodeItemView() + var isPortrait: Bool { + let result = verticalSizeClass == .regular && horizontalSizeClass == .compact + return result + } + + var body: some View { + if(playing) { + PlayerDemo(item: fullItem, playing: $playing).onAppear(perform: lockOrientations) + } else { + LoadingView(isShowing: $isLoading) { + VStack(alignment:.leading) { + if(!isLoading) { + if(isPortrait) { + GeometryReader { geometry in + VStack() { + WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(fullItem.ParentBackdropItemId)/Images/Backdrop?maxWidth=1000&quality=90&tag=\(fullItem.Backdrop)")!) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (fullItem.BackdropBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.BackdropBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .frame(width: geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing, height: (geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing) * 0.5625) + } + + .opacity(0.4) + .aspectRatio(contentMode: .fill) + .frame(width: geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing, height: (geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing) * 0.5625) + .shadow(radius: 5) + .overlay( + HStack() { + WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(fullItem.SeriesId ?? "")/Images/Primary?fillWidth=300&fillHeight=450&quality=90&tag=\(fullItem.Poster)")!) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (fullItem.PosterBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.PosterBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .frame(width: 120, height: 180) + .cornerRadius(10) + }.aspectRatio(contentMode: .fill) + .frame(width: 120, height: 180) + .cornerRadius(10) + VStack(alignment: .leading) { + Spacer() + Text(fullItem.Name).font(.headline) + .fontWeight(.semibold) + .foregroundColor(.primary) + .fixedSize(horizontal: false, vertical: true) + .offset(y: -4) + HStack() { + Text(String(fullItem.ProductionYear)).font(.subheadline) + .fontWeight(.medium) + .foregroundColor(.secondary) + .lineLimit(1) + Text(fullItem.Runtime).font(.subheadline) + .fontWeight(.medium) + .foregroundColor(.secondary) + .lineLimit(1) + if(fullItem.OfficialRating != "") { + Text(fullItem.OfficialRating).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.secondary) + .lineLimit(1) + .padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4)) + .overlay( + RoundedRectangle(cornerRadius: 2) + .stroke(Color.secondary, lineWidth: 1) + ) + } + if(fullItem.CommunityRating != "") { + HStack() { + Image(systemName: "star").foregroundColor(.secondary) + Text(fullItem.CommunityRating).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.secondary) + .lineLimit(1) + .offset(x: -7, y: 0.7) + } + } + } + + }.offset(x: 0, y: -46).padding(.trailing, 30) + }.offset(x: 16, y: 40) + , alignment: .bottomLeading) + VStack(alignment: .leading) { + HStack() { + //Play button + Button() { + playing = true; + } label: { + HStack() { + Text(fullItem.Progress == 0 ? "Play" : "\(progressString) left").foregroundColor(Color.white).font(.callout).fontWeight(.semibold) + Image(systemName: "play.fill").foregroundColor(Color.white).font(.system(size: 20)) + } + .frame(width: 120, height: 35) + .background(Color(UIColor.systemBlue)) + .cornerRadius(10) + }.buttonStyle(PlainButtonStyle()) + .frame(width: 120, height: 25) + Spacer() + HStack() { + Button() { + favorite.toggle() + } label: { + if(!favorite) { + Image(systemName: "heart").foregroundColor(Color.primary).font(.system(size: 20)) + } else { + Image(systemName: "heart.fill").foregroundColor(Color(UIColor.systemRed)).font(.system(size: 20)) + } + } + Button() { + watched.toggle() + } label: { + if(watched) { + Image(systemName: "checkmark.rectangle.fill").foregroundColor(Color.primary).font(.system(size: 20)) + } else { + Image(systemName: "xmark.rectangle").foregroundColor(Color.primary).font(.system(size: 20)) + } + } + } + }.padding(.leading, 16).padding(.trailing,16) + ScrollView() { + VStack(alignment: .leading) { + if(fullItem.Tagline != "") { + Text(fullItem.Tagline).font(.body).italic().padding(.top, 7).fixedSize(horizontal: false, vertical: true).padding(.leading, 16).padding(.trailing,16) + } + Text(fullItem.Overview).font(.footnote).padding(.top, 3).fixedSize(horizontal: false, vertical: true).padding(.bottom, 3).padding(.leading, 16).padding(.trailing,16) + if(fullItem.Genres.count != 0) { + ScrollView(.horizontal, showsIndicators: false) { + HStack() { + Text("Genres:").font(.callout).fontWeight(.semibold) + ForEach(fullItem.Genres, id: \.Id) {genre in + NavigationLink(destination: LibraryView(extraParams: "&Genres=\(genre.Name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "")", title: genre.Name)) { + Text(genre.Name).font(.footnote) + } + } + }.padding(.leading, 16).padding(.trailing,16) + } + } + if(fullItem.Cast.count != 0) { + ScrollView(.horizontal, showsIndicators: false) { + VStack() { + Spacer().frame(height: 8); + HStack() { + Spacer().frame(width: 16) + ForEach(fullItem.Cast, id: \.Id) { cast in + NavigationLink(destination: LibraryView(extraParams: "&PersonIds=\(cast.Id)", title: cast.Name)) { + VStack() { + WebImage(url: cast.Image) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (cast.ImageBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : cast.ImageBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 100, height: 100) + .cornerRadius(10) + } + .aspectRatio(contentMode: .fill) + .frame(width: 100, height: 100) + .cornerRadius(10).shadow(radius: 6) + Text(cast.Name).font(.footnote).fontWeight(.regular).lineLimit(1).frame(width: 100).foregroundColor(Color.primary) + if(cast.Role != "") { + Text(cast.Role).font(.caption).fontWeight(.medium).lineLimit(1).foregroundColor(Color.secondary).frame(width: 100) + } + } + } + Spacer().frame(width: 10) + } + Spacer().frame(width: 16) + } + } + }.padding(.top, -3) + } + if(fullItem.Directors.count != 0) { + HStack() { + Text("Directors:").font(.callout).fontWeight(.semibold) + Text(fullItem.Directors.joined(separator: ", ")).font(.footnote).lineLimit(1).foregroundColor(Color.secondary) + }.padding(.leading, 16).padding(.trailing,16) + } + if(fullItem.Writers.count != 0) { + HStack() { + Text("Writers:").font(.callout).fontWeight(.semibold) + Text(fullItem.Writers.joined(separator: ", ")).font(.footnote).lineLimit(1).foregroundColor(Color.secondary) + }.padding(.leading, 16).padding(.trailing,16) + } + if(fullItem.Studios.count != 0) { + HStack() { + Text("Studios:").font(.callout).fontWeight(.semibold) + Text(fullItem.Studios.joined(separator: ", ")).font(.footnote).lineLimit(1).foregroundColor(Color.secondary) + }.padding(.leading, 16).padding(.trailing,16) + } + Spacer().frame(height: 3) + } + } + }.padding(EdgeInsets(top: 24, leading: 0, bottom: 0, trailing: 0)) + } + } + } else { + GeometryReader { geometry in + ZStack() { + WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(fullItem.ParentBackdropItemId)/Images/Backdrop?maxWidth=1000&quality=90&tag=\(fullItem.Backdrop)")!) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (fullItem.BackdropBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.BackdropBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .frame(width: geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing, height: (geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing) * 0.5625) + } + + .opacity(0.4) + .aspectRatio(contentMode: .fill) + .frame(width: geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing, height: (geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing) * 0.5625) + .edgesIgnoringSafeArea(.all) + HStack() { + VStack() { + WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(fullItem.SeriesId ?? "")/Images/Primary?maxWidth=300&quality=90&tag=\(fullItem.Poster)")!) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (fullItem.PosterBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.PosterBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .frame(width: 120, height: 180) + } + .aspectRatio(contentMode: .fill) + .frame(width: 120, height: 180) + .cornerRadius(10) + .shadow(radius: 5) + Spacer().frame(height: 15) + Button() { + playing = true; + } label: { + HStack() { + Text(fullItem.Progress == 0 ? "Play" : "\(progressString) left").foregroundColor(Color.white).font(.callout).fontWeight(.semibold) + Image(systemName: "play.fill").foregroundColor(Color.white).font(.system(size: 20)) + } + .frame(width: 120, height: 35) + .background(Color(UIColor.systemBlue)) + .cornerRadius(10) + }.buttonStyle(PlainButtonStyle()) + .frame(width: 120, height: 25) + Spacer() + } + ScrollView() { + VStack(alignment: .leading) { + HStack() { + VStack(alignment: .leading) { + Text(fullItem.Name).font(.headline) + .fontWeight(.semibold) + .foregroundColor(.primary) + .fixedSize(horizontal: false, vertical: true) + .offset(x: 12, y: 0) + Spacer().frame(height: 1) + HStack() { + Text(String(fullItem.ProductionYear)).font(.subheadline) + .fontWeight(.medium) + .foregroundColor(.secondary) + .lineLimit(1) + Text(fullItem.Runtime).font(.subheadline) + .fontWeight(.medium) + .foregroundColor(.secondary) + .lineLimit(1) + if(fullItem.OfficialRating != "") { + Text(fullItem.OfficialRating).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.secondary) + .lineLimit(1) + .padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4)) + .overlay( + RoundedRectangle(cornerRadius: 2) + .stroke(Color.secondary, lineWidth: 1) + ) + } + if(fullItem.CommunityRating != "") { + HStack() { + Image(systemName: "star").foregroundColor(.secondary) + Text(fullItem.CommunityRating).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.secondary) + .lineLimit(1) + .offset(x: -7, y: 0.7) + } + } + Spacer() + }.frame(maxWidth: .infinity) + .offset(x: 12) + }.frame(maxWidth: .infinity) + Spacer() + HStack() { + Button() { + favorite.toggle() + } label: { + if(!favorite) { + Image(systemName: "heart").foregroundColor(Color.primary).font(.system(size: 20)) + } else { + Image(systemName: "heart.fill").foregroundColor(Color(UIColor.systemRed)).font(.system(size: 20)) + } + } + Button() { + watched.toggle() + } label: { + if(watched) { + Image(systemName: "checkmark.rectangle.fill").foregroundColor(Color.primary).font(.system(size: 20)) + } else { + Image(systemName: "xmark.rectangle").foregroundColor(Color.primary).font(.system(size: 20)) + } + } + } + } + if(fullItem.Tagline != "") { + Text(fullItem.Tagline).font(.body).italic().padding(.top, 3).fixedSize(horizontal: false, vertical: true).padding(.leading, 16).padding(.trailing,16) + } + Text(fullItem.Overview).font(.footnote).padding(.top, 3).fixedSize(horizontal: false, vertical: true).padding(.bottom, 3).padding(.leading, 16).padding(.trailing,16) + if(fullItem.Genres.count != 0) { + ScrollView(.horizontal, showsIndicators: false) { + HStack() { + Text("Genres:").font(.callout).fontWeight(.semibold) + ForEach(fullItem.Genres, id: \.Id) {genre in + NavigationLink(destination: LibraryView(extraParams: "&Genres=\(genre.Name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "")", title: genre.Name)) { + Text(genre.Name).font(.footnote) + } + } + }.padding(.leading, 16).padding(.trailing,16) + } + } + if(fullItem.Cast.count != 0) { + ScrollView(.horizontal, showsIndicators: false) { + VStack() { + Spacer().frame(height: 8); + HStack() { + Spacer().frame(width: 16) + ForEach(fullItem.Cast, id: \.Id) { cast in + NavigationLink(destination: LibraryView(extraParams: "&PersonIds=\(cast.Id)", title: cast.Name)) { + VStack() { + WebImage(url: cast.Image) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (cast.ImageBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : cast.ImageBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 100, height: 100) + .cornerRadius(10) + } + .aspectRatio(contentMode: .fill) + .frame(width: 100, height: 100) + .cornerRadius(10).shadow(radius: 6) + Text(cast.Name).font(.footnote).fontWeight(.regular).lineLimit(1).frame(width: 100).foregroundColor(Color.primary) + if(cast.Role != "") { + Text(cast.Role).font(.caption).fontWeight(.medium).lineLimit(1).foregroundColor(Color.secondary).frame(width: 100) + } + } + } + Spacer().frame(width: 10) + } + Spacer().frame(width: 16) + } + } + }.padding(.top, -3) + } + if(fullItem.Directors.count != 0) { + HStack() { + Text("Directors:").font(.callout).fontWeight(.semibold) + Text(fullItem.Directors.joined(separator: ", ")).font(.footnote).lineLimit(1).foregroundColor(Color.secondary) + }.padding(.leading, 16).padding(.trailing,16) + } + if(fullItem.Writers.count != 0) { + HStack() { + Text("Writers:").font(.callout).fontWeight(.semibold) + Text(fullItem.Writers.joined(separator: ", ")).font(.footnote).lineLimit(1).foregroundColor(Color.secondary) + }.padding(.leading, 16).padding(.trailing,16) + } + if(fullItem.Studios.count != 0) { + HStack() { + Text("Studios:").font(.callout).fontWeight(.semibold) + Text(fullItem.Studios.joined(separator: ", ")).font(.footnote).lineLimit(1).foregroundColor(Color.secondary) + }.padding(.leading, 16).padding(.trailing,16) + } + Spacer().frame(height: 195); + }.frame(maxHeight: .infinity) + }.padding(.trailing, 55) + }.padding(.top, 12) + } + } + } + } + } + .navigationBarTitleDisplayMode(.inline) + .navigationTitle(fullItem.Name) + .supportedOrientations(.allButUpsideDown) + .prefersHomeIndicatorAutoHidden(false) + .withHostingWindow() { window in + let rootVC = window?.rootViewController; + let UIHostingcontroller: PreferenceUIHostingController = rootVC as! PreferenceUIHostingController; + vc = UIHostingcontroller; + } + .introspectTabBarController { (UITabBarController) in + UITabBarController.tabBar.isHidden = false + } + }.onAppear(perform: loadData) + } } } diff --git a/JellyfinPlayer/ItemView.swift b/JellyfinPlayer/ItemView.swift index 77467537..c8e6a843 100644 --- a/JellyfinPlayer/ItemView.swift +++ b/JellyfinPlayer/ItemView.swift @@ -27,6 +27,8 @@ struct ItemView: View { SeasonItemView(item: self.item) } else if(item.Type == "Series") { SeriesItemView(item: self.item) + } else if(item.Type == "Episode") { + EpisodeItemView(item: self.item) } else { Text("Type: \(item.Type) not implemented yet :(") } diff --git a/JellyfinPlayer/MovieItemView.swift b/JellyfinPlayer/MovieItemView.swift index 31ae48c3..872aef63 100644 --- a/JellyfinPlayer/MovieItemView.swift +++ b/JellyfinPlayer/MovieItemView.swift @@ -43,6 +43,8 @@ class DetailItem: ObservableObject { @Published var ParentId: String = ""; @Published var Genres: [IVGenre] = []; @Published var ProgressStr: String = ""; + @Published var ResumeItem: ResumeItem? = nil; + @Published var ParentBackdropItemId: String = ""; } class IVGenre: ObservableObject { @@ -322,7 +324,7 @@ struct MovieItemView: View { } } - }.offset(x: 0, y: -46) + }.offset(x: 0, y: -46).padding(.trailing, 30) }.offset(x: 16, y: 40) , alignment: .bottomLeading) VStack(alignment: .leading) { diff --git a/JellyfinPlayer/SeasonItemView.swift b/JellyfinPlayer/SeasonItemView.swift index 18c7624c..106b6591 100644 --- a/JellyfinPlayer/SeasonItemView.swift +++ b/JellyfinPlayer/SeasonItemView.swift @@ -113,6 +113,21 @@ struct SeasonItemView: View { episode.ParentId = episode.SeasonId ?? ""; episode.CommunityRating = String(json["CommunityRating"].float ?? 0.0) + let rI = ResumeItem() + rI.Name = episode.Name; + rI.Id = episode.Id; + rI.IndexNumber = episode.IndexNumber; + rI.ParentIndexNumber = episode.ParentIndexNumber; + rI.Image = episode.Poster; + rI.ImageType = "Primary"; + rI.BlurHash = episode.PosterBlurHash; + rI.Type = "Episode"; + rI.SeasonId = episode.SeasonId; + rI.SeriesId = episode.SeriesId; + rI.SeriesName = episode.SeriesName; + rI.ProductionYear = episode.ProductionYear; + episode.ResumeItem = rI; + let seconds: Int = ((json["RunTimeTicks"].int ?? 0)/10000000) episode.RuntimeTicks = json["RunTimeTicks"].int ?? 0; let hours = (seconds/3600) @@ -218,42 +233,44 @@ struct SeasonItemView: View { } Text(fullItem.Overview).font(.footnote).padding(.top, 3).fixedSize(horizontal: false, vertical: true).padding(.bottom, 3).padding(.leading, 16).padding(.trailing,16) ForEach(episodes, id: \.Id) { episode in - HStack() { - WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(episode.Id)/Images/Primary?maxWidth=1000&quality=90&tag=\(episode.Poster)")!) - .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size - .placeholder { - Image(uiImage: UIImage(blurHash: (episode.PosterBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.PosterBlurHash), size: CGSize(width: 32, height: 32))!) - .resizable() - .frame(width: 150, height: 90) - .cornerRadius(10) - }.aspectRatio(contentMode: .fill) - .shadow(radius: 5) - .frame(width: 150, height: 90) - .cornerRadius(10) - .overlay( - RoundedRectangle(cornerRadius: 10, style: .circular) - .fill(Color(red: 172/255, green: 92/255, blue: 195/255).opacity(0.4)) - .frame(width: CGFloat((episode.Progress/Double(episode.RuntimeTicks))*150), height: 90) - .padding(0), alignment: .bottomLeading - ) - VStack(alignment: .leading) { - HStack() { - Text(episode.Name).font(.subheadline) - .fontWeight(.semibold) - .foregroundColor(.primary) - .fixedSize(horizontal: false, vertical: true) - .lineLimit(1) + NavigationLink(destination: ItemView(item: episode.ResumeItem ?? ResumeItem())) { + HStack() { + WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(episode.Id)/Images/Primary?maxWidth=1000&quality=90&tag=\(episode.Poster)")!) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (episode.PosterBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.PosterBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .frame(width: 150, height: 90) + .cornerRadius(10) + }.aspectRatio(contentMode: .fill) + .shadow(radius: 5) + .frame(width: 150, height: 90) + .cornerRadius(10) + .overlay( + RoundedRectangle(cornerRadius: 10, style: .circular) + .fill(Color(red: 172/255, green: 92/255, blue: 195/255).opacity(0.4)) + .frame(width: CGFloat((episode.Progress/Double(episode.RuntimeTicks))*150), height: 90) + .padding(0), alignment: .bottomLeading + ) + VStack(alignment: .leading) { + HStack() { + Text(episode.Name).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.primary) + .fixedSize(horizontal: false, vertical: true) + .lineLimit(1) + Spacer() + Text(episode.Runtime).font(.subheadline) + .fontWeight(.medium) + .foregroundColor(.secondary) + .lineLimit(1) + } Spacer() - Text(episode.Runtime).font(.subheadline) - .fontWeight(.medium) - .foregroundColor(.secondary) - .lineLimit(1) - } - Spacer() - Text(episode.Overview).font(.footnote).foregroundColor(.secondary).fixedSize(horizontal: false, vertical: true).lineLimit(4) - Spacer() - }.padding(.trailing, 20).offset(y: 2) - }.offset(x: 12, y: 0) + Text(episode.Overview).font(.footnote).foregroundColor(.secondary).fixedSize(horizontal: false, vertical: true).lineLimit(4) + Spacer() + }.padding(.trailing, 20).offset(y: 2) + }.offset(x: 12, y: 0) + } } if(fullItem.Directors.count != 0) { HStack() { @@ -319,63 +336,65 @@ struct SeasonItemView: View { } Text(fullItem.Overview).font(.footnote).padding(.top, 3).fixedSize(horizontal: false, vertical: true).padding(.bottom, 3).padding(.leading, 16).padding(.trailing,16) ForEach(episodes, id: \.Id) { episode in - HStack() { - WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(episode.Id)/Images/Primary?maxWidth=1000&quality=90&tag=\(episode.Poster)")!) - .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size - .placeholder { - Image(uiImage: UIImage(blurHash: (episode.PosterBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.PosterBlurHash), size: CGSize(width: 32, height: 32))!) - .resizable() - .frame(width: 150, height: 90) - .cornerRadius(10) - }.aspectRatio(contentMode: .fill) - .shadow(radius: 5) - .frame(width: 150, height: 90) - .cornerRadius(10) - .overlay( - RoundedRectangle(cornerRadius: 10, style: .circular) - .fill(Color(red: 172/255, green: 92/255, blue: 195/255).opacity(0.4)) - .frame(width: CGFloat((episode.Progress/Double(episode.RuntimeTicks))*150), height: 90) - .padding(0), alignment: .bottomLeading - ) - VStack(alignment: .leading) { - HStack() { - Text(episode.Name).font(.subheadline) - .fontWeight(.semibold) - .foregroundColor(.primary) - .fixedSize(horizontal: false, vertical: true) - .lineLimit(1) - Text(episode.Runtime).font(.subheadline) - .fontWeight(.medium) - .foregroundColor(.secondary) - .lineLimit(1) - if(episode.OfficialRating != "") { - Text(episode.OfficialRating).font(.subheadline) + NavigationLink(destination: ItemView(item: episode.ResumeItem ?? ResumeItem())) { + HStack() { + WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(episode.Id)/Images/Primary?maxWidth=1000&quality=90&tag=\(episode.Poster)")!) + .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size + .placeholder { + Image(uiImage: UIImage(blurHash: (episode.PosterBlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : fullItem.PosterBlurHash), size: CGSize(width: 32, height: 32))!) + .resizable() + .frame(width: 150, height: 90) + .cornerRadius(10) + }.aspectRatio(contentMode: .fill) + .shadow(radius: 5) + .frame(width: 150, height: 90) + .cornerRadius(10) + .overlay( + RoundedRectangle(cornerRadius: 10, style: .circular) + .fill(Color(red: 172/255, green: 92/255, blue: 195/255).opacity(0.4)) + .frame(width: CGFloat((episode.Progress/Double(episode.RuntimeTicks))*150), height: 90) + .padding(0), alignment: .bottomLeading + ) + VStack(alignment: .leading) { + HStack() { + Text(episode.Name).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.primary) + .fixedSize(horizontal: false, vertical: true) + .lineLimit(1) + Text(episode.Runtime).font(.subheadline) .fontWeight(.medium) .foregroundColor(.secondary) .lineLimit(1) - .padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4)) - .overlay( - RoundedRectangle(cornerRadius: 2) - .stroke(Color.secondary, lineWidth: 1) - ) - } - if(episode.CommunityRating != "") { - HStack() { - Image(systemName: "star").foregroundColor(.secondary) - Text(episode.CommunityRating).font(.subheadline) - .fontWeight(.semibold) + if(episode.OfficialRating != "") { + Text(episode.OfficialRating).font(.subheadline) + .fontWeight(.medium) .foregroundColor(.secondary) .lineLimit(1) - .offset(x: -6, y: 0) + .padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4)) + .overlay( + RoundedRectangle(cornerRadius: 2) + .stroke(Color.secondary, lineWidth: 1) + ) } + if(episode.CommunityRating != "") { + HStack() { + Image(systemName: "star").foregroundColor(.secondary) + Text(episode.CommunityRating).font(.subheadline) + .fontWeight(.semibold) + .foregroundColor(.secondary) + .lineLimit(1) + .offset(x: -6, y: 0) + } + } + Spacer() } Spacer() - } - Spacer() - Text(episode.Overview).font(.footnote).foregroundColor(.secondary).fixedSize(horizontal: false, vertical: true).lineLimit(4) - Spacer() - }.padding(.trailing, 20).offset(y: 2) - }.offset(x: 12, y: 0) + Text(episode.Overview).font(.footnote).foregroundColor(.secondary).fixedSize(horizontal: false, vertical: true).lineLimit(4) + Spacer() + }.padding(.trailing, 20).offset(y: 2) + }.offset(x: 12, y: 0) + } } if(fullItem.Directors.count != 0) { HStack() {