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