Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 8 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
//
2
//  CardGalleryView.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 3/6/22.
6
//
7
 
8
import Foundation
9
import SwiftUI
10
import AVKit
11
 
12
struct CardGalleryView: View {
13
 
14
    @EnvironmentObject private var appNavigation : AppNavigation
15
    @ObservedObject private var viewModel = GalleryCardViewModel()
16
 
17
    private let appData = AppData.sharedInstance
18
 
19
    private var buttonShow : Bool = false
20
    private var buttonTitle : String = ""
21
 
22
 
23
 
24
 
25
 
26
 
27
 
28
    init (slideUuid : String) {
29
 
30
        self.viewModel.fetch(slideUuid: slideUuid, userUuid: appData.userUuid)
31
 
32
 
33
 
34
 
35
 
36
        self.buttonShow = false
37
        if self.viewModel.slide.type == Constants.SLIDE_TYPE_QUIZ  {
38
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_QUIZ
39
            self.buttonShow = true
40
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO {
41
            self.buttonTitle =  Config.LANG_BUTTON_LAUNCH_VIDEO_PLAYER
42
            self.buttonShow = true
43
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO   {
44
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_AUDIO_PLAYER
45
            self.buttonShow = true
46
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {
47
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_VIEW_PDF
48
            self.buttonShow = true
49
        } else {
50
            self.buttonShow = false
51
        }
52
 
53
    }
54
 
55
 
56
 
57
 
58
    var body: some View {
59
 
60
        GeometryReader { geometry in
61
            let checkMarkX = (geometry.size.width - 50) / 2
62
            let checkMarkY = -1 * ((geometry.size.height - 50) / 2)
63
 
64
            let buttonX = (geometry.size.width - 180) / 2
65
            let buttonY = (geometry.size.height - 80) / 2
66
 
67
            ZStack {
68
 
69
                if self.viewModel.slide.completed == 1  {
70
                    Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).alignmentGuide(.top, computeValue: { dimension in
71
                       10
72
                    }).offset(x: checkMarkX, y: checkMarkY).zIndex(10000)
73
                }
74
 
75
                if self.buttonShow {
76
 
77
                    Button(action: {
78
                        btnPlay()
79
                    }, label: {
80
                        Text(self.buttonTitle)
81
                            .font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_BUTTONS))
82
                        .foregroundColor(Color("color_button_gallery_foreground"))
83
 
84
                    })
85
 
86
                    .padding(.vertical, 15)
87
                    .padding(.horizontal, 10)
88
                    .background(Color("color_button_gallery_background"))
89
                    .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
90
                    .offset(x: buttonX, y: buttonY)
91
                    .zIndex(10000)
92
                }
93
 
94
                if (self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0)
95
                    || (self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0) {
96
                    Button(action: {
97
                        if self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0 {
98
 
99
                            appNavigation.subpageActive = .finishtopic
100
 
101
                        } else {
102
                            if self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0 {
103
                                appNavigation.subpageActive = .finishcapsule
104
                            }
105
                        }
106
                    }, label: {
107
                        Text(Config.LANG_BUTTON_FINISH_CAPSULE_OR_TOPIC)
108
                        .font(.callout)
109
                        .foregroundColor(.black)
110
                    })
111
                    .padding()
112
                    .background(Color("color_button_gallery_background"))
113
                    .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
114
                    .zIndex(10000)
115
                }
116
 
117
                VStack {
118
                    Spacer()
119
                    HStack {
120
                        if viewModel.slide.background.isEmpty && viewModel.slide.file.isEmpty {
121
                            Image(uiImage: UIImage(named: "logo") ?? UIImage())
122
                            .resizable()
123
                            .aspectRatio(contentMode: .fit)
124
                        } else {
125
                            CustomAsyncImage(
126
                                url: URL(string: self.viewModel.slide.type == Constants.SLIDE_TYPE_IMAGE ? self.viewModel.slide.file : self.viewModel.slide.background)!,
127
                                placeholder: {
128
                                    Spacer()
129
                                    Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)
130
                                    Spacer()
131
                                },
132
                                image: {
133
                                    Image(uiImage: $0).resizable()
134
                                }
135
                            )
136
                        }
137
                    }.padding(.horizontal, 5)
138
 
139
                    Spacer()
140
                }
141
               // .zIndex(500)
142
 
143
            } .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE))
144
            { data in
145
               // print("CardGalleryView  Receive " )
146
 
147
                if data.userInfo != nil {
148
                    if let slideUuid = data.userInfo?["slideUuid"]! as? String {
149
                        if !slideUuid.isEmpty && slideUuid == self.viewModel.slide.uuid {
150
                            self.viewModel.fetchProgress(slideUuid: slideUuid, userUuid: appData.userUuid)
151
                        }
152
                    }
153
                }
154
 
155
            }
156
        }
157
    }
158
 
159
    private func btnPlay()
160
    {
161
 
162
 
163
        if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO {
164
            AppDelegate.orientationLock = UIInterfaceOrientationMask.landscapeLeft
165
            UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
166
            UIViewController.attemptRotationToDeviceOrientation()
167
 
168
 
169
            appNavigation.subpageActive = .videoplayer
170
        }  else if self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO {
171
 
172
            appNavigation.subpageActive = .videoplayer
173
        }  else if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {
174
 
175
            appNavigation.subpageActive = .pdfviewer
176
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_TEXT {
177
 
178
            appNavigation.subpageActive = .webviewer
179
 
180
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_QUIZ {
181
 
182
            appNavigation.subpageActive = .quiz
183
        }
184
    }
185
 
186
 
187
 
188
}
189
 
190
struct CardGalleryView_Previews: PreviewProvider {
191
    static var previews: some View {
192
        CardGalleryView(slideUuid: "S123")
193
    }
194
 
195
}
196