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 |
|
|
|
12 |
@EnvironmentObject private var appNavigation : AppNavigation
|
|
|
13 |
@ObservedObject private var viewModel = CapsuleCardViewModel()
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
private let userUuid : String;
|
|
|
17 |
private var capsuleTitle : String = ""
|
21 |
efrain |
18 |
private var appData = Environment(\.appData).wrappedValue
|
1 |
efrain |
19 |
|
|
|
20 |
|
|
|
21 |
init(capsuleUuid : String)
|
|
|
22 |
{
|
|
|
23 |
userUuid = appData.userUuid
|
|
|
24 |
viewModel.fetch(capsuleUuid: capsuleUuid, userUuid: appData.userUuid)
|
|
|
25 |
|
|
|
26 |
if viewModel.capsule.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
|
|
|
27 |
capsuleTitle = String(Array(self.viewModel.capsule.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
|
|
|
28 |
} else {
|
|
|
29 |
capsuleTitle = viewModel.capsule.name
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
var body: some View {
|
|
|
36 |
|
|
|
37 |
Button(action: {
|
|
|
38 |
appData.topicUuidActive = self.viewModel.capsule.topicUuid
|
|
|
39 |
appData.capsuleUuidActive = self.viewModel.capsule.uuid
|
|
|
40 |
appData.slideUuidActive = ""
|
|
|
41 |
appData.save()
|
|
|
42 |
|
|
|
43 |
appNavigation.subpageActive = .slides
|
|
|
44 |
|
|
|
45 |
}) {
|
|
|
46 |
VStack {
|
|
|
47 |
Text(self.capsuleTitle)
|
|
|
48 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_TITLE))
|
|
|
49 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
50 |
.padding(.horizontal, 5)
|
|
|
51 |
.padding(.top, 5)
|
|
|
52 |
.multilineTextAlignment(/*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/)
|
|
|
53 |
|
|
|
54 |
HStack {
|
19 |
efrain |
55 |
if self.viewModel.capsule.image.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
1 |
efrain |
56 |
Image(uiImage: UIImage(named: "logo") ?? UIImage())
|
|
|
57 |
.resizable()
|
|
|
58 |
.aspectRatio(contentMode: .fit)
|
|
|
59 |
} else {
|
|
|
60 |
CustomAsyncImage(
|
19 |
efrain |
61 |
url: URL(string: self.viewModel.capsule.image.trimmingCharacters(in: .whitespacesAndNewlines))!,
|
1 |
efrain |
62 |
placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
|
|
|
63 |
image: {
|
|
|
64 |
Image(uiImage: $0).resizable()
|
|
|
65 |
}
|
|
|
66 |
)
|
|
|
67 |
}
|
|
|
68 |
}.padding(.horizontal, 5)
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
Spacer()
|
|
|
72 |
|
|
|
73 |
Group() {
|
|
|
74 |
HStack {
|
|
|
75 |
ProgressBar(
|
|
|
76 |
value: self.viewModel.capsule.progress,
|
|
|
77 |
maxValue: 100,
|
|
|
78 |
backgroundColor: Color("color_card_view_progress_background"),
|
|
|
79 |
foregroundColor: Color("color_card_view_progress_foreground")
|
|
|
80 |
|
|
|
81 |
)
|
|
|
82 |
.frame(height: 6)
|
|
|
83 |
.padding(10)
|
|
|
84 |
|
|
|
85 |
Text( String(format: "%.1f", self.viewModel.capsule.progress) + "%")
|
|
|
86 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_CARD_VIEW_FOOTER ))
|
|
|
87 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
88 |
.padding(5)
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
.background(Color("color_card_view_background_footer"))
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
.background(Color("color_card_view_background"))
|
|
|
95 |
.cornerRadius(16)
|
|
|
96 |
.overlay(
|
|
|
97 |
RoundedRectangle(cornerRadius: 16)
|
|
|
98 |
.stroke(Color("color_card_view_border"), lineWidth:1)
|
|
|
99 |
)
|
|
|
100 |
.padding(.horizontal, 5)
|
|
|
101 |
}.onAppear {
|
|
|
102 |
viewModel.fetchProgress(capsuleUuid: self.viewModel.capsule.uuid, userUuid: self.userUuid)
|
|
|
103 |
}
|
|
|
104 |
.onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_CHANGE_PERCENTAJE_COMPLETED_CAPSULE))
|
|
|
105 |
{ data in
|
|
|
106 |
if data.userInfo != nil {
|
|
|
107 |
if let capsuleUuid = data.userInfo?["capsuleUuid"]! as? String {
|
|
|
108 |
if !capsuleUuid.isEmpty && capsuleUuid == self.viewModel.capsule.uuid {
|
|
|
109 |
|
|
|
110 |
self.viewModel.fetchProgress(capsuleUuid: capsuleUuid, userUuid: appData.userUuid)
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
.padding(.top, 5)
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
struct CardCapsuleView_Previews: PreviewProvider {
|
|
|
126 |
static var previews: some View {
|
|
|
127 |
CardCapsuleView(capsuleUuid: "C123")
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
|