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