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
//  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
 
8 efrain 16
    @EnvironmentObject private var networkMonitor : NetworkMonitor
17
 
1 efrain 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
 
8 efrain 30
 
1 efrain 31
    private let firstName : String
9 efrain 32
    private let appDao = AppDao.sharedInstance
1 efrain 33
 
34
    init ()
35
    {
11 efrain 36
        let appData = appDao.selectOne()
37
        let arrayFirstName = appData.userFirstname.split(separator: " ")
1 efrain 38
 
39
 
40
 
41
        firstName = String(arrayFirstName[0])
42
 
43
 
44
 
45
    }
46
 
47
 
48
    var body: some View {
49
 
50
        VStack(spacing: 0) {
51
            HStack {
8 efrain 52
 
53
 
1 efrain 54
                Image("logo")
55
                .resizable()
56
                .frame(width: 32, height: 32, alignment: .center)
57
                .aspectRatio(contentMode: .fit)
8 efrain 58
                    .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 59
                .padding(.leading, 16)
60
 
61
 
8 efrain 62
                Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : Config.LANG_TAB_BAR_BUTTON_MY_CAPSULES)
1 efrain 63
                .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
8 efrain 64
                    .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
1 efrain 65
                .padding(.leading, 4)
66
 
67
                Spacer()
68
 
69
            }
70
            .edgesIgnoringSafeArea(.top)
71
            .frame(height: 50)
8 efrain 72
            .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
73
 
74
            Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
1 efrain 75
 
76
            MyCapsulesHeaderView(showInProgress: self.$showInProgress, firstName:  self.firstName)
77
 
78
            if self.showInProgress {
79
 
80
                MyCapsuleInProgressView(
81
                    capsuleUuid: self.inprogressViewModel.capsule.uuid
82
                ).frame(height: 170)
83
                    .transition(.scale)
84
                .environmentObject(appNavigation)
85
 
86
                Divider()
87
 
88
            }
89
 
90
            MyCapsulesPickerView (selectedType: self.$selectedType)
91
            .frame(height: 48)
92
 
93
            Divider()
94
 
95
            MyCapsulesFilterView(search: self.$search, searching: self.$searching)
96
            .frame(height: 64)
97
 
98
            Divider()
99
 
100
            Spacer()
101
 
102
            ScrollView {
103
                LazyVStack {
104
 
105
                    ForEach(0..<self.listingViewModel.capsules.count) { index in
106
 
107
                        if self.selectedType == .pending && self.listingViewModel.capsules[index].viewSlides == 0 {
108
 
109
                            if(self.search.isEmpty) {
110
                                MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
111
 
112
                                .environmentObject(appNavigation)
113
                            } else {
114
                                if self.listingViewModel.capsules[index].name.contains(self.search) {
115
 
116
                                    MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
117
 
118
                                    .environmentObject(appNavigation)
119
                                }
120
                            }
121
                        }
122
 
123
                        if self.selectedType == .inprogress && self.listingViewModel.capsules[index].viewSlides > 0
124
                            && self.listingViewModel.capsules[index].completed == 0 {
125
 
126
 
127
                            if(self.search.isEmpty) {
128
                                MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
129
 
130
                                .environmentObject(appNavigation)
131
                            } else {
132
                                if self.listingViewModel.capsules[index].name.contains(self.search) {
133
 
134
                                    MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
135
 
136
                                    .environmentObject(appNavigation)
137
                                }
138
                            }
139
                        }
140
 
141
                        if self.selectedType == .completed && self.listingViewModel.capsules[index].viewSlides > 0
142
                            && self.listingViewModel.capsules[index].completed == 1 {
143
 
144
                            if(self.search.isEmpty) {
145
                                MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
146
 
147
                                .environmentObject(appNavigation)
148
                            } else {
149
                                if self.listingViewModel.capsules[index].name.contains(self.search) {
150
 
151
                                    MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid)
152
 
153
                                    .environmentObject(appNavigation)
154
                                }
155
                            }
156
 
157
 
158
                        }
159
 
160
 
161
                        //.id(index)
162
 
163
                    }
164
 
165
 
166
                }
167
 
8 efrain 168
            }.onAppear {
169
 
170
 
171
                self.listingViewModel.fetch()
172
                self.inprogressViewModel.fetch()
173
 
1 efrain 174
            }.background(Color("color_capsule_list_item_background"))
175
 
176
 
177
 
178
        }
179
 
180
    }
181
 
182
 
183
}
184
 
185
 
186
 
187
 
188
 
189
struct MyCapsulesView_Previews: PreviewProvider {
190
    static var previews: some View {
191
        MyCapsulesView()
192
    }
193
}