AutorÃa | Ultima modificación | Ver Log |
//// CardCapsuleView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 2/17/22.//import SwiftUIstruct CardCapsuleView: View {private var capsuleModel : CapsuleModel@State private var colorCardViewBackground = UIColor(hex: Config.COLOR_WINDOW_BACKGROUND)@State private var colorWindowBackground = UIColor(hex: Config.COLOR_WINDOW_BACKGROUND)@State private var colorCardViewBorder = UIColor(hex: Config.COLOR_CARD_VIEW_BORDER)@State private var colorBackgroundTopicFooter = UIColor(hex: Config.COLOR_BACKGROUND_TOPIC_FOOTER)@State private var colorForegroundTopicProgressBar = UIColor(hex: Config.COLOR_FOREGROUND_TOPIC_PROGRESS_BAR)@State private var colorTitle = UIColor(hex: Config.COLOR_TEXT_VIEW_TITLE);@State private var goToSlides : Bool = falseinit(capsuleModel : CapsuleModel){self.capsuleModel = capsuleModelif self.capsuleModel.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {self.capsuleModel.name = String(Array(self.capsuleModel.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."}}var body: some View {Button(action: {let preference = Preference.sharedInstancepreference.topicUuidActive = self.capsuleModel.topicUuidpreference.capsuleUuidActive = self.capsuleModel.uuidpreference.slideUuidActive = ""preference.save()self.goToSlides = true}) {NavigationLink("", destination: GridSlideView(capsuleUuid: self.capsuleModel.uuid), isActive: self.$goToSlides).frame( height: 0)VStack {Text(self.capsuleModel.name).fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/).font(.system(size: 11.0)).foregroundColor(Color(colorTitle ?? .red)).padding(.horizontal, 5).padding(.top, 5)Spacer()HStack {if self.capsuleModel.image.isEmpty {Image(uiImage: UIImage(named: "logo") ?? UIImage()).resizable().aspectRatio(contentMode: .fit)} else {CustomAsyncImage(url: URL(string: self.capsuleModel.image)!,placeholder: { Text("Cargando...").font(.footnote).foregroundColor(.black)},image: {Image(uiImage: $0).resizable()})}}.padding(.horizontal, 5)Spacer()Group() {HStack {ProgressBar(value: self.capsuleModel.progress,maxValue: 100,foregroundColor: Color(colorForegroundTopicProgressBar ?? .green)).frame(height: 6).padding(10)Text( String(format: "%.1f", self.capsuleModel.progress) + "%").font(.system(size: 9.0)).foregroundColor(Color(colorTitle ?? .red)).padding(5)}}.background(Color(colorBackgroundTopicFooter ?? .systemBlue))}.background(Color(colorCardViewBackground ?? .gray)).cornerRadius(16).overlay(RoundedRectangle(cornerRadius: 16).stroke(Color(colorCardViewBorder ?? .systemBlue), lineWidth:1)).padding(.horizontal, 5)} .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE)){ data in// print("CardGalleryView Receive " )if data.userInfo != nil {if let capsuleUuid = data.userInfo?["capsuleUuid"]! as? String {if !capsuleUuid.isEmpty && capsuleUuid == self.capsuleModel.uuid {// loadProgress()}}}} .onAppear {print("CardCapsuleView")}.padding(.top, 5)}}struct CardCapsuleView_Previews: PreviewProvider {static var previews: some View {let capsule = CapsuleModel(uuid: "C123", topicUuid: "T123",name: "Capsula #1",description: "",image: "https://dev.leaderslinked.com/images/ll-logo.png",position: 10,totalSlides: 20,viewSlides: 10,progress: 50,completed: 1)CardCapsuleView(capsuleModel: capsule)}}