Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 1 | Rev 9 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 8
Línea 4... Línea 4...
4
//
4
//
5
//  Created by Efrain Yanez Recanatini on 5/4/22.
5
//  Created by Efrain Yanez Recanatini on 5/4/22.
6
//
6
//
Línea 7... Línea 7...
7
 
7
 
8
import Foundation
-
 
9
 
-
 
10
import Foundation
8
import Foundation
11
import SwiftUI
-
 
-
 
9
import SwiftUI
-
 
10
import Alamofire
Línea 12... Línea 11...
12
 
11
import TTGSnackbar
-
 
12
 
13
 
13
struct ProfileView: View {
-
 
14
    @EnvironmentObject private var appNavigation : AppNavigation
-
 
15
    @EnvironmentObject private var networkMonitor : NetworkMonitor
14
struct ProfileView: View {
16
    
-
 
17
    @State private var showGlobalAlert : Bool = false
Línea 15... Línea 18...
15
    @Environment(\.presentationMode)
18
    @State private var titleGlobalAlert : String = ""
Línea 30... Línea 33...
30
                HStack {
33
                HStack {
31
                    Image("logo")
34
                    Image("logo")
32
                    .resizable()
35
                    .resizable()
33
                    .frame(width: 32, height: 32, alignment: .center)
36
                    .frame(width: 32, height: 32, alignment: .center)
34
                    .aspectRatio(contentMode: .fit)
37
                    .aspectRatio(contentMode: .fit)
35
                    .foregroundColor(Color("color_app_bar_foreground"))
38
                        .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
36
                    .padding(.leading, 16)
39
                    .padding(.leading, 16)
Línea 37... Línea 40...
37
                 
40
                 
38
                    
41
                    
39
                    Text(Config.LANG_TAB_BAR_BUTTON_PROFILE)
42
                    Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT :   Config.LANG_TAB_BAR_BUTTON_PROFILE)
40
                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
43
                    .font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
Línea 41... Línea 44...
41
                    .foregroundColor(Color("color_app_bar_foreground"))
44
                        .foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
42
                    .padding(.leading, 4)
45
                    .padding(.leading, 4)
Línea -... Línea 46...
-
 
46
                    
-
 
47
                    Spacer()
-
 
48
  
-
 
49
                    
-
 
50
                    Button(action: {
-
 
51
                        let snackbar = TTGSnackbar(message: Config.LANG_SIGNOUT_MESSAGE, duration: .long)
-
 
52
 
-
 
53
                        // Action 1
-
 
54
                        snackbar.actionText = Config.LANG_COMMON_YES
-
 
55
                        snackbar.actionTextColor = UIColor( Color("color_snackbar_button_yes"))
-
 
56
                        snackbar.actionBlock = { (snackbar) in signout() }
-
 
57
 
-
 
58
               
-
 
59
                        snackbar.secondActionText = Config.LANG_COMMON_NO
-
 
60
                        snackbar.secondActionTextColor = UIColor(Color("color_snackbar_button_no"))
-
 
61
                        snackbar.secondActionBlock = { (snackbar) in }
-
 
62
                           
-
 
63
                        snackbar.show()
-
 
64
                       
-
 
65
                    }, label: {
-
 
66
                        Image(uiImage: UIImage(named: "ui_exit_app") ?? UIImage())
-
 
67
                        .resizable()
-
 
68
                        .frame(width: 24, height: 24, alignment: .center)
43
                    
69
                        .aspectRatio(contentMode: .fit)
44
                    Spacer()
-
 
45
 
70
                        .foregroundColor(Color("color_network_disconnected_foreground"))
46
                    
71
                        .padding(.trailing, 16)
47
                }
72
                    })
-
 
73
                }
-
 
74
                .edgesIgnoringSafeArea(.top)
-
 
75
                .frame(height: 50)
Línea 48... Línea 76...
48
                .background(Color("color_app_bar_background"))
76
                .background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
Línea 49... Línea 77...
49
                .edgesIgnoringSafeArea(.top)
77
                
Línea 89... Línea 117...
89
                    Text("\(appData.firstName) \(appData.lastName)" )
117
                    Text("\(appData.firstName) \(appData.lastName)" )
90
                        .bold()
118
                        .bold()
91
                        .font(.title)
119
                        .font(.title)
92
                    Text("\(appData.email)")
120
                    Text("\(appData.email)")
93
                        .font(.body)
121
                        .font(.body)
94
                        .foregroundColor(Color("color_texview"))
122
                        .foregroundColor(Color("color_textview_foreground"))
95
                }.padding()
123
                }.padding()
Línea 96... Línea 124...
96
 
124
 
Línea 97... Línea 125...
97
 
125
 
98
            }.background(Color("color_card_view_background"))
126
            }.background(Color("color_card_view_background"))
99
            
-
 
100
            ScrollView {
-
 
101
                ForEach(0..<self.userExtendedPointViewModel.points.count) { i in
127
            
102
                    
128
            ScrollView {
103
 
-
 
104
                    UserExtendedPointView(userExtendedPoint: self.userExtendedPointViewModel.points[i])
129
                ForEach(0..<self.userExtendedPointViewModel.points.count) { i in
105
                        .listRowInsets(.init()).frame(width: geometry.size.width, height: 70, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
130
                    UserExtendedPointView(userExtendedPoint: self.userExtendedPointViewModel.points[i])
106
                        
-
 
107
                }
-
 
108
            }
-
 
109
            
131
                        .listRowInsets(.init()).frame(width: geometry.size.width, height: 70, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
110
            //.listStyle(InsetListStyle())
-
 
111
            
-
 
112
            .background(Color("color_card_view_background"))
-
 
113
            
-
 
114
            
132
                }
115
            //Spacer()
133
            }
-
 
134
            .background(Color("color_card_view_background"))
-
 
135
        }.onAppear {
-
 
136
            userExtendedPointViewModel.loadAll()
-
 
137
        }.alert(isPresented: $showGlobalAlert) {
-
 
138
            Alert(
-
 
139
                title: Text(self.titleGlobalAlert),
116
           
140
                message: Text(self.messageGlobalAlert),
117
        }.onAppear {
-
 
118
            userExtendedPointViewModel.loadAll()
-
 
119
        }
-
 
120
        .navigationTitle("Perfil")
-
 
121
        .navigationBarBackButtonHidden(true)
-
 
122
        .navigationBarTitleDisplayMode(.inline)
-
 
123
        .navigationBarItems(
-
 
124
 
-
 
125
            
-
 
126
            trailing:
-
 
127
            Button(action: {
-
 
128
                print("Dismissing sheet view...")
-
 
129
            }, label: {
-
 
130
                HStack {
-
 
131
                    Image(systemName: "arrow.clockwise")
-
 
132
                    .aspectRatio(contentMode: .fit)
-
 
133
                    //.foregroundColor(Color("color_app_bar_foreground"))
-
 
134
                    //.background(Color("color_app_bar_background"))
-
 
135
                }
-
 
136
            })
-
 
137
        )
141
                dismissButton: .default(Text(Config.LANG_COMMON_OK))
138
 
142
            )
Línea -... Línea 143...
-
 
143
        }
-
 
144
        }
-
 
145
    }
-
 
146
    
-
 
147
    private func signout() -> Void {
-
 
148
        
-
 
149
        if networkMonitor.status == .disconnected {
-
 
150
        
-
 
151
            self.titleGlobalAlert = Config.LANG_ERROR_NETWORK_TITLE
-
 
152
            self.messageGlobalAlert = Config.LANG_ERROR_NETWORK_MESSAGE_LONG
-
 
153
            self.showGlobalAlert  = true
-
 
154
        } else {
-
 
155
            let headerSecurity = HeaderSecurity()
-
 
156
            let headers: HTTPHeaders = [
-
 
157
                .init(name: Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid),
-
 
158
                .init(name: Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret),
-
 
159
                .init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),
-
 
160
                .init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),
-
 
161
                .accept(Constants.HTTP_HEADER_ACCEPT)
-
 
162
            ]
-
 
163
            
-
 
164
            AF.request(Config.URL_SIGNOUT, method: .post, headers: headers).responseJSON{(response) in
-
 
165
                switch response.result {
-
 
166
                    case .success:
-
 
167
                        let now = Date()
-
 
168
                        let dateFormatter = DateFormatter()
-
 
169
                        dateFormatter.dateFormat = Constants.FORMAT_DATETIME_SERVICE
-
 
170
                        let dateOn = dateFormatter.string(from: now)
-
 
171
                            
-
 
172
                            
-
 
173
                        var userLog = UserLogModel()
-
 
174
                        userLog.activity = Constants.USER_LOG_ACTIVITY_SIGNOUT
-
 
175
                        userLog.userUuid = appData.userUuid
-
 
176
                        userLog.addedOn = dateOn
-
 
177
                       
-
 
178
                        let userLogDao = UserLogDao.sharedInstance
-
 
179
                        userLogDao.insert(record: userLog)
-
 
180
                            
-
 
181
                        var json : [String: Any] = userLog.toJson()
-
 
182
                        json[Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME] = Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG
-
 
183
                                    
-
 
184
                        var sync = SyncModel();
-
 
185
                        sync.type = Constants.SYNC_ADAPTER_TYPE_SYNC
-
 
186
                        if let theJSONData = try?  JSONSerialization.data(withJSONObject: json, options: .prettyPrinted),
-
 
187
                           let data = String(data: theJSONData, encoding: String.Encoding.ascii) {
-
 
188
                                sync.data = data
-
 
189
                            }
-
 
190
                             
-
 
191
                        let syncDao = SyncDao.sharedInstance
-
 
192
                        syncDao.insert(record : sync)
-
 
193
                            
-
 
194
                            
-
 
195
                        appData.email = ""
139
           
196
                        appData.firstName = ""
-
 
197
                        appData.lastName = ""
-
 
198
                        appData.userUuid = "";
140
        }
199
                        appData.save()
-
 
200
                            
-
 
201
                        appNavigation.pageActive = .goodbye
-
 
202
                        break;
-
 
203
                            
141
    }
204
                    case .failure:
-
 
205
                        self.titleGlobalAlert = Config.LANG_ERROR_COMMUNICATION_TITLE
-
 
206
                        self.messageGlobalAlert = Config.LANG_ERROR_COMMUNICATION_MESSAGE
-
 
207
                        self.showGlobalAlert = true
-
 
208
                                
-
 
209
                        break;
142
    
210
                }
Línea 143... Línea 211...
143
    
211
            }
144
 
212
        }