Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 1 | 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
//  MyCapsules.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 7/10/22.
6
//
7
 
8
import Foundation
9
 
10
import SwiftUI
11
 
12
 
13
 
14
struct MyCapsulesView: View {
15
 
16
    @EnvironmentObject private var networkMonitor : NetworkMonitor
17
 
18
    @EnvironmentObject private var appNavigation : AppNavigation
19
    @State private var selectedType: CapsulePickerType = .pending
20
    @State private var search : String = ""
21
    @State private var searching : Bool = false
22
 
23
    @State private var showInProgress : Bool = true
24
 
25
    @StateObject private var listingViewModel : MyCapsulesListingViewModel = MyCapsulesListingViewModel()
26
 
27
    @StateObject private var inprogressViewModel : MyCapsulesInProgressViewModel = MyCapsulesInProgressViewModel()
28
 
29
 
30
 
31
    private let firstName : String
32
    private var appData = AppData.sharedInstance
33
 
34
    init ()
35
    {
36
        let arrayFirstName = appData.userFirstname.split(separator: " ")
37
        firstName = String(arrayFirstName[0])
38
    }
39
 
40
 
41
    var body: some View {
42
 
43
        VStack(spacing: 0) {
44
            HStack {
45
 
46
 
47
                Image("logo")
48
                .resizable()
49
                .frame(width: 32, height: 32, alignment: .center)
50
                .aspectRatio(contentMode: .fit)
51
                    .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
52
                .padding(.leading, 16)
53
 
54
 
55
                Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : Config.LANG_TAB_BAR_BUTTON_MY_CAPSULES)
56
                .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
57
                    .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
58
                .padding(.leading, 4)
59
 
60
                Spacer()
61
 
62
            }
63
            .edgesIgnoringSafeArea(.top)
64
            .frame(height: 50)
65
            .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
66
 
67
            Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
68
 
69
            MyCapsulesHeaderView(showInProgress: self.$showInProgress, firstName:  self.firstName)
70
 
71
            if self.showInProgress {
72
 
73
                MyCapsuleInProgressView(
74
                    capsuleUuid: self.inprogressViewModel.capsule.uuid
75
                ).frame(height: 170)
76
                    .transition(.scale)
77
                .environmentObject(appNavigation)
78
 
79
                Divider()
80
 
81
            }
82
 
83
            MyCapsulesPickerView (selectedType: self.$selectedType)
84
            .frame(height: 48)
85
 
86
            Divider()
87
 
88
            MyCapsulesFilterView(search: self.$search, searching: self.$searching)
89
            .frame(height: 64)
90
 
91
            Divider()
92
 
93
            Spacer()
94
 
95
            ScrollView {
96
                LazyVStack {
97
 
98
                    ForEach(0..<self.listingViewModel.capsules.count) { index in
99
 
100
                        if self.selectedType == .pending && self.listingViewModel.capsules[index].viewSlides == 0 {
101
 
102
                            if(self.search.isEmpty) {
103
                                MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
104
 
17 efrain 105
                                    .environmentObject(appNavigation).onTapGesture {
106
                                        goToCapsuleDetail(topicUuid: self.listingViewModel.capsules[index].topicUuid, capsuleUuid: self.listingViewModel.capsules[index].uuid)
107
                                    }
1 efrain 108
                            } else {
109
                                if self.listingViewModel.capsules[index].name.contains(self.search) {
110
 
111
                                    MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
112
 
17 efrain 113
                                    .environmentObject(appNavigation).onTapGesture {
114
                                        goToCapsuleDetail(topicUuid: self.listingViewModel.capsules[index].topicUuid, capsuleUuid: self.listingViewModel.capsules[index].uuid)
115
                                    }
1 efrain 116
                                }
117
                            }
118
                        }
119
 
120
                        if self.selectedType == .inprogress && self.listingViewModel.capsules[index].viewSlides > 0
121
                            && self.listingViewModel.capsules[index].completed == 0 {
122
 
123
 
124
                            if(self.search.isEmpty) {
125
                                MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
126
 
17 efrain 127
                                .environmentObject(appNavigation).onTapGesture {
128
                                    goToCapsuleDetail(topicUuid: self.listingViewModel.capsules[index].topicUuid, capsuleUuid: self.listingViewModel.capsules[index].uuid)
129
                                }
1 efrain 130
                            } else {
131
                                if self.listingViewModel.capsules[index].name.contains(self.search) {
132
 
133
                                    MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
134
 
17 efrain 135
                                    .environmentObject(appNavigation).onTapGesture {
136
                                        goToCapsuleDetail(topicUuid: self.listingViewModel.capsules[index].topicUuid, capsuleUuid: self.listingViewModel.capsules[index].uuid)
137
                                    }
1 efrain 138
                                }
139
                            }
140
                        }
141
 
142
                        if self.selectedType == .completed && self.listingViewModel.capsules[index].viewSlides > 0
143
                            && self.listingViewModel.capsules[index].completed == 1 {
144
 
145
                            if(self.search.isEmpty) {
146
                                MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
147
 
17 efrain 148
                                .environmentObject(appNavigation).onTapGesture {
149
                                    goToCapsuleDetail(topicUuid: self.listingViewModel.capsules[index].topicUuid, capsuleUuid: self.listingViewModel.capsules[index].uuid)
150
                                }
1 efrain 151
                            } else {
152
                                if self.listingViewModel.capsules[index].name.contains(self.search) {
153
 
154
                                    MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
155
 
17 efrain 156
                                    .environmentObject(appNavigation).onTapGesture {
157
                                        goToCapsuleDetail(topicUuid: self.listingViewModel.capsules[index].topicUuid, capsuleUuid: self.listingViewModel.capsules[index].uuid)
158
                                    }
1 efrain 159
                                }
160
                            }
161
 
162
 
163
                        }
164
 
165
 
166
                        //.id(index)
167
 
168
                    }
169
 
170
 
171
                }
172
 
17 efrain 173
 
174
 
1 efrain 175
            }.onAppear {
176
 
177
 
178
                self.listingViewModel.fetch()
179
                self.inprogressViewModel.fetch()
180
 
181
            }.background(Color("color_capsule_list_item_background"))
182
 
183
 
184
 
185
        }
186
 
187
    }
188
 
17 efrain 189
    private func goToCapsuleDetail(topicUuid : String, capsuleUuid : String)
190
    {
191
        appData.topicUuidActive = topicUuid
192
        appData.capsuleUuidActive = capsuleUuid
193
        appData.slideUuidActive = ""
194
        appData.save()
195
 
196
//appNavigation.subPageSource = .mycapsules
197
        appNavigation.subpageActive = .commentsandrating
198
    }
199
 
1 efrain 200
 
201
}
202
 
203
 
204
 
205
 
206
 
207
struct MyCapsulesView_Previews: PreviewProvider {
208
    static var previews: some View {
209
        MyCapsulesView()
210
    }
211
}