Autoría | Ultima modificación | Ver Log |
//// CardTopicView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 1/26/22.//import SwiftUIstruct CardTopicView: View{private let colorCardViewBackground = UIColor(hex: Config.COLOR_WINDOW_BACKGROUND)private let colorCardViewBorder = UIColor(hex: Config.COLOR_CARD_VIEW_BORDER)private let colorBackgroundTopicFooter = UIColor(hex: Config.COLOR_BACKGROUND_TOPIC_FOOTER)private let colorForegroundTopicProgressBar = UIColor(hex: Config.COLOR_FOREGROUND_TOPIC_PROGRESS_BAR)private let colorTitle = UIColor(hex: Config.COLOR_TEXT_VIEW_TITLE);@State private var goToCapsules : Bool = falseprivate var topicModel : TopicModelinit(topicModel : TopicModel){self.topicModel = topicModelif self.topicModel.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {self.topicModel.name = String(Array(self.topicModel.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."}}var body: some View {Button(action: {let preference = Preference.sharedInstancepreference.topicUuidActive = self.topicModel.uuidpreference.capsuleUuidActive = ""preference.slideUuidActive = ""preference.save()self.goToCapsules = true}) {NavigationLink("", destination: GridCapsuleView(topicUuid: self.topicModel.uuid), isActive: self.$goToCapsules).frame( height: 0)VStack {Text(self.topicModel.name).fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/).font(.system(size: 11.0)).foregroundColor(Color(colorTitle ?? .white)).padding(.horizontal, 5).padding(.top, 5).multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)Spacer()HStack {if self.topicModel.image.isEmpty {Image(uiImage: UIImage(named: "logo") ?? UIImage()).resizable().aspectRatio(contentMode: .fit)} else {CustomAsyncImage(url: URL(string: self.topicModel.image)!,placeholder: { Text("Cargando...").font(.footnote).foregroundColor(.black)},image: {Image(uiImage: $0).resizable()})}}.padding(.horizontal, 5)Spacer()Group() {HStack {ProgressBar(value: self.topicModel.progress,maxValue: 100,foregroundColor: Color(colorForegroundTopicProgressBar ?? .green)).frame(height: 6).padding(10)Text( String(format: "%.1f", self.topicModel.progress) + "%").font(.system(size: 11.0)).foregroundColor(Color(colorTitle ?? .white)).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)} .onAppear {print("CardTopicView")} .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC)){ data in// print("CardGalleryView Receive " )if data.userInfo != nil {if let topicUuid = data.userInfo?["topicUuid"]! as? String {if !topicUuid.isEmpty && topicUuid == self.topicModel.uuid {//loadProgress()}}}}.padding(.top, 5)}}struct CardTopicView_Previews: PreviewProvider {static var previews: some View {let topic = TopicModel(uuid: "T123",companyUuid: "C123", name: "Titulo1", description: "Descripción 1", image: "https://dev.leaderslinked.com/images/ll-logo.png", position: 1, totalSlides: 20, viewSlides: 10, progress: 50, completed: 0)CardTopicView(topicModel: topic)}}