Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 11 | Rev 17 | Ir a la última revisión | | Comparar con el anterior | 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
8 efrain 11
import NavigationStack
1 efrain 12
 
13
struct CardGalleryView: View {
14
 
8 efrain 15
    @EnvironmentObject private var networkMonitor : NetworkMonitor
1 efrain 16
    @EnvironmentObject private var appNavigation : AppNavigation
17
    @ObservedObject private var viewModel = GalleryCardViewModel()
18
 
8 efrain 19
    @State private var goToVideoPlayer : Bool = false
20
    @State private var goToPdfViewer : Bool = false
21
    @State private var goToWebViewer : Bool = false
22
 
23
    @State private var showGlobalAlert : Bool = false
24
    @State private var titleGlobalAlert : String = ""
25
    @State private var messageGlobalAlert : String = ""
26
 
27
 
14 efrain 28
 
1 efrain 29
 
30
    private var buttonShow : Bool = false
31
    private var buttonTitle : String = ""
32
 
8 efrain 33
 
14 efrain 34
    private let userUuid : String
1 efrain 35
 
36
 
37
 
38
 
39
 
40
    init (slideUuid : String) {
14 efrain 41
        let appDao = AppDao.sharedInstance
11 efrain 42
        let appData = appDao.selectOne()
14 efrain 43
        userUuid = appData.userUuid
44
 
45
        viewModel.fetch(slideUuid: slideUuid, userUuid: userUuid)
1 efrain 46
 
47
 
48
 
49
 
50
 
51
        self.buttonShow = false
52
        if self.viewModel.slide.type == Constants.SLIDE_TYPE_QUIZ  {
53
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_QUIZ
54
            self.buttonShow = true
55
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO {
56
            self.buttonTitle =  Config.LANG_BUTTON_LAUNCH_VIDEO_PLAYER
57
            self.buttonShow = true
58
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO   {
59
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_AUDIO_PLAYER
60
            self.buttonShow = true
61
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {
62
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_VIEW_PDF
63
            self.buttonShow = true
8 efrain 64
 
65
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_TEXT {
14 efrain 66
            self.buttonTitle = Config.LANG_BUTTON_LAUNCH_VIEW_TEXT
8 efrain 67
            self.buttonShow = true
1 efrain 68
        } else {
69
            self.buttonShow = false
70
        }
71
 
72
    }
73
 
74
 
75
 
76
 
77
    var body: some View {
78
        GeometryReader { geometry in
79
            let checkMarkX = (geometry.size.width - 50) / 2
80
            let checkMarkY = -1 * ((geometry.size.height - 50) / 2)
81
 
82
            let buttonX = (geometry.size.width - 180) / 2
83
            let buttonY = (geometry.size.height - 80) / 2
84
 
85
            ZStack {
86
                if self.viewModel.slide.completed == 1  {
8 efrain 87
                    Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).offset(x: checkMarkX, y: checkMarkY).zIndex(10000)
1 efrain 88
                }
89
 
90
                if self.buttonShow {
91
 
92
                    Button(action: {
93
                        btnPlay()
94
                    }, label: {
95
                        Text(self.buttonTitle)
96
                            .font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_BUTTONS))
97
                        .foregroundColor(Color("color_button_gallery_foreground"))
98
 
99
                    })
100
 
101
                    .padding(.vertical, 15)
102
                    .padding(.horizontal, 10)
103
                    .background(Color("color_button_gallery_background"))
104
                    .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
105
                    .offset(x: buttonX, y: buttonY)
106
                    .zIndex(10000)
107
                }
108
 
109
                if (self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0)
110
                    || (self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0) {
111
                    Button(action: {
112
                        if self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0 {
113
 
114
                            appNavigation.subpageActive = .finishtopic
115
 
116
                        } else {
117
                            if self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0 {
118
                                appNavigation.subpageActive = .finishcapsule
119
                            }
120
                        }
121
                    }, label: {
122
                        Text(Config.LANG_BUTTON_FINISH_CAPSULE_OR_TOPIC)
123
                        .font(.callout)
124
                        .foregroundColor(.black)
125
                    })
126
                    .padding()
127
                    .background(Color("color_button_gallery_background"))
128
                    .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
129
                    .zIndex(10000)
130
                }
131
 
132
                VStack {
8 efrain 133
 
134
                    if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO || self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO {
135
                    PushView(
136
                        destination: VideoPlayerView(slideUuid: viewModel.slide.uuid),
137
                        isActive: self.$goToVideoPlayer,
138
                        label: {
139
                            Text("")
140
                        }).frame(height: 0)
141
                    }
142
 
143
                    if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {
144
 
145
                        PushView(
146
                            destination: PdfViewerView(slideUuid: viewModel.slide.uuid),
147
                            isActive: self.$goToPdfViewer,
148
                            label: {
149
                                Text("")
150
                            }).frame(height: 0)
151
                    }
152
 
153
 
154
                    if self.viewModel.slide.type == Constants.SLIDE_TYPE_TEXT {
155
 
156
                        PushView(
157
                            destination: WebViewerView(slideUuid: viewModel.slide.uuid),
158
                            isActive: self.$goToWebViewer,
159
                            label: {
160
                                Text("")
161
                        }).frame(height: 0)
162
                    }
163
 
1 efrain 164
                    Spacer()
165
                    HStack {
166
                        if viewModel.slide.background.isEmpty && viewModel.slide.file.isEmpty {
167
                            Image(uiImage: UIImage(named: "logo") ?? UIImage())
168
                            .resizable()
169
                            .aspectRatio(contentMode: .fit)
170
                        } else {
171
                            CustomAsyncImage(
172
                                url: URL(string: self.viewModel.slide.type == Constants.SLIDE_TYPE_IMAGE ? self.viewModel.slide.file : self.viewModel.slide.background)!,
173
                                placeholder: {
174
                                    Spacer()
175
                                    Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)
176
                                    Spacer()
177
                                },
178
                                image: {
179
                                    Image(uiImage: $0).resizable()
180
                                }
181
                            )
182
                        }
183
                    }.padding(.horizontal, 5)
184
 
185
                    Spacer()
186
                }
187
               // .zIndex(500)
188
 
14 efrain 189
            }.onAppear {
190
                self.viewModel.fetchProgress(slideUuid: self.viewModel.slide.uuid, userUuid: self.userUuid)
191
            }
192
 
193
            /*.onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMPLETED_SLIDE))
1 efrain 194
            { data in
195
               // print("CardGalleryView  Receive " )
11 efrain 196
                let appData = appDao.selectOne()
1 efrain 197
                if data.userInfo != nil {
198
                    if let slideUuid = data.userInfo?["slideUuid"]! as? String {
199
                        if !slideUuid.isEmpty && slideUuid == self.viewModel.slide.uuid {
200
                            self.viewModel.fetchProgress(slideUuid: slideUuid, userUuid: appData.userUuid)
201
                        }
202
                    }
203
                }
14 efrain 204
             }
205
          */
206
             .alert(isPresented: $showGlobalAlert) {
8 efrain 207
                Alert(
208
                    title: Text(self.titleGlobalAlert),
209
                    message: Text(self.messageGlobalAlert),
210
                    dismissButton: .default(Text(Config.LANG_COMMON_OK))
211
                )
1 efrain 212
            }
213
        }
214
    }
215
 
216
    private func btnPlay()
217
    {
218
 
8 efrain 219
        if networkMonitor.status == .disconnected {
1 efrain 220
 
8 efrain 221
            self.titleGlobalAlert = Config.LANG_ERROR_NETWORK_TITLE
222
            self.messageGlobalAlert = Config.LANG_ERROR_NETWORK_MESSAGE_LONG
223
            self.showGlobalAlert  = true
224
            return
225
        }
226
 
227
 
1 efrain 228
        if self.viewModel.slide.type == Constants.SLIDE_TYPE_VIDEO {
229
            AppDelegate.orientationLock = UIInterfaceOrientationMask.landscapeLeft
230
            UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
231
            UIViewController.attemptRotationToDeviceOrientation()
232
 
233
 
8 efrain 234
            self.goToVideoPlayer = true
235
 
236
 
237
 
1 efrain 238
        }  else if self.viewModel.slide.type == Constants.SLIDE_TYPE_AUDIO {
239
 
8 efrain 240
            self.goToVideoPlayer = true
241
 
1 efrain 242
        }  else if self.viewModel.slide.type == Constants.SLIDE_TYPE_DOCUMENT {
243
 
8 efrain 244
            self.goToPdfViewer = true
245
 
1 efrain 246
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_TEXT {
247
 
8 efrain 248
            self.goToWebViewer = true
1 efrain 249
 
250
        } else if self.viewModel.slide.type == Constants.SLIDE_TYPE_QUIZ {
251
 
8 efrain 252
 
1 efrain 253
        }
254
    }
255
 
256
 
257
 
258
}
259
 
260
struct CardGalleryView_Previews: PreviewProvider {
261
    static var previews: some View {
262
        CardGalleryView(slideUuid: "S123")
263
    }
264
 
265
}
266