Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 34 | Rev 36 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 34 Rev 35
Línea 13... Línea 13...
13
struct GridGalleryView: View {
13
struct GridGalleryView: View {
Línea 14... Línea 14...
14
 
14
 
15
    @EnvironmentObject private var networkMonitor : NetworkMonitor
15
    @EnvironmentObject private var networkMonitor : NetworkMonitor
16
    @EnvironmentObject private var appNavigation : AppNavigation
16
    @EnvironmentObject private var appNavigation : AppNavigation
17
    @ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()
-
 
-
 
17
    @ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()
Línea 18... Línea 18...
18
    
18
    @State private var positionVisible: Int = 0
19
 
19
 
-
 
20
 
-
 
21
    private var appData = AppData.sharedInstance
20
 
22
    private var capsuleTitle : String = ""
Línea 21... Línea 23...
21
    private var appData = AppData.sharedInstance
23
    private let rows = [
Línea 41... Línea 43...
41
 
43
 
42
    
44
    
43
    @ViewBuilder
45
    @ViewBuilder
44
    var body: some View {
46
    var body: some View {
45
        GeometryReader { geometry in
-
 
46
        ZStack {
-
 
47
            
-
 
48
            if self.viewModel.hasPrevious()  {
-
 
49
                Button(action: {
-
 
50
                    print("Button previouse")
-
 
51
                    self.viewModel.previous()
-
 
52
                    print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
-
 
53
                    self.completeSlide(position: self.viewModel.slideActiveIndex)
-
 
54
                    
-
 
55
                    appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
56
                    appData.save()
-
 
57
                }, label: {
-
 
Línea 58... Línea -...
58
                    Image(systemName: "arrow.left")
-
 
59
                })
-
 
60
                
-
 
61
                .frame(width: 40.0, height: 40.0, alignment: .center)
-
 
62
                     .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
-
 
63
                .background(Color("color_button_gallery_background"))
-
 
64
                .foregroundColor(Color("color_button_gallery_foreground"))
-
 
65
                    .offset(x: -1 * ((geometry.size.width / 2) - 30), y :  25).zIndex(10000)
47
        GeometryReader { geometry in
66
            }
48
            ZStack {
67
            
49
                
68
            if self.viewModel.hasNext() {
50
                if self.viewModel.hasPrevious()  {
69
                Button(action: {
51
                    Button(action: {
70
                    print("Button next")
52
                        print("Button previouse")
71
                    self.viewModel.next()
53
                        self.viewModel.previous()
72
                    print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
54
                        print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
73
                    self.completeSlide(position: self.viewModel.slideActiveIndex)
55
                        self.completeSlide(position: self.viewModel.slideActiveIndex)
74
                    
-
 
-
 
56
                        
-
 
57
                        appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
58
                        appData.save()
Línea 75... Línea -...
75
                    appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
76
                    appData.save()
59
                    }, label: {
77
                    
-
 
78
                    
60
                        Image(systemName: "arrow.left")
79
                }, label: {
61
                    })
80
                    Image(systemName: "arrow.right")
62
                    
81
                })
63
                    .frame(width: 40.0, height: 40.0, alignment: .center)
82
                .frame(width: 40.0, height: 40.0, alignment: .center)
64
                         .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
83
                .background(Color("color_button_gallery_background"))
65
                    .background(Color("color_button_gallery_background"))
84
                .foregroundColor(Color("color_button_gallery_foreground"))
66
                    .foregroundColor(Color("color_button_gallery_foreground"))
85
                .offset(x: ((geometry.size.width  / 2) - 30), y :  25).zIndex(10000)
-
 
86
            }
67
                        .offset(x: -1 * ((geometry.size.width / 2) - 30), y :  25).zIndex(10000)
-
 
68
                }
-
 
69
                
-
 
70
                if self.viewModel.hasNext() {
-
 
71
                    Button(action: {
Línea 87... Línea -...
87
            
-
 
-
 
72
                        print("Button next")
88
            VStack(spacing: 0) {
73
                        self.viewModel.next()
Línea 89... Línea 74...
89
                HStack {
74
                        print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
90
                    Button(action: {
-
 
91
                        
-
 
92
                       
75
                        self.completeSlide(position: self.viewModel.slideActiveIndex)
93
                        appNavigation.subpageActive = .slides
-
 
94
                        
-
 
95
                        
-
 
96
                    }, label: {
76
                        
97
 
77
                        appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
98
                        
-
 
99
                        Image(systemName: "chevron.backward")
-
 
100
                        .frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
78
                        appData.save()
101
                        .aspectRatio(contentMode: .fit)
79
                        
102
                            .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
80
                        
103
                    })
-
 
104
                    .padding(.leading, 16)
-
 
105
                    
81
                    }, label: {
106
                    Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT :  capsuleTitle)
-
 
107
                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
-
 
108
                        .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
-
 
109
                        .padding(.leading, 4)
-
 
110
                    
-
 
111
                    Spacer()
-
 
Línea 112... Línea -...
112
                }
-
 
113
                .edgesIgnoringSafeArea(.top)
82
                        Image(systemName: "arrow.right")
114
                .frame(height: 50)
-
 
115
                .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
83
                    })
116
        
84
                    .frame(width: 40.0, height: 40.0, alignment: .center)
117
        
-
 
118
                Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
-
 
119
                
85
                    .background(Color("color_button_gallery_background"))
120
                /*
-
 
121
                CardGalleryView(
-
 
122
                    slideUuid:  self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
123
                )
86
                    .foregroundColor(Color("color_button_gallery_foreground"))
124
                .environmentObject(appNavigation)
-
 
125
                Text("slideActive : \(viewModel.slideActiveIndex)")
87
                    .offset(x: ((geometry.size.width  / 2) - 30), y :  25).zIndex(10000)
126
 */
88
                }
127
                    
-
 
128
                GeometryReader { geometry in
89
                
129
                    let checkMarkX = (geometry.size.width - 50) / 2
90
                VStack(spacing: 0) {
Línea -... Línea 91...
-
 
91
                    HStack {
-
 
92
                        Button(action: {
-
 
93
                            
-
 
94
                           
-
 
95
                            appNavigation.subpageActive = .slides
-
 
96
                            
-
 
97
                            
Línea -... Línea 98...
-
 
98
                        }, label: {
130
                    let checkMarkY = -1 * ((geometry.size.height - 50) / 2)
99
 
131
                    
100
                            
132
                    let buttonX = (geometry.size.width - 180) / 2
-
 
133
                   // let buttonY = (geometry.size.height - 80) / 2
-
 
134
                    
101
                            Image(systemName: "chevron.backward")
Línea 135... Línea 102...
135
                    let buttonY = (geometry.size.height - 100) / 2
102
                            .frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
136
                  
103
                            .aspectRatio(contentMode: .fit)
137
                    ZStack {
104
                                .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
138
 
105
                        })
139
                        
-
 
140
                        if self.viewModel.slides[self.viewModel.slideActiveIndex].completed == 1  {
106
                        .padding(.leading, 16)
141
                            Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).offset(x: checkMarkX, y: checkMarkY).zIndex(10000)
107
                        
142
                        }
-
 
143
                        /*
108
                        Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT :  capsuleTitle)
144
                        if self.buttonShow {
-
 
145
                        
-
 
146
                            Button(action: {
109
                        .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
147
                                btnPlay()
-
 
148
                            }, label: {
-
 
149
                                Text(self.buttonTitle)
-
 
150
                                    .font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_BUTTONS))
-
 
-
 
110
                            .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
Línea 151... Línea 111...
151
                                .foregroundColor(Color("color_button_gallery_foreground"))
111
                            .padding(.leading, 4)
152
                               
112
                        
153
                            })
113
                        Spacer()
154
                      
114
                    }
155
                            .padding(.vertical, 15)
-
 
156
                            .padding(.horizontal, 10)
115
                    .edgesIgnoringSafeArea(.top)
157
                            .background(Color("color_button_gallery_background"))
-
 
-
 
116
                    .frame(height: 50)
158
                            .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
117
                    .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
159
                            .offset(x: buttonX, y: buttonY)
118
            
160
                            .zIndex(10000)
119
            
161
                        }
120
                    Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
162
                        
121
                    
163
                        if (self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0)
-
 
164
                            || (self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0) {
-
 
165
                            Button(action: {
-
 
166
                                if self.viewModel.progressTopic >= 100 && self.viewModel.completedTopic == 0 {
-
 
167
                                
122
                        
168
                                    appNavigation.subpageActive = .finishtopic
-
 
169
                                    
-
 
170
                                } else {
-
 
171
                                    if self.viewModel.progressCapsule >= 100 && self.viewModel.completedCapsule == 0 {
-
 
172
                                        appNavigation.subpageActive = .finishcapsule
-
 
173
                                    }
-
 
174
                                }
-
 
175
                            }, label: {
-
 
176
                                Text(Config.LANG_BUTTON_FINISH_CAPSULE_OR_TOPIC)
-
 
Línea -... Línea 123...
-
 
123
                    ScrollViewReader { scrollProxy in
-
 
124
                        ScrollView(.horizontal) {
-
 
125
                            LazyHGrid(rows: rows, alignment: .center) {
-
 
126
                                ForEach(0..<self.viewModel.slides.count) { index in
Línea 177... Línea -...
177
                                .font(.callout)
-
 
178
                                .foregroundColor(.black)
-
 
179
                            })
-
 
180
                            .padding()
-
 
181
                            .background(Color("color_button_gallery_background"))
-
 
182
                            .cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
-
 
183
                            .zIndex(10000)
-
 
184
                        }
-
 
185
                         */
127
                                    CardGalleryView(
186
                       
-
 
187
                        VStack {
-
 
188
                        
-
 
189
                            
-
 
190
                            
-
 
191
                            Spacer()
-
 
192
                            HStack {
-
 
193
                                if self.viewModel.slides[self.viewModel.slideActiveIndex].background.isEmpty && self.viewModel.slides[self.viewModel.slideActiveIndex].file.isEmpty {
-
 
194
                                    Image(uiImage: UIImage(named: "logo") ?? UIImage())
-
 
195
                                    .resizable()
-
 
196
                                    .aspectRatio(contentMode: .fit)
128
                                        slideUuid:  self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
Línea 197... Línea -...
197
                                } else {
-
 
198
                                    CustomAsyncImage(
129
                                    )
199
                                        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)!,
130
                                    .environmentObject(appNavigation)
200
                                        placeholder: {
-
 
201
                                            Spacer()
-
 
202
                                            Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)
-
 
203
                                            Spacer()
-
 
204
                                        },
-
 
205
                                        image: {
-
 
206
                                            Image(uiImage: $0).resizable()
131
                                    .frame(width: geometry.size.width, height: geometry.size.height)
207
                                        }
132
                                    .id(index)
208
                                    )
-
 
209
                                }
-
 
210
                            }.padding(.horizontal, 5)
133
                                }
211
 
-
 
212
                            Spacer()
-
 
213
                        }
-
 
214
                       // .zIndex(500)
134
                            }
215
                      
135
                            
216
                    }
136
                        }
217
                }
-
 
218
                .transition(.slide)
137
       
219
                .gesture(
-
 
220
                    DragGesture(minimumDistance: 60).onEnded {
-
 
221
                        if $0.startLocation.x > $0.location.x {
-
 
222
                            print("left")
-
 
223
                            if self.viewModel.hasPrevious()  {
-
 
224
                                print("hasPrevious")
-
 
225
                                self.viewModel.previous()
-
 
226
                                print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
-
 
227
                                self.completeSlide(position: self.viewModel.slideActiveIndex)
138
                        .onChange(of: self.positionVisible) { id in
228
                                    
-
 
229
                                appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
230
                                appData.save()
-
 
231
                            }
-
 
232
                        } else if $0.startLocation.x < $0.location.x {
-
 
233
                            print("right")
-
 
234
                            if self.viewModel.hasNext() {
-
 
235
                                print("hasNext")
-
 
236
                                self.viewModel.next()
-
 
237
                                print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
-
 
238
                                self.completeSlide(position: self.viewModel.slideActiveIndex)
-
 
239
                                    
-
 
240
                                appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
-
 
241
                                appData.save()
-
 
242
                            }
-
 
243
                        } else {
-
 
244
                            print("none")
-
 
245
                        }
-
 
246
                        
-
 
247
                        
-
 
248
                        
-
 
Línea 249... Línea -...
249
                        
-
 
250
                    })
-
 
251
                    
-
 
252
                
-
 
253
                
-
 
254
                
-
 
255
                /*
-
 
256
                TabView(selection: self.$selectedTab) {
-
 
257
                    ForEach(0..<self.viewModel.slides.count) { index in
-
 
258
                        CardGalleryView(
-
 
259
                            slideUuid:  self.viewModel.slides[index].uuid
-
 
260
                        )
-
 
261
                        .environmentObject(appNavigation)
-
 
262
                        .tag(index)
-
 
263
                        .transition(.slide)
139
                            guard id != nil else { return }
264
                            
-
 
265
                    }
140
                            
266
                }
141
                            print("positionVisible : \(positionVisible)")
267
                //.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
-
 
268
                .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
142
                            scrollProxy.scrollTo(id)
269
 
-
 
270
                .onChange(of: self.selectedTab) { selectedTab in
-
 
271
                    appData.slideUuidActive = self.viewModel.slides[selectedTab].uuid
-
 
272
                    appData.save()
-
 
273
                    
-
 
274
                    completeSlide(position: self.selectedTab)
-
 
275
                }.onAppear {
-
 
276
 
-
 
277
                    var position : Int = 0
-
 
278
                    var i : Int = 0
-
 
279
                    while i < self.viewModel.slides.count {
-
 
280
                        if appData.slideUuidActive == self.viewModel.slides[i].uuid {
-
 
281
                            position = i
-
 
282
                        }
-
 
283
                        i += 1
-
 
284
                    }
143
 
285
                    
-
 
286
                    self.selectedTab =  position
-
 
287
                    completeSlide(position: self.selectedTab)
-
 
288
                }*/
-
 
289
       
144
                        }
290
            }
145
                        .onAppear {
291
            .onAppear {
146
                            var position : Int = 0
Línea 292... Línea 147...
292
 
147
                            var i : Int = 0