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