Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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

Rev 8 Rev 11
Línea 6... Línea 6...
6
//
6
//
Línea 7... Línea 7...
7
 
7
 
8
import Foundation
8
import Foundation
9
import SwiftUI
9
import SwiftUI
-
 
10
import PDFKit
-
 
11
import Network
-
 
12
import Alamofire
-
 
13
import SwiftyJSON
10
import PDFKit
14
import TTGSnackbar
Línea 11... Línea 15...
11
import NavigationStack
15
import NavigationStack
Línea 12... Línea 16...
12
 
16
 
Línea 13... Línea 17...
13
 
17
 
14
struct PdfViewerView: View {
-
 
-
 
18
struct PdfViewerView: View {
Línea 15... Línea 19...
15
    
19
    
16
    @State private var backToGallery : Bool = false
20
    @State private var backToGallery : Bool = false
Línea 17... Línea -...
17
    
-
 
-
 
21
    
-
 
22
    @State private var isCompleted : Bool = false
Línea 18... Línea 23...
18
    @State private var isCompleted : Bool = false
23
    @State private var url : URL? = nil
19
    
24
    
Línea 35... Línea 40...
35
        } else {
40
        } else {
36
            slideTitle = self.slideModel.name
41
            slideTitle = self.slideModel.name
37
        }
42
        }
Línea 38... Línea -...
38
        
-
 
-
 
43
        
Línea -... Línea 44...
-
 
44
        
-
 
45
 
39
        
46
        
Línea 40... Línea 47...
40
        print("Viewer PDF: \(slideModel.file) ")
47
        //print("Viewer PDF: \(slideModel.file) ")
Línea 57... Línea 64...
57
            ).frame( height: 0)
64
            ).frame( height: 0)
Línea 58... Línea 65...
58
            
65
            
59
            HStack {
66
            HStack {
60
                Button(action: {
67
                Button(action: {
61
                    let dataService = DataService()
-
 
62
                    if self.isCompleted {
-
 
63
                    
-
 
64
                       
68
                    let dataService = DataService()
65
                        dataService.completeSlide(slide: slideModel)
-
 
66
                    } else {
-
 
67
                        dataService.incompleteSlide(slide: slideModel)
-
 
68
                    }
-
 
69
                    
-
 
70
 
-
 
71
 
69
                    dataService.completeSlide(slide: slideModel)
Línea 72... Línea 70...
72
                    self.backToGallery.toggle()
70
                    self.backToGallery.toggle()
Línea 93... Línea 91...
93
            .background(Color("color_app_bar_background"))
91
            .background(Color("color_app_bar_background"))
94
            .edgesIgnoringSafeArea(.top)
92
            .edgesIgnoringSafeArea(.top)
95
            .frame(height: 50)
93
            .frame(height: 50)
96
            Divider()
94
            Divider()
Línea 97... Línea -...
97
 
-
 
98
            GeometryReader { geometry in
-
 
99
            
-
 
100
            PDFKitRepresentedView(url!)
95
 
101
                .frame(
96
            if self.url != nil {
102
                    width: geometry.size.width,
-
 
103
                    height: geometry.size.height,
-
 
104
                    alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
-
 
Línea -... Línea 97...
-
 
97
                GeometryReader { geometry in
-
 
98
                
-
 
99
                    PDFKitRepresentedView(url!)
-
 
100
                    .frame(
-
 
101
                        width: geometry.size.width,
-
 
102
                        height: geometry.size.height,
-
 
103
                        alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
-
 
104
                    .border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: /*@START_MENU_TOKEN@*/1/*@END_MENU_TOKEN@*/)
105
                .border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: /*@START_MENU_TOKEN@*/1/*@END_MENU_TOKEN@*/)
105
                    
-
 
106
                }
-
 
107
            }
-
 
108
                
Línea -... Línea 109...
-
 
109
            
-
 
110
            Spacer()
-
 
111
 
-
 
112
           
-
 
113
        }.onAppear {
-
 
114
            let appDao = AppDao.sharedInstance
-
 
115
            let appData = appDao.selectOne()
-
 
116
            let headerSecurity = HeaderSecurity()
-
 
117
            
-
 
118
            
-
 
119
            let headerAccept = HTTPHeader(name : Constants.HTTP_HEADER_ACCEPT, value: Constants.HTTP_HEADER_ACCEPT_VALUE)
-
 
120
            
-
 
121
            let headerRand = HTTPHeader(name : Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand))
-
 
122
            
-
 
123
            let headerToken = HTTPHeader(name : Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid)
-
 
124
            
-
 
125
            let headerCreated = HTTPHeader(name : Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created))
-
 
126
            
-
 
127
            let headerSecret = HTTPHeader(name : Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret)
-
 
128
            
-
 
129
            
-
 
130
            var headers = HTTPHeaders()
-
 
131
            headers.add(headerAccept)
-
 
132
            headers.add(headerRand)
-
 
133
            headers.add(headerToken)
-
 
134
            headers.add(headerCreated)
-
 
135
            headers.add(headerSecret)
-
 
136
            
-
 
137
            
-
 
138
            /*
-
 
139
                Constants.HTTP_HEADER_ACCEPT: Constants.HTTP_HEADER_ACCEPT_VALUE,
-
 
140
                Constants.HTTP_HEADER_SECURITY_RAND: String(headerSecurity.rand),
-
 
141
                Constants.HTTP_HEADER_SECURITY_TOKEN: appData.deviceUuid,
-
 
142
                Constants.HTTP_HEADER_SECURITY_CREATED: String(headerSecurity.created) ,
-
 
143
                Constants.HTTP_HEADER_SECURITY_SECRET: headerSecurity.secret,
-
 
144
            ]*/
-
 
145
            /*
-
 
146
            let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
-
 
147
            */
-
 
148
            /*
-
 
149
            let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory, in: .userDomainMask)
-
 
150
                    
-
 
151
            
-
 
152
            let destination: DownloadRequest.DownloadFileDestination
-
 
153
            
-
 
154
    
-
 
155
            print("Download")
-
 
156
            AF.download(
-
 
157
                url!,
-
 
158
                method: .get,
-
 
159
                encoding: JSONEncoding.default,
-
 
160
                headers: headers, to: destination).downloadProgress(closure: { (progress) in
-
 
161
            //progress closure
-
 
162
        }).response(completionHandler: { (DefaultDownloadResponse) in
-
 
163
            //here you able to access the DefaultDownloadResponse
-
 
164
            //result closure
-
 
165
        })*/
-
 
166
            
-
 
167
            /*
-
 
168
                Constants.HTTP_HEADER_ACCEPT: Constants.HTTP_HEADER_ACCEPT_VALUE,
-
 
169
                Constants.HTTP_HEADER_SECURITY_RAND: String(headerSecurity.rand),
-
 
170
                Constants.HTTP_HEADER_SECURITY_TOKEN: appData.deviceUuid,
-
 
171
                Constants.HTTP_HEADER_SECURITY_CREATED: String(headerSecurity.created) ,
-
 
172
                Constants.HTTP_HEADER_SECURITY_SECRET: headerSecurity.secret,
-
 
173
            ]*/
-
 
174
            
-
 
175
            //AF.download()
-
 
176
                /*
-
 
177
                .downloadProgress { progress in
-
 
178
                    print("Download Progress: \(progress.fractionCompleted)")
-
 
179
                }
-
 
180
                .responseData { response in
-
 
181
                    do {
-
 
182
                        try response.result.value?.write(to: File.getPath(filename: "_cr"))
-
 
183
                    } catch {
-
 
184
                        print("oops !")
-
 
185
                    }
-
 
186
                }*/
-
 
187
            
-
 
188
            
-
 
189
            
-
 
190
            let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
-
 
191
             
-
 
192
            print("download")
-
 
193
            AF.download(
-
 
194
                URL(string: slideModel.file)!,
-
 
195
                method: .get,
-
 
196
                encoding: JSONEncoding.default,
-
 
197
                headers: headers).downloadProgress(closure: { (progress) in
-
 
198
                        print(progress.completedUnitCount)
-
 
199
                    }).responseData { (response) in
-
 
200
                        
-
 
201
                        self.url = response.fileURL
-
 
202
                        
-
 
203
                        //print("fileURL = \(fileURL)")
-
 
204
                        
-
 
205
                        /*
-
 
206
                        let destiUrl = responce.destiUrl? ""
-
 
207
                        print(destiUrl!)
-
 
208
                        */
-
 
209
                        /*
-
 
210
                        let newUrl = destiUrl?.deletingPathExtension().appendingPathExtension("zip")
-
 
211
                        do {
-
 
212
                            try FileManager.default.copyItem(at: destiUrl!, to: newUrl!)
-
 
213
             
-
 
214
                            let unzipDirectory = try Zip.quickUnzipFile(newUrl!)
-
 
215
                            print(unzipDirectory.absoluteString)
-
 
216
                       }
106
                
217
                        catch let error as NSError{
107
            }
218
                            print(error)
108
 
219
                        }*/