Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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