Advertisement
Guest User

test

a guest
Apr 12th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. //
  2. // Swiftfin is subject to the terms of the Mozilla Public
  3. // License, v2.0. If a copy of the MPL was not distributed with this
  4. // file, you can obtain one at https://mozilla.org/MPL/2.0/.
  5. //
  6. // Copyright (c) 2022 Jellyfin & Jellyfin Contributors
  7. //
  8.  
  9. import Foundation
  10. import SwiftUI
  11.  
  12. struct LiveTVProgramsView: View {
  13. @EnvironmentObject
  14. private var programsRouter: LiveTVProgramsCoordinator.Router
  15. @StateObject
  16. var viewModel = LiveTVProgramsViewModel()
  17.  
  18. var body: some View {
  19. ScrollView {
  20. LazyVStack(alignment: .leading) {
  21. if !viewModel.recommendedItems.isEmpty,
  22. let items = viewModel.recommendedItems
  23. {
  24. Text("On Now")
  25. .font(.headline)
  26. .fontWeight(.semibold)
  27. .padding(.leading, 90)
  28. ScrollView(.horizontal, showsIndicators: false) {
  29. LazyHStack {
  30. Spacer().frame(width: 45)
  31. ForEach(items, id: \.id) { item in
  32. Button {
  33. if let chanId = item.channelId,
  34. let chan = viewModel.findChannel(id: chanId)
  35. {
  36. self.viewModel.fetchVideoPlayerViewModel(item: chan) { playerViewModel in
  37. self.programsRouter.route(to: \.videoPlayer, playerViewModel)
  38. }
  39. }
  40. } label: {
  41. LandscapeItemElement(item: item)
  42. }
  43. .buttonStyle(PlainNavigationLinkButtonStyle())
  44. }
  45. Spacer().frame(width: 45)
  46. }
  47. }.frame(height: 350)
  48. }
  49. if !viewModel.seriesItems.isEmpty,
  50. let items = viewModel.seriesItems
  51. {
  52. Text("Shows")
  53. .font(.headline)
  54. .fontWeight(.semibold)
  55. .padding(.leading, 90)
  56. ScrollView(.horizontal, showsIndicators: false) {
  57. LazyHStack {
  58. Spacer().frame(width: 45)
  59. ForEach(items, id: \.id) { item in
  60. Button {
  61. if let chanId = item.channelId,
  62. let chan = viewModel.findChannel(id: chanId)
  63. {
  64. self.viewModel.fetchVideoPlayerViewModel(item: chan) { playerViewModel in
  65. self.programsRouter.route(to: \.videoPlayer, playerViewModel)
  66. }
  67. }
  68. } label: {
  69. LandscapeItemElement(item: item)
  70. }
  71. .buttonStyle(PlainNavigationLinkButtonStyle())
  72. }
  73. Spacer().frame(width: 45)
  74. }
  75. }.frame(height: 350)
  76. }
  77. if !viewModel.movieItems.isEmpty,
  78. let items = viewModel.movieItems
  79. {
  80. Text("Movies")
  81. .font(.headline)
  82. .fontWeight(.semibold)
  83. .padding(.leading, 90)
  84. ScrollView(.horizontal, showsIndicators: false) {
  85. LazyHStack {
  86. Spacer().frame(width: 45)
  87. ForEach(items, id: \.id) { item in
  88. Button {
  89. if let chanId = item.channelId,
  90. let chan = viewModel.findChannel(id: chanId)
  91. {
  92. self.viewModel.fetchVideoPlayerViewModel(item: chan) { playerViewModel in
  93. self.programsRouter.route(to: \.videoPlayer, playerViewModel)
  94. }
  95. }
  96. } label: {
  97. LandscapeItemElement(item: item)
  98. }
  99. .buttonStyle(PlainNavigationLinkButtonStyle())
  100. }
  101. Spacer().frame(width: 45)
  102. }
  103. }.frame(height: 350)
  104. }
  105. if !viewModel.sportsItems.isEmpty,
  106. let items = viewModel.sportsItems
  107. {
  108. Text("Sports")
  109. .font(.headline)
  110. .fontWeight(.semibold)
  111. .padding(.leading, 90)
  112. ScrollView(.horizontal, showsIndicators: false) {
  113. LazyHStack {
  114. Spacer().frame(width: 45)
  115. ForEach(items, id: \.id) { item in
  116. Button {
  117. if let chanId = item.channelId,
  118. let chan = viewModel.findChannel(id: chanId)
  119. {
  120. self.viewModel.fetchVideoPlayerViewModel(item: chan) { playerViewModel in
  121. self.programsRouter.route(to: \.videoPlayer, playerViewModel)
  122. }
  123. }
  124. } label: {
  125. LandscapeItemElement(item: item)
  126. }
  127. .buttonStyle(PlainNavigationLinkButtonStyle())
  128. }
  129. Spacer().frame(width: 45)
  130. }
  131. }.frame(height: 350)
  132. }
  133. if !viewModel.kidsItems.isEmpty,
  134. let items = viewModel.kidsItems
  135. {
  136. Text("Kids")
  137. .font(.headline)
  138. .fontWeight(.semibold)
  139. .padding(.leading, 90)
  140. ScrollView(.horizontal, showsIndicators: false) {
  141. LazyHStack {
  142. Spacer().frame(width: 45)
  143. ForEach(items, id: \.id) { item in
  144. Button {
  145. if let chanId = item.channelId,
  146. let chan = viewModel.findChannel(id: chanId)
  147. {
  148. self.viewModel.fetchVideoPlayerViewModel(item: chan) { playerViewModel in
  149. self.programsRouter.route(to: \.videoPlayer, playerViewModel)
  150. }
  151. }
  152. } label: {
  153. LandscapeItemElement(item: item)
  154. }
  155. .buttonStyle(PlainNavigationLinkButtonStyle())
  156. }
  157. Spacer().frame(width: 45)
  158. }
  159. }.frame(height: 350)
  160. }
  161. if !viewModel.newsItems.isEmpty,
  162. let items = viewModel.newsItems
  163. {
  164. Text("News")
  165. .font(.headline)
  166. .fontWeight(.semibold)
  167. .padding(.leading, 90)
  168. ScrollView(.horizontal, showsIndicators: false) {
  169. LazyHStack {
  170. Spacer().frame(width: 45)
  171. ForEach(items, id: \.id) { item in
  172. Button {
  173. if let chanId = item.channelId,
  174. let chan = viewModel.findChannel(id: chanId)
  175. {
  176. self.viewModel.fetchVideoPlayerViewModel(item: chan) { playerViewModel in
  177. self.programsRouter.route(to: \.videoPlayer, playerViewModel)
  178. }
  179. }
  180. } label: {
  181. LandscapeItemElement(item: item)
  182. }
  183. .buttonStyle(PlainNavigationLinkButtonStyle())
  184. }
  185. Spacer().frame(width: 45)
  186. }
  187. }.frame(height: 350)
  188. }
  189. }
  190. }
  191. }
  192. }
  193.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement