| 1 | efrain | 1 | //
 | 
        
           |  |  | 2 | //  FinishCapsuleView.swift
 | 
        
           |  |  | 3 | //  twogetskills
 | 
        
           |  |  | 4 | //
 | 
        
           |  |  | 5 | //  Created by Efrain Yanez Recanatini on 1/28/22.
 | 
        
           |  |  | 6 | //
 | 
        
           |  |  | 7 |   | 
        
           |  |  | 8 |   | 
        
           |  |  | 9 | import SwiftUI
 | 
        
           |  |  | 10 |   | 
        
           |  |  | 11 | struct FinishCapsuleView: View {
 | 
        
           |  |  | 12 |     @EnvironmentObject var appNavigation : AppNavigation
 | 
        
           |  |  | 13 |   | 
        
           | 21 | efrain | 14 |     private var appData = Environment(\.appData).wrappedValue
 | 
        
           | 1 | efrain | 15 |   | 
        
           |  |  | 16 |     private let capsuleModel : CapsuleModel
 | 
        
           |  |  | 17 |     private let topicModel : TopicModel
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 |     init()
 | 
        
           |  |  | 20 |     {
 | 
        
           |  |  | 21 |   | 
        
           | 17 | efrain | 22 |         let capsuleDao = CapsuleDao()
 | 
        
           | 1 | efrain | 23 |         capsuleModel = capsuleDao.selectByUuid(uuid: appData.capsuleUuidActive)
 | 
        
           |  |  | 24 |   | 
        
           | 17 | efrain | 25 |         let topicDao = TopicDao()
 | 
        
           | 1 | efrain | 26 |         topicModel = topicDao.selectByUuid(uuid: capsuleModel.topicUuid)
 | 
        
           |  |  | 27 |     }
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 |     var body: some View {
 | 
        
           |  |  | 31 |         HStack {
 | 
        
           |  |  | 32 |             Spacer()
 | 
        
           |  |  | 33 |         VStack(spacing: 0) {
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 |             LottieView(name: "topic-finish")
 | 
        
           |  |  | 36 |                 .frame(width: UIScreen.main.bounds.width / 2,
 | 
        
           |  |  | 37 |                        height: UIScreen.main.bounds.height / 4)
 | 
        
           |  |  | 38 |                 .padding(.top, 40)
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 |             Text(Config.LANG_FINISH_CAPSULE_TITLE)
 | 
        
           |  |  | 41 |                 .font(Font.custom(Config.FONT_NAME_BOLD, size:Config.FONT_SIZE_FINISH_TITLE))
 | 
        
           |  |  | 42 |                 .foregroundColor(Color("color_textview_foreground"))
 | 
        
           |  |  | 43 |                 .padding(.top, 40)
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 |             Text(Config.LANG_FINISH_CAPSULE_LABEL)
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 |                 .font(Font.custom(Config.FONT_NAME_BOLD, size:Config.FONT_SIZE_FINISH_MESSAGE))
 | 
        
           |  |  | 49 |                 .foregroundColor(Color("color_textview_foreground"))
 | 
        
           |  |  | 50 |   | 
        
           |  |  | 51 |                 .padding(.top, 20)
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 |     Spacer()
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |                      Button(action: {
 | 
        
           |  |  | 56 |                         let dataService = DataService()
 | 
        
           |  |  | 57 |                         dataService.complete(topicModel: topicModel, capsuleModel: capsuleModel)
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 |   | 
        
           |  |  | 60 |                         appData.topicUuidActive = ""
 | 
        
           |  |  | 61 |                         appData.capsuleUuidActive = ""
 | 
        
           |  |  | 62 |                         appData.slideUuidActive = ""
 | 
        
           |  |  | 63 |                         appData.save()
 | 
        
           |  |  | 64 |   | 
        
           |  |  | 65 |                         if appNavigation.subPageSource == .topics {
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |                             withAnimation {
 | 
        
           |  |  | 68 |                                 appNavigation.subpageActive = .capsules
 | 
        
           |  |  | 69 |                             }
 | 
        
           |  |  | 70 |                         } else {
 | 
        
           |  |  | 71 |                             withAnimation {
 | 
        
           |  |  | 72 |                                 appNavigation.subpageActive = .mycapsules
 | 
        
           |  |  | 73 |                             }
 | 
        
           |  |  | 74 |                         }
 | 
        
           |  |  | 75 |   | 
        
           |  |  | 76 |                      }, label: {
 | 
        
           |  |  | 77 |                         Text(Config.LANG_BUTTON_CONTINUE)
 | 
        
           |  |  | 78 |                             .font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
 | 
        
           |  |  | 79 |                             .frame(width: UIScreen.main.bounds.width - 32, height: 35)
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |                                .foregroundColor(Color("color_button_dark_foreground"))
 | 
        
           |  |  | 82 |                                .background(Color("color_button_dark_background"))
 | 
        
           |  |  | 83 |                                .border(Color( "color_button_dark_border"), width: Config.BUTTON_BORDER_SIZE)
 | 
        
           |  |  | 84 |                                .cornerRadius(Config.BUTTON_BORDER_RADIUS)
 | 
        
           |  |  | 85 |                      }).padding(.bottom, 30)
 | 
        
           |  |  | 86 |   | 
        
           |  |  | 87 |         }
 | 
        
           |  |  | 88 |             Spacer();
 | 
        
           |  |  | 89 |         }.background(Color("color_window_background"))
 | 
        
           |  |  | 90 |     }
 | 
        
           |  |  | 91 | }
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 | struct FinishCapsuleView_Previews: PreviewProvider {
 | 
        
           |  |  | 94 |     static var previews: some View {
 | 
        
           |  |  | 95 |         FinishCapsuleView()
 | 
        
           |  |  | 96 |     }
 | 
        
           |  |  | 97 | }
 |