Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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