| 1 |
efrain |
1 |
//
|
|
|
2 |
// GridGalleryView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 3/7/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import Foundation
|
|
|
9 |
|
|
|
10 |
import SwiftUI
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
struct GridGalleryView: View {
|
|
|
14 |
|
| 8 |
efrain |
15 |
@EnvironmentObject private var networkMonitor : NetworkMonitor
|
| 1 |
efrain |
16 |
@EnvironmentObject private var appNavigation : AppNavigation
|
| 32 |
efrain |
17 |
@ObservedObject private var viewModel : GalleryGridViewModel = GalleryGridViewModel()
|
| 8 |
efrain |
18 |
|
| 1 |
efrain |
19 |
|
|
|
20 |
|
| 17 |
efrain |
21 |
private var appData = AppData.sharedInstance
|
| 1 |
efrain |
22 |
private var capsuleTitle : String = ""
|
| 32 |
efrain |
23 |
|
| 1 |
efrain |
24 |
|
|
|
25 |
|
| 17 |
efrain |
26 |
|
| 1 |
efrain |
27 |
|
|
|
28 |
init()
|
|
|
29 |
{
|
|
|
30 |
self.viewModel.fetch(capsuleUuid: appData.capsuleUuidActive, userUuid: appData.userUuid)
|
|
|
31 |
|
|
|
32 |
let capsuleDao = CapsuleDao.sharedInstance
|
|
|
33 |
let capsule = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)
|
|
|
34 |
|
|
|
35 |
if capsule.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
|
|
|
36 |
capsuleTitle = String(Array(capsule.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."
|
|
|
37 |
} else {
|
|
|
38 |
capsuleTitle = capsule.name
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
|
| 33 |
efrain |
43 |
@ViewBuilder
|
| 1 |
efrain |
44 |
var body: some View {
|
|
|
45 |
GeometryReader { geometry in
|
|
|
46 |
ZStack {
|
| 20 |
efrain |
47 |
|
| 32 |
efrain |
48 |
if self.viewModel.hasPrevious() {
|
| 1 |
efrain |
49 |
Button(action: {
|
| 33 |
efrain |
50 |
print("Button previouse")
|
| 32 |
efrain |
51 |
self.viewModel.previous()
|
| 33 |
efrain |
52 |
print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
|
| 32 |
efrain |
53 |
self.completeSlide(position: self.viewModel.slideActiveIndex)
|
|
|
54 |
|
|
|
55 |
appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
|
| 17 |
efrain |
56 |
appData.save()
|
|
|
57 |
}, label: {
|
|
|
58 |
Image(systemName: "arrow.left")
|
|
|
59 |
})
|
| 1 |
efrain |
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)
|
|
|
66 |
}
|
|
|
67 |
|
| 32 |
efrain |
68 |
if self.viewModel.hasNext() {
|
| 1 |
efrain |
69 |
Button(action: {
|
| 33 |
efrain |
70 |
print("Button next")
|
| 32 |
efrain |
71 |
self.viewModel.next()
|
| 33 |
efrain |
72 |
print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
|
| 32 |
efrain |
73 |
self.completeSlide(position: self.viewModel.slideActiveIndex)
|
|
|
74 |
|
|
|
75 |
appData.slideUuidActive = self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
|
| 17 |
efrain |
76 |
appData.save()
|
|
|
77 |
|
| 32 |
efrain |
78 |
|
| 17 |
efrain |
79 |
}, label: {
|
|
|
80 |
Image(systemName: "arrow.right")
|
|
|
81 |
})
|
| 1 |
efrain |
82 |
.frame(width: 40.0, height: 40.0, alignment: .center)
|
|
|
83 |
.background(Color("color_button_gallery_background"))
|
|
|
84 |
.foregroundColor(Color("color_button_gallery_foreground"))
|
|
|
85 |
.offset(x: ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)
|
| 20 |
efrain |
86 |
}
|
| 1 |
efrain |
87 |
|
|
|
88 |
VStack(spacing: 0) {
|
|
|
89 |
HStack {
|
|
|
90 |
Button(action: {
|
| 22 |
efrain |
91 |
|
| 1 |
efrain |
92 |
|
| 11 |
efrain |
93 |
appNavigation.subpageActive = .slides
|
| 1 |
efrain |
94 |
|
|
|
95 |
|
|
|
96 |
}, label: {
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
Image(systemName: "chevron.backward")
|
|
|
100 |
.frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
101 |
.aspectRatio(contentMode: .fit)
|
| 8 |
efrain |
102 |
.foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
|
| 1 |
efrain |
103 |
})
|
|
|
104 |
.padding(.leading, 16)
|
|
|
105 |
|
| 8 |
efrain |
106 |
Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : capsuleTitle)
|
| 1 |
efrain |
107 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
|
| 8 |
efrain |
108 |
.foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
|
| 1 |
efrain |
109 |
.padding(.leading, 4)
|
|
|
110 |
|
|
|
111 |
Spacer()
|
|
|
112 |
}
|
|
|
113 |
.edgesIgnoringSafeArea(.top)
|
|
|
114 |
.frame(height: 50)
|
| 8 |
efrain |
115 |
.background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
|
| 1 |
efrain |
119 |
|
| 34 |
efrain |
120 |
/*
|
| 32 |
efrain |
121 |
CardGalleryView(
|
| 33 |
efrain |
122 |
slideUuid: self.viewModel.slides[self.viewModel.slideActiveIndex].uuid
|
| 32 |
efrain |
123 |
)
|
|
|
124 |
.environmentObject(appNavigation)
|
| 33 |
efrain |
125 |
Text("slideActive : \(viewModel.slideActiveIndex)")
|
| 34 |
efrain |
126 |
*/
|
|
|
127 |
|
|
|
128 |
GeometryReader { geometry in
|
|
|
129 |
let checkMarkX = (geometry.size.width - 50) / 2
|
|
|
130 |
let checkMarkY = -1 * ((geometry.size.height - 50) / 2)
|
|
|
131 |
|
|
|
132 |
let buttonX = (geometry.size.width - 180) / 2
|
|
|
133 |
// let buttonY = (geometry.size.height - 80) / 2
|
|
|
134 |
|
|
|
135 |
let buttonY = (geometry.size.height - 100) / 2
|
|
|
136 |
|
|
|
137 |
ZStack {
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
if self.viewModel.slides[self.viewModel.slideActiveIndex].completed == 1 {
|
|
|
141 |
Image(uiImage: UIImage(named: "ic_slide_completado_checkmark") ?? UIImage()).offset(x: checkMarkX, y: checkMarkY).zIndex(10000)
|
|
|
142 |
}
|
|
|
143 |
/*
|
|
|
144 |
if self.buttonShow {
|
|
|
145 |
|
|
|
146 |
Button(action: {
|
|
|
147 |
btnPlay()
|
|
|
148 |
}, label: {
|
|
|
149 |
Text(self.buttonTitle)
|
|
|
150 |
.font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_BUTTONS))
|
|
|
151 |
.foregroundColor(Color("color_button_gallery_foreground"))
|
|
|
152 |
|
|
|
153 |
})
|
|
|
154 |
|
|
|
155 |
.padding(.vertical, 15)
|
|
|
156 |
.padding(.horizontal, 10)
|
|
|
157 |
.background(Color("color_button_gallery_background"))
|
|
|
158 |
.cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
|
|
|
159 |
.offset(x: buttonX, y: buttonY)
|
|
|
160 |
.zIndex(10000)
|
|
|
161 |
}
|
|
|
162 |
|
|
|
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 |
|
|
|
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)
|
|
|
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 |
*/
|
|
|
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)
|
|
|
197 |
} else {
|
|
|
198 |
CustomAsyncImage(
|
|
|
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)!,
|
|
|
200 |
placeholder: {
|
|
|
201 |
Spacer()
|
|
|
202 |
Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)
|
|
|
203 |
Spacer()
|
|
|
204 |
},
|
|
|
205 |
image: {
|
|
|
206 |
Image(uiImage: $0).resizable()
|
|
|
207 |
}
|
|
|
208 |
)
|
|
|
209 |
}
|
|
|
210 |
}.padding(.horizontal, 5)
|
|
|
211 |
|
|
|
212 |
Spacer()
|
|
|
213 |
}
|
|
|
214 |
// .zIndex(500)
|
|
|
215 |
|
|
|
216 |
}
|
|
|
217 |
}
|
| 32 |
efrain |
218 |
.transition(.slide)
|
|
|
219 |
.gesture(
|
|
|
220 |
DragGesture(minimumDistance: 60).onEnded {
|
|
|
221 |
if $0.startLocation.x > $0.location.x {
|
|
|
222 |
print("left")
|
|
|
223 |
if self.viewModel.hasPrevious() {
|
| 33 |
efrain |
224 |
print("hasPrevious")
|
| 32 |
efrain |
225 |
self.viewModel.previous()
|
| 33 |
efrain |
226 |
print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
|
| 32 |
efrain |
227 |
self.completeSlide(position: self.viewModel.slideActiveIndex)
|
|
|
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() {
|
| 33 |
efrain |
235 |
print("hasNext")
|
| 32 |
efrain |
236 |
self.viewModel.next()
|
| 33 |
efrain |
237 |
print("slideActiveIndex: \(self.viewModel.slideActiveIndex)")
|
| 32 |
efrain |
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 |
|
|
|
249 |
|
|
|
250 |
})
|
| 34 |
efrain |
251 |
|
| 1 |
efrain |
252 |
|
| 32 |
efrain |
253 |
|
|
|
254 |
|
|
|
255 |
/*
|
| 1 |
efrain |
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)
|
|
|
264 |
|
|
|
265 |
}
|
|
|
266 |
}
|
| 26 |
efrain |
267 |
//.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
|
|
|
268 |
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
|
| 1 |
efrain |
269 |
|
|
|
270 |
.onChange(of: self.selectedTab) { selectedTab in
|
| 17 |
efrain |
271 |
appData.slideUuidActive = self.viewModel.slides[selectedTab].uuid
|
|
|
272 |
appData.save()
|
|
|
273 |
|
| 1 |
efrain |
274 |
completeSlide(position: self.selectedTab)
|
|
|
275 |
}.onAppear {
|
| 17 |
efrain |
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 |
}
|
|
|
285 |
|
|
|
286 |
self.selectedTab = position
|
| 1 |
efrain |
287 |
completeSlide(position: self.selectedTab)
|
| 32 |
efrain |
288 |
}*/
|
| 1 |
efrain |
289 |
|
|
|
290 |
}
|
| 32 |
efrain |
291 |
.onAppear {
|
| 1 |
efrain |
292 |
|
| 32 |
efrain |
293 |
var position : Int = 0
|
|
|
294 |
var i : Int = 0
|
|
|
295 |
while i < self.viewModel.slides.count {
|
|
|
296 |
if appData.slideUuidActive == self.viewModel.slides[i].uuid {
|
|
|
297 |
position = i
|
|
|
298 |
}
|
|
|
299 |
i += 1
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
self.viewModel.slideActiveIndex = position
|
| 1 |
efrain |
303 |
}
|
| 32 |
efrain |
304 |
|
|
|
305 |
}
|
| 1 |
efrain |
306 |
}
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
private func completeSlide(position: Int)
|
|
|
310 |
{
|
|
|
311 |
|
|
|
312 |
if self.viewModel.slides[position].type == Constants.SLIDE_TYPE_IMAGE {
|
|
|
313 |
|
|
|
314 |
let dataService = DataService()
|
|
|
315 |
dataService.completeSlide(slide: self.viewModel.slides[position])
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
struct GridGalleryView_Previews: PreviewProvider {
|
|
|
330 |
static var previews: some View {
|
|
|
331 |
//GridGalleryView(capsuleUuid: "C123", position: 2)
|
|
|
332 |
|
|
|
333 |
GridGalleryView()
|
|
|
334 |
}
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|