Rev 33 | Rev 35 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// GridGalleryView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 3/7/22.//import Foundationimport SwiftUIstruct GridGalleryView: View {@EnvironmentObject private var networkMonitor : NetworkMonitor@EnvironmentObject private var appNavigation : AppNavigation@ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()private var appData = AppData.sharedInstanceprivate var capsuleTitle : String = ""init(){self.viewModel.fetch(capsuleUuid: appData.capsuleUuidActive, userUuid: appData.userUuid)let capsuleDao = CapsuleDao.sharedInstancelet capsule = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)if capsule.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {capsuleTitle = String(Array(capsule.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."} else {capsuleTitle = capsule.name}}@ViewBuildervar body: some View {GeometryReader { geometry inZStack {if self.viewModel.hasPrevious() {Button(action: {print("Button previouse")self.viewModel.previous()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}, label: {Image(systemName: "arrow.left")}).frame(width: 40.0, height: 40.0, alignment: .center).cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/).background(Color("color_button_gallery_background")).foregroundColor(Color("color_button_gallery_foreground")).offset(x: -1 * ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)}if self.viewModel.hasNext() {Button(action: {print("Button next")self.viewModel.next()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}, label: {Image(systemName: "arrow.right")}).frame(width: 40.0, height: 40.0, alignment: .center).background(Color("color_button_gallery_background")).foregroundColor(Color("color_button_gallery_foreground")).offset(x: ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)}VStack(spacing: 0) {HStack {Button(action: {appNavigation.subpageActive = .slides}, label: {Image(systemName: "chevron.backward").frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).aspectRatio(contentMode: .fit).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))}).padding(.leading, 16)Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : capsuleTitle).font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 )).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground")).padding(.leading, 4)Spacer()}.edgesIgnoringSafeArea(.top).frame(height: 50).background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))/*CardGalleryView(slideUuid: self.viewModel.slides[self.viewModel.slideActiveIndex].uuid).environmentObject(appNavigation)Text("slideActive : \(viewModel.slideActiveIndex)")*/GeometryReader { geometry inlet checkMarkX = (geometry.size.width - 50) / 2let checkMarkY = -1 * ((geometry.size.height - 50) / 2)let buttonX = (geometry.size.width - 180) / 2// let buttonY = (geometry.size.height - 80) / 2let buttonY = (geometry.size.height - 100) / 2ZStack {if self.viewModel.slides[self.viewModel.slideActiveIndex].completed == 1 {Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).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 self.viewModel.slides[self.viewModel.slideActiveIndex].background.isEmpty && self.viewModel.slides[self.viewModel.slideActiveIndex].file.isEmpty {Image(uiImage: UIImage(named: "logo") ?? UIImage()).resizable().aspectRatio(contentMode: .fit)} else {CustomAsyncImage(url: URL(string: self.viewModel.slides[self.viewModel.slideActiveIndex].type == Constants.SLIDE_TYPE_IMAGE ? self.viewModel.slides[self.viewModel.slideActiveIndex].file : self.viewModel.slides[self.viewModel.slideActiveIndex].background)!,placeholder: {Spacer()Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)Spacer()},image: {Image(uiImage: $0).resizable()})}}.padding(.horizontal, 5)Spacer()}// .zIndex(500)}}.transition(.slide).gesture(DragGesture(minimumDistance: 60).onEnded {if $0.startLocation.x > $0.location.x {print("left")if self.viewModel.hasPrevious() {print("hasPrevious")self.viewModel.previous()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}} else if $0.startLocation.x < $0.location.x {print("right")if self.viewModel.hasNext() {print("hasNext")self.viewModel.next()print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")self.completeSlide(position: self.viewModel.slideActiveIndex)appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuidappData.save()}} else {print("none")}})/*TabView(selection: self.$selectedTab) {ForEach(0..<self.viewModel.slides.count) { index inCardGalleryView(slideUuid: self.viewModel.slides[index].uuid).environmentObject(appNavigation).tag(index).transition(.slide)}}//.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic)).tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)).onChange(of: self.selectedTab) { selectedTab inappData.slideUuidActive = self.viewModel.slides[selectedTab].uuidappData.save()completeSlide(position: self.selectedTab)}.onAppear {var position : Int = 0var i : Int = 0while i < self.viewModel.slides.count {if appData.slideUuidActive == self.viewModel.slides[i].uuid {position = i}i += 1}self.selectedTab = positioncompleteSlide(position: self.selectedTab)}*/}.onAppear {var position : Int = 0var i : Int = 0while i < self.viewModel.slides.count {if appData.slideUuidActive == self.viewModel.slides[i].uuid {position = i}i += 1}self.viewModel.slideActiveIndex = position}}}}private func completeSlide(position: Int){if self.viewModel.slides[position].type == Constants.SLIDE_TYPE_IMAGE {let dataService = DataService()dataService.completeSlide(slide: self.viewModel.slides[position])}}}struct GridGalleryView_Previews: PreviewProvider {static var previews: some View {//GridGalleryView(capsuleUuid: "C123", position: 2)GridGalleryView()}}