| 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 |
class GridGalleryTabController: ObservableObject {
|
|
|
14 |
@Published var activeTab : Int = 0
|
|
|
15 |
|
|
|
16 |
func open( tab: Int) {
|
|
|
17 |
activeTab = tab
|
|
|
18 |
}
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
struct GridGalleryView: View {
|
|
|
22 |
|
|
|
23 |
@EnvironmentObject private var appNavigation : AppNavigation
|
|
|
24 |
@State private var selectedTab : Int = 0
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
private let appData = AppData.sharedInstance
|
|
|
28 |
|
|
|
29 |
private var capsuleTitle : String = ""
|
|
|
30 |
|
|
|
31 |
private var viewModel : GalleryGridViewModel = GalleryGridViewModel()
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
//init(capsuleUuid : String, position : Int)
|
|
|
38 |
|
|
|
39 |
init()
|
|
|
40 |
{
|
|
|
41 |
self.viewModel.fetch(capsuleUuid: appData.capsuleUuidActive, userUuid: appData.userUuid)
|
|
|
42 |
|
|
|
43 |
let capsuleDao = CapsuleDao.sharedInstance
|
|
|
44 |
let capsule = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)
|
|
|
45 |
|
|
|
46 |
if capsule.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
|
|
|
47 |
capsuleTitle = String(Array(capsule.name)[0...Constants.APP_BAR_TITLE_MAX_LENGTH]) + "..."
|
|
|
48 |
} else {
|
|
|
49 |
capsuleTitle = capsule.name
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
var body: some View {
|
|
|
56 |
GeometryReader { geometry in
|
|
|
57 |
ZStack {
|
|
|
58 |
if self.selectedTab > 0 {
|
|
|
59 |
Button(action: {
|
|
|
60 |
self.selectedTab = self.selectedTab - 1
|
|
|
61 |
}, label: {
|
|
|
62 |
Image(systemName: "arrow.left")
|
|
|
63 |
})
|
|
|
64 |
|
|
|
65 |
.frame(width: 40.0, height: 40.0, alignment: .center)
|
|
|
66 |
.cornerRadius(/*@START_MENU_TOKEN@*/3.0/*@END_MENU_TOKEN@*/)
|
|
|
67 |
.background(Color("color_button_gallery_background"))
|
|
|
68 |
.foregroundColor(Color("color_button_gallery_foreground"))
|
|
|
69 |
.offset(x: -1 * ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
if self.selectedTab < (self.viewModel.slides.count - 1) {
|
|
|
73 |
Button(action: {
|
|
|
74 |
self.selectedTab = self.selectedTab + 1
|
|
|
75 |
}, label: {
|
|
|
76 |
Image(systemName: "arrow.right")
|
|
|
77 |
})
|
|
|
78 |
.frame(width: 40.0, height: 40.0, alignment: .center)
|
|
|
79 |
.background(Color("color_button_gallery_background"))
|
|
|
80 |
.foregroundColor(Color("color_button_gallery_foreground"))
|
|
|
81 |
.offset(x: ((geometry.size.width / 2) - 30), y : 25).zIndex(10000)
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
VStack(spacing: 0) {
|
|
|
85 |
HStack {
|
|
|
86 |
Button(action: {
|
|
|
87 |
appData.slideUuidActive = ""
|
|
|
88 |
appData.save()
|
|
|
89 |
|
|
|
90 |
appNavigation.subpageActive = .capsules
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
}, label: {
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
Image(systemName: "chevron.backward")
|
|
|
97 |
.frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
98 |
.aspectRatio(contentMode: .fit)
|
|
|
99 |
.foregroundColor(Color("color_app_bar_foreground"))
|
|
|
100 |
})
|
|
|
101 |
.padding(.leading, 16)
|
|
|
102 |
|
|
|
103 |
Text(capsuleTitle)
|
|
|
104 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
|
|
|
105 |
.foregroundColor(Color("color_app_bar_foreground"))
|
|
|
106 |
.padding(.leading, 4)
|
|
|
107 |
|
|
|
108 |
Spacer()
|
|
|
109 |
}
|
|
|
110 |
.background(Color("color_app_bar_background"))
|
|
|
111 |
.edgesIgnoringSafeArea(.top)
|
|
|
112 |
.frame(height: 50)
|
|
|
113 |
|
|
|
114 |
Divider()
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
TabView(selection: self.$selectedTab) {
|
|
|
118 |
ForEach(0..<self.viewModel.slides.count) { index in
|
|
|
119 |
CardGalleryView(
|
|
|
120 |
slideUuid: self.viewModel.slides[index].uuid
|
|
|
121 |
)
|
|
|
122 |
.environmentObject(appNavigation)
|
|
|
123 |
.tag(index)
|
|
|
124 |
.transition(.slide)
|
|
|
125 |
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
//.tabViewStyle(PageTabViewStyle())
|
|
|
129 |
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
|
|
|
130 |
|
|
|
131 |
.onChange(of: self.selectedTab) { selectedTab in
|
|
|
132 |
completeSlide(position: self.selectedTab)
|
|
|
133 |
}.onAppear {
|
|
|
134 |
self.selectedTab = appData.slidePositionInitial
|
|
|
135 |
completeSlide(position: self.selectedTab)
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
private func completeSlide(position: Int)
|
|
|
145 |
{
|
|
|
146 |
|
|
|
147 |
if self.viewModel.slides[position].type == Constants.SLIDE_TYPE_IMAGE {
|
|
|
148 |
|
|
|
149 |
let dataService = DataService()
|
|
|
150 |
dataService.completeSlide(slide: self.viewModel.slides[position])
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
struct GridGalleryView_Previews: PreviewProvider {
|
|
|
165 |
static var previews: some View {
|
|
|
166 |
//GridGalleryView(capsuleUuid: "C123", position: 2)
|
|
|
167 |
|
|
|
168 |
GridGalleryView()
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|