Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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