Rev 9 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// CardGalleryView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 3/6/22.//import Foundationimport SwiftUIimport AVKitstruct CardGalleryView: View {@EnvironmentObject private var appNavigation : AppNavigation@ObservedObject private var viewModel = GalleryCardViewModel()private let appData = AppData.sharedInstanceprivate var buttonShow : Bool = falseprivate var buttonTitle : String = ""init (slideUuid : String) {self.viewModel.fetch(slideUuid: slideUuid, userUuid: appData.userUuid)self.buttonShow = falseif self.viewModel.slide.type == Constants.SLIDE_TYPE_QUIZ {self.buttonTitle = Config.LANG_BUTTON_LAUNCH_QUIZself.buttonShow = true} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO {self.buttonTitle = Config.LANG_BUTTON_LAUNCH_VIDEO_PLAYERself.buttonShow = true} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO {self.buttonTitle = Config.LANG_BUTTON_LAUNCH_AUDIO_PLAYERself.buttonShow = true} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {self.buttonTitle = Config.LANG_BUTTON_LAUNCH_VIEW_PDFself.buttonShow = true} else {self.buttonShow = false}}var body: some View {GeometryReader { geometry inlet checkMarkX = (geometry.size.width - 50) / 2let checkMarkY = -1 * ((geometry.size.height - 50) / 2)let buttonX = (geometry.size.width - 180) / 2let buttonY = (geometry.size.height - 80) / 2ZStack {if self.viewModel.slide.completed == 1 {Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).alignmentGuide(.top, computeValue: { dimension in10}).offset(x: checkMarkX, y: checkMarkY).zIndex(10000)}if self.buttonShow {Button(action: {btnPlay()}, label: {Text(self.buttonTitle).font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_BUTTONS)).foregroundColor(Color("color_button_gallery_foreground"))}).padding(.vertical, 15).padding(.horizontal, 10).background(Color("color_button_gallery_background")).cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/).offset(x: buttonX, y: buttonY).zIndex(10000)}if (self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0)|| (self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0) {Button(action: {if self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0 {appNavigation.subpageActive = .finishtopic} else {if self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0 {appNavigation.subpageActive = .finishcapsule}}}, label: {Text(Config.LANG_BUTTON_FINISH_CAPSULE_OR_TOPIC).font(.callout).foregroundColor(.black)}).padding().background(Color("color_button_gallery_background")).cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/).zIndex(10000)}VStack {Spacer()HStack {if viewModel.slide.background.isEmpty && viewModel.slide.file.isEmpty {Image(uiImage: UIImage(named: "logo") ?? UIImage()).resizable().aspectRatio(contentMode: .fit)} else {CustomAsyncImage(url: URL(string: self.viewModel.slide.type == Constants.SLIDE_TYPE_IMAGE ? self.viewModel.slide.file : self.viewModel.slide.background)!,placeholder: {Spacer()Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)Spacer()},image: {Image(uiImage: $0).resizable()})}}.padding(.horizontal, 5)Spacer()}// .zIndex(500)} .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE)){ data in// print("CardGalleryView Receive " )if data.userInfo != nil {if let slideUuid = data.userInfo?["slideUuid"]! as? String {if !slideUuid.isEmpty && slideUuid == self.viewModel.slide.uuid {self.viewModel.fetchProgress(slideUuid: slideUuid, userUuid: appData.userUuid)}}}}}}private func btnPlay(){if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO {AppDelegate.orientationLock = UIInterfaceOrientationMask.landscapeLeftUIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")UIViewController.attemptRotationToDeviceOrientation()appNavigation.subpageActive = .videoplayer} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO {appNavigation.subpageActive = .videoplayer} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {appNavigation.subpageActive = .pdfviewer} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_TEXT {appNavigation.subpageActive = .webviewer} else if self.viewModel.slide.type == Constants.SLIDE_TYPE_QUIZ {appNavigation.subpageActive = .quiz}}}struct CardGalleryView_Previews: PreviewProvider {static var previews: some View {CardGalleryView(slideUuid: "S123")}}