1 |
efrain |
1 |
//
|
|
|
2 |
// CardTopicView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 1/26/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import SwiftUI
|
|
|
9 |
|
|
|
10 |
struct CardTopicView: View
|
|
|
11 |
{
|
|
|
12 |
private let colorCardViewBackground = UIColor(hex: Config.COLOR_WINDOW_BACKGROUND)
|
|
|
13 |
private let colorCardViewBorder = UIColor(hex: Config.COLOR_CARD_VIEW_BORDER)
|
|
|
14 |
private let colorBackgroundTopicFooter = UIColor(hex: Config.COLOR_BACKGROUND_TOPIC_FOOTER)
|
|
|
15 |
private let colorForegroundTopicProgressBar = UIColor(hex: Config.COLOR_FOREGROUND_TOPIC_PROGRESS_BAR)
|
|
|
16 |
private let colorTitle = UIColor(hex: Config.COLOR_TEXT_VIEW_TITLE);
|
|
|
17 |
|
|
|
18 |
@State private var goToCapsules : Bool = false
|
|
|
19 |
private var topicModel : TopicModel
|
|
|
20 |
|
|
|
21 |
init(topicModel : TopicModel)
|
|
|
22 |
{
|
|
|
23 |
self.topicModel = topicModel
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
if self.topicModel.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
|
|
|
27 |
self.topicModel.name = String(Array(self.topicModel.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
var body: some View {
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
Button(action: {
|
|
|
36 |
let preference = Preference.sharedInstance
|
|
|
37 |
preference.topicUuidActive = self.topicModel.uuid
|
|
|
38 |
preference.capsuleUuidActive = ""
|
|
|
39 |
preference.slideUuidActive = ""
|
|
|
40 |
preference.save()
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
self.goToCapsules = true
|
|
|
44 |
}) {
|
|
|
45 |
NavigationLink("", destination: GridCapsuleView(topicUuid: self.topicModel.uuid), isActive: self.$goToCapsules).frame( height: 0)
|
|
|
46 |
|
|
|
47 |
VStack {
|
|
|
48 |
|
|
|
49 |
Text(self.topicModel.name)
|
|
|
50 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
51 |
.font(.system(size: 11.0))
|
|
|
52 |
.foregroundColor(Color(colorTitle ?? .white))
|
|
|
53 |
.padding(.horizontal, 5)
|
|
|
54 |
.padding(.top, 5)
|
|
|
55 |
.multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
|
|
|
56 |
|
|
|
57 |
Spacer()
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
HStack {
|
|
|
61 |
if self.topicModel.image.isEmpty {
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
Image(uiImage: UIImage(named: "logo") ?? UIImage())
|
|
|
65 |
.resizable()
|
|
|
66 |
.aspectRatio(contentMode: .fit)
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
} else {
|
|
|
70 |
CustomAsyncImage(
|
|
|
71 |
url: URL(string: self.topicModel.image)!,
|
|
|
72 |
placeholder: { Text("Cargando...").font(.footnote).foregroundColor(.black)},
|
|
|
73 |
image: {
|
|
|
74 |
Image(uiImage: $0).resizable()
|
|
|
75 |
}
|
|
|
76 |
)
|
|
|
77 |
}
|
|
|
78 |
}.padding(.horizontal, 5)
|
|
|
79 |
|
|
|
80 |
Spacer()
|
|
|
81 |
|
|
|
82 |
Group() {
|
|
|
83 |
HStack {
|
|
|
84 |
|
|
|
85 |
ProgressBar(
|
|
|
86 |
value: self.topicModel.progress,
|
|
|
87 |
maxValue: 100,
|
|
|
88 |
foregroundColor: Color(colorForegroundTopicProgressBar ?? .green)
|
|
|
89 |
|
|
|
90 |
)
|
|
|
91 |
.frame(height: 6)
|
|
|
92 |
.padding(10)
|
|
|
93 |
|
|
|
94 |
Text( String(format: "%.1f", self.topicModel.progress) + "%")
|
|
|
95 |
.font(.system(size: 11.0))
|
|
|
96 |
.foregroundColor(Color(colorTitle ?? .white))
|
|
|
97 |
.padding(5)
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
.background(Color(colorBackgroundTopicFooter ?? .systemBlue))
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
.background(Color(colorCardViewBackground ?? .gray))
|
|
|
104 |
.cornerRadius(16)
|
|
|
105 |
.overlay(
|
|
|
106 |
RoundedRectangle(cornerRadius: 16)
|
|
|
107 |
.stroke(Color(colorCardViewBorder ?? .systemBlue), lineWidth:1)
|
|
|
108 |
)
|
|
|
109 |
.padding(.horizontal, 5)
|
|
|
110 |
} .onAppear {
|
|
|
111 |
print("CardTopicView")
|
|
|
112 |
} .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_TOPIC))
|
|
|
113 |
{ data in
|
|
|
114 |
// print("CardGalleryView Receive " )
|
|
|
115 |
|
|
|
116 |
if data.userInfo != nil {
|
|
|
117 |
if let topicUuid = data.userInfo?["topicUuid"]! as? String {
|
|
|
118 |
if !topicUuid.isEmpty && topicUuid == self.topicModel.uuid {
|
|
|
119 |
//loadProgress()
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
.padding(.top, 5)
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
struct CardTopicView_Previews: PreviewProvider {
|
|
|
135 |
static var previews: some View {
|
|
|
136 |
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)
|
|
|
137 |
|
|
|
138 |
CardTopicView(topicModel: topic)
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
|