Refactor
This commit is contained in:
parent
16e3cd6ea5
commit
d10cb35451
|
@ -263,8 +263,8 @@
|
|||
E18845F626DD631E00B0C5B7 /* BaseItemDto+Stackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18845F426DD631E00B0C5B7 /* BaseItemDto+Stackable.swift */; };
|
||||
E18845F826DEA9C900B0C5B7 /* ItemViewBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18845F726DEA9C900B0C5B7 /* ItemViewBody.swift */; };
|
||||
E188460026DECB9E00B0C5B7 /* ItemLandscapeTopBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18845FF26DECB9E00B0C5B7 /* ItemLandscapeTopBarView.swift */; };
|
||||
E188460426DEF04800B0C5B7 /* CardVStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E188460326DEF04800B0C5B7 /* CardVStackView.swift */; };
|
||||
E188460526DEF04800B0C5B7 /* CardVStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E188460326DEF04800B0C5B7 /* CardVStackView.swift */; };
|
||||
E188460426DEF04800B0C5B7 /* EpisodeCardVStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E188460326DEF04800B0C5B7 /* EpisodeCardVStackView.swift */; };
|
||||
E188460526DEF04800B0C5B7 /* EpisodeCardVStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E188460326DEF04800B0C5B7 /* EpisodeCardVStackView.swift */; };
|
||||
E1AD104A26D94822003E4A08 /* DetailItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1AD104926D94822003E4A08 /* DetailItem.swift */; };
|
||||
E1AD104B26D94822003E4A08 /* DetailItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1AD104926D94822003E4A08 /* DetailItem.swift */; };
|
||||
E1AD104D26D96CE3003E4A08 /* BaseItemDtoExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1AD104C26D96CE3003E4A08 /* BaseItemDtoExtensions.swift */; };
|
||||
|
@ -497,7 +497,7 @@
|
|||
E18845F426DD631E00B0C5B7 /* BaseItemDto+Stackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BaseItemDto+Stackable.swift"; sourceTree = "<group>"; };
|
||||
E18845F726DEA9C900B0C5B7 /* ItemViewBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemViewBody.swift; sourceTree = "<group>"; };
|
||||
E18845FF26DECB9E00B0C5B7 /* ItemLandscapeTopBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemLandscapeTopBarView.swift; sourceTree = "<group>"; };
|
||||
E188460326DEF04800B0C5B7 /* CardVStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardVStackView.swift; sourceTree = "<group>"; };
|
||||
E188460326DEF04800B0C5B7 /* EpisodeCardVStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EpisodeCardVStackView.swift; sourceTree = "<group>"; };
|
||||
E1AD104926D94822003E4A08 /* DetailItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailItem.swift; sourceTree = "<group>"; };
|
||||
E1AD104C26D96CE3003E4A08 /* BaseItemDtoExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseItemDtoExtensions.swift; sourceTree = "<group>"; };
|
||||
E1AD105526D981CE003E4A08 /* PortraitHStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortraitHStackView.swift; sourceTree = "<group>"; };
|
||||
|
@ -962,7 +962,7 @@
|
|||
E1AD105B26D9ABDD003E4A08 /* PillHStackView.swift */,
|
||||
E1AD105526D981CE003E4A08 /* PortraitHStackView.swift */,
|
||||
53F866432687A45F00DCD1D7 /* PortraitItemView.swift */,
|
||||
E188460326DEF04800B0C5B7 /* CardVStackView.swift */,
|
||||
E188460326DEF04800B0C5B7 /* EpisodeCardVStackView.swift */,
|
||||
);
|
||||
path = Components;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1533,7 +1533,7 @@
|
|||
53ABFDE4267974EF00886593 /* LibraryListViewModel.swift in Sources */,
|
||||
5364F456266CA0DC0026ECBA /* BaseItemPersonExtensions.swift in Sources */,
|
||||
E1AD105D26D9ABDD003E4A08 /* PillHStackView.swift in Sources */,
|
||||
E188460526DEF04800B0C5B7 /* CardVStackView.swift in Sources */,
|
||||
E188460526DEF04800B0C5B7 /* EpisodeCardVStackView.swift in Sources */,
|
||||
5364F456266CA0DC0026ECBA /* BaseItemPersonExtensions.swift in Sources */,
|
||||
6220D0BE26D60D6600B8E046 /* ItemViewModel.swift in Sources */,
|
||||
531690FA267AD6EC005D8AB9 /* PlainNavigationLinkButton.swift in Sources */,
|
||||
|
@ -1575,7 +1575,7 @@
|
|||
E1FCD08826C35A0D007C8DCF /* NetworkError.swift in Sources */,
|
||||
E18845F826DEA9C900B0C5B7 /* ItemViewBody.swift in Sources */,
|
||||
E173DA5426D050F500CC4EB7 /* ServerDetailViewModel.swift in Sources */,
|
||||
E188460426DEF04800B0C5B7 /* CardVStackView.swift in Sources */,
|
||||
E188460426DEF04800B0C5B7 /* EpisodeCardVStackView.swift in Sources */,
|
||||
53F8377D265FF67C00F456B3 /* VideoPlayerSettingsView.swift in Sources */,
|
||||
53192D5D265AA78A008A4215 /* DeviceProfileBuilder.swift in Sources */,
|
||||
62133890265F83A900A81A2A /* LibraryListView.swift in Sources */,
|
||||
|
|
|
@ -10,9 +10,10 @@
|
|||
import SwiftUI
|
||||
import JellyfinAPI
|
||||
|
||||
struct CardVStackView: View {
|
||||
struct EpisodeCardVStackView: View {
|
||||
|
||||
let items: [BaseItemDto]
|
||||
let selectedAction: (BaseItemDto) -> Void
|
||||
|
||||
private func buildCardOverlayView(item: BaseItemDto) -> some View {
|
||||
HStack {
|
||||
|
@ -45,8 +46,9 @@ struct CardVStackView: View {
|
|||
var body: some View {
|
||||
VStack {
|
||||
ForEach(items, id: \.id) { item in
|
||||
NavigationLink(destination: ItemNavigationView(item: item)) {
|
||||
|
||||
Button {
|
||||
selectedAction(item)
|
||||
} label: {
|
||||
HStack {
|
||||
|
||||
// MARK: Image
|
|
@ -13,11 +13,12 @@ protocol PillStackable {
|
|||
var title: String { get }
|
||||
}
|
||||
|
||||
struct PillHStackView<NavigationView: View, ItemType: PillStackable>: View {
|
||||
struct PillHStackView<ItemType: PillStackable>: View {
|
||||
|
||||
let title: String
|
||||
let items: [ItemType]
|
||||
let navigationView: (ItemType) -> NavigationView
|
||||
// let navigationView: (ItemType) -> NavigationView
|
||||
let selectedAction: (ItemType) -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
|
@ -30,14 +31,14 @@ struct PillHStackView<NavigationView: View, ItemType: PillStackable>: View {
|
|||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack {
|
||||
ForEach(items, id: \.title) { item in
|
||||
NavigationLink(destination: LazyView {
|
||||
navigationView(item)
|
||||
}) {
|
||||
Button {
|
||||
selectedAction(item)
|
||||
} label: {
|
||||
ZStack {
|
||||
Color(UIColor.systemFill)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.cornerRadius(10)
|
||||
|
||||
|
||||
Text(item.title)
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
|
|
|
@ -17,20 +17,20 @@ public protocol PortraitImageStackable {
|
|||
var failureInitials: String { get }
|
||||
}
|
||||
|
||||
struct PortraitImageHStackView<TopBarView: View, NavigationView: View, ItemType: PortraitImageStackable>: View {
|
||||
struct PortraitImageHStackView<TopBarView: View, ItemType: PortraitImageStackable>: View {
|
||||
|
||||
let items: [ItemType]
|
||||
let maxWidth: Int
|
||||
let horizontalAlignment: HorizontalAlignment
|
||||
let topBarView: () -> TopBarView
|
||||
let navigationView: (ItemType) -> NavigationView
|
||||
let selectedAction: (ItemType) -> Void
|
||||
|
||||
init(items: [ItemType], maxWidth: Int, horizontalAlignment: HorizontalAlignment = .leading, topBarView: @escaping () -> TopBarView, navigationView: @escaping (ItemType) -> NavigationView) {
|
||||
init(items: [ItemType], maxWidth: Int, horizontalAlignment: HorizontalAlignment = .leading, topBarView: @escaping () -> TopBarView, selectedAction: @escaping (ItemType) -> Void) {
|
||||
self.items = items
|
||||
self.maxWidth = maxWidth
|
||||
self.horizontalAlignment = horizontalAlignment
|
||||
self.topBarView = topBarView
|
||||
self.navigationView = navigationView
|
||||
self.selectedAction = selectedAction
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
@ -45,38 +45,36 @@ struct PortraitImageHStackView<TopBarView: View, NavigationView: View, ItemType:
|
|||
Spacer().frame(width: 16)
|
||||
|
||||
ForEach(items, id: \.title) { item in
|
||||
NavigationLink(
|
||||
destination: LazyView {
|
||||
navigationView(item)
|
||||
},
|
||||
label: {
|
||||
VStack {
|
||||
ImageView(src: item.imageURLContsructor(maxWidth: maxWidth),
|
||||
bh: item.blurHash,
|
||||
failureInitials: item.failureInitials)
|
||||
.frame(width: 100, height: CGFloat(maxWidth))
|
||||
.cornerRadius(10)
|
||||
.shadow(radius: 4, y: 2)
|
||||
|
||||
Text(item.title)
|
||||
.font(.footnote)
|
||||
.fontWeight(.regular)
|
||||
Button {
|
||||
selectedAction(item)
|
||||
} label: {
|
||||
VStack {
|
||||
ImageView(src: item.imageURLContsructor(maxWidth: maxWidth),
|
||||
bh: item.blurHash,
|
||||
failureInitials: item.failureInitials)
|
||||
.frame(width: 100, height: CGFloat(maxWidth))
|
||||
.cornerRadius(10)
|
||||
.shadow(radius: 4, y: 2)
|
||||
|
||||
Text(item.title)
|
||||
.font(.footnote)
|
||||
.fontWeight(.regular)
|
||||
.frame(width: 100)
|
||||
.foregroundColor(.primary)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
|
||||
if let description = item.description {
|
||||
Text(description)
|
||||
.font(.caption)
|
||||
.fontWeight(.medium)
|
||||
.frame(width: 100)
|
||||
.foregroundColor(.primary)
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
|
||||
if let description = item.description {
|
||||
Text(description)
|
||||
.font(.caption)
|
||||
.fontWeight(.medium)
|
||||
.frame(width: 100)
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer().frame(width: UIDevice.current.userInterfaceIdiom == .pad ? 16 : 55)
|
||||
}
|
||||
|
|
|
@ -33,22 +33,26 @@ struct ItemViewBody: View {
|
|||
.fontWeight(.semibold)
|
||||
.padding(.top, 3)
|
||||
.padding(.leading, 16)
|
||||
}, navigationView: { season in
|
||||
ItemNavigationView(item: season)
|
||||
}, selectedAction: { season in
|
||||
// Router work here to present a:
|
||||
// ItemNavigationView(item: Season)
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: Genres
|
||||
PillHStackView(title: "Genres",
|
||||
items: viewModel.item.genreItems ?? []) { genre in
|
||||
LibraryView(viewModel: .init(genre: genre), title: genre.title)
|
||||
}
|
||||
items: viewModel.item.genreItems ?? [],
|
||||
selectedAction: { genre in
|
||||
// Router work here to present a:
|
||||
// LibraryView(viewModel: .init(genre: genre), title: genre.title)
|
||||
})
|
||||
|
||||
// MARK: Studios
|
||||
if let studios = viewModel.item.studios {
|
||||
PillHStackView(title: "Studios",
|
||||
items: studios) { studio in
|
||||
LibraryView(viewModel: .init(studio: studio), title: studio.name ?? "")
|
||||
// Router work here to present a:
|
||||
// LibraryView(viewModel: .init(studio: studio), title: studio.name ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,8 +67,9 @@ struct ItemViewBody: View {
|
|||
.padding(.top, 3)
|
||||
.padding(.leading, 16)
|
||||
},
|
||||
navigationView: { person in
|
||||
LibraryView(viewModel: .init(person: person), title: person.title)
|
||||
selectedAction: { person in
|
||||
// Router work here to present a:
|
||||
// LibraryView(viewModel: .init(person: person), title: person.title)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -79,8 +84,9 @@ struct ItemViewBody: View {
|
|||
.padding(.top, 3)
|
||||
.padding(.leading, 16)
|
||||
},
|
||||
navigationView: { item in
|
||||
ItemNavigationView(item: item)
|
||||
selectedAction: { item in
|
||||
// Router work here to present a:
|
||||
// ItemNavigationView(item: item)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,10 @@ struct ItemLandscapeMainView: View {
|
|||
// MARK: ItemViewBody
|
||||
|
||||
if let episodeViewModel = viewModel as? SeasonItemViewModel {
|
||||
CardVStackView(items: episodeViewModel.episodes)
|
||||
EpisodeCardVStackView(items: episodeViewModel.episodes) { episode in
|
||||
// Router work here to present a:
|
||||
// ItemNavigationView(item: episode)
|
||||
}
|
||||
} else {
|
||||
ItemViewBody()
|
||||
.environmentObject(viewModel)
|
||||
|
|
|
@ -49,8 +49,11 @@ struct ItemPortraitMainView: View {
|
|||
|
||||
if let episodeViewModel = viewModel as? SeasonItemViewModel {
|
||||
Spacer()
|
||||
CardVStackView(items: episodeViewModel.episodes)
|
||||
.padding(.top, 5)
|
||||
EpisodeCardVStackView(items: episodeViewModel.episodes) { episode in
|
||||
// Router work to present a:
|
||||
// ItemNavigationView(item: episode)
|
||||
}
|
||||
.padding(.top, 5)
|
||||
} else {
|
||||
ItemViewBody()
|
||||
.environmentObject(viewModel)
|
||||
|
|
Loading…
Reference in New Issue