| 1 |
efrain |
1 |
//
|
|
|
2 |
// CapsuleInProgressView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 7/27/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import SwiftUI
|
|
|
9 |
import HTMLEntities
|
|
|
10 |
|
|
|
11 |
struct MyCapsuleInProgressView: View {
|
|
|
12 |
|
|
|
13 |
@EnvironmentObject var appNavigation : AppNavigation
|
|
|
14 |
private let appData : AppData = AppData.sharedInstance
|
|
|
15 |
|
|
|
16 |
private var capsuleModel : CapsuleModel
|
|
|
17 |
private var capsuleTitle : String
|
|
|
18 |
|
|
|
19 |
init(capsuleUuid: String)
|
|
|
20 |
{
|
|
|
21 |
let capsuleDao = CapsuleDao.sharedInstance
|
|
|
22 |
capsuleModel = capsuleDao.selectByUuid(uuid: capsuleUuid)
|
|
|
23 |
|
|
|
24 |
if capsuleModel.uuid.isEmpty {
|
|
|
25 |
self.capsuleTitle = Config.LANG_MY_CAPSULES_INPROGRESS_NOT_AVAILABLE
|
|
|
26 |
} else {
|
|
|
27 |
|
|
|
28 |
if capsuleModel.name.count > Constants.CAPSULE_TITLE_MAX_LENGTH {
|
|
|
29 |
self.capsuleTitle = String(Array(capsuleModel.name)[0...Constants.CAPSULE_TITLE_MAX_LENGTH]) + "..."
|
|
|
30 |
} else {
|
|
|
31 |
self.capsuleTitle = capsuleModel.name
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
var body: some View {
|
|
|
42 |
Group {
|
|
|
43 |
HStack {
|
|
|
44 |
VStack(spacing: 0) {
|
|
|
45 |
HStack {
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
Text(Config.LANG_MY_CAPSULES_INPROGRESS_TITLE)
|
|
|
50 |
.font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_TITLE))
|
|
|
51 |
.foregroundColor(Color("color_capsule_inprogress_foreground_title"))
|
|
|
52 |
|
|
|
53 |
Spacer()
|
|
|
54 |
}
|
|
|
55 |
.padding(.top, 16)
|
|
|
56 |
.padding(.leading, 16)
|
|
|
57 |
|
|
|
58 |
HStack {
|
|
|
59 |
Text(self.capsuleTitle)
|
|
|
60 |
.font(Font.custom(Config.FONT_NAME_BOLD, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_CAPSULE_NAME))
|
|
|
61 |
.foregroundColor(Color("color_capsule_inprogress_foreground_capsule_name"))
|
|
|
62 |
|
|
|
63 |
.padding(.leading, 4)
|
|
|
64 |
.padding(.trailing, 4)
|
|
|
65 |
Spacer()
|
|
|
66 |
}
|
|
|
67 |
.padding(.top, 10)
|
|
|
68 |
.padding(.leading, 16)
|
|
|
69 |
|
|
|
70 |
HStack {
|
|
|
71 |
ProgressBar(
|
|
|
72 |
value: self.capsuleModel.progress,
|
|
|
73 |
maxValue: 100,
|
|
|
74 |
backgroundColor: Color("color_capsule_inprogress_progress_bar_background"),
|
|
|
75 |
foregroundColor: Color("color_capsule_inprogress_progress_bar_foreground")
|
|
|
76 |
|
|
|
77 |
)
|
|
|
78 |
.frame(height: 6)
|
|
|
79 |
.padding(10)
|
|
|
80 |
|
|
|
81 |
Text( String(format: "%.1f", self.capsuleModel.progress) + "%")
|
|
|
82 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_PROGRESS_LABEL ))
|
|
|
83 |
.foregroundColor(Color("color_capsule_inprogress_progress_label"))
|
|
|
84 |
.padding(5)
|
|
|
85 |
}
|
|
|
86 |
.padding(.leading, 10)
|
|
|
87 |
.padding(.trailing, 10)
|
|
|
88 |
|
|
|
89 |
Spacer()
|
|
|
90 |
|
|
|
91 |
if !self.capsuleModel.uuid.isEmpty {
|
|
|
92 |
|
|
|
93 |
HStack {
|
|
|
94 |
Button(action: {
|
|
|
95 |
|
|
|
96 |
appData.topicUuidActive = capsuleModel.topicUuid
|
|
|
97 |
appData.capsuleUuidActive = capsuleModel.uuid
|
|
|
98 |
appData.slideUuidActive = ""
|
|
|
99 |
appData.subPageSource = AppData.SUB_PAGE_SOURCE_MY_CAPSULES
|
|
|
100 |
appData.save()
|
|
|
101 |
|
|
|
102 |
withAnimation {
|
| 8 |
efrain |
103 |
appNavigation.subpageActive = .slides
|
| 1 |
efrain |
104 |
}
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
}, label: {
|
|
|
108 |
Text(Config.LANG_MY_CAPSULES_INPROGRESS_BUTTON_CONTINUE)
|
|
|
109 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_MY_CAPSULES_INPROGRESS_BUTTON))
|
|
|
110 |
.foregroundColor(Color("color_capsule_inprogress_button_foreground"))
|
|
|
111 |
.padding(.vertical, 5)
|
|
|
112 |
.padding(.horizontal, 10)
|
|
|
113 |
|
|
|
114 |
})
|
|
|
115 |
.background(Color("color_capsule_inprogress_button_background"))
|
|
|
116 |
.cornerRadius(3)
|
|
|
117 |
.overlay(
|
|
|
118 |
RoundedRectangle(cornerRadius: 3)
|
|
|
119 |
.stroke(Color("color_capsule_inprogress_button_border"), lineWidth:1)
|
|
|
120 |
)
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
Spacer()
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
.padding(.leading, 16)
|
|
|
129 |
.padding(.bottom, 10)
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
}
|
|
|
134 |
Group {
|
|
|
135 |
if self.capsuleModel.image.isEmpty {
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
Image(uiImage: UIImage(named: "logo") ?? UIImage())
|
|
|
139 |
.resizable()
|
|
|
140 |
.resizable()
|
|
|
141 |
.aspectRatio(contentMode: .fit)
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
} else {
|
|
|
146 |
CustomAsyncImage(
|
|
|
147 |
url: URL(string: self.capsuleModel.image)!,
|
|
|
148 |
placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
|
|
|
149 |
image: {
|
|
|
150 |
Image(uiImage: $0).resizable()
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
}
|
|
|
154 |
)
|
|
|
155 |
}
|
|
|
156 |
} . frame(width: 93, height: 140, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
157 |
.background(Color("color_window_background"))
|
|
|
158 |
.padding(.top, 16)
|
|
|
159 |
.padding(.bottom, 16)
|
|
|
160 |
.padding(.trailing, 16)
|
|
|
161 |
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
.frame(width: UIScreen.main.bounds.width - 32, height: 151)
|
|
|
165 |
.background(Color("color_capsule_inprogress_background"))
|
|
|
166 |
.cornerRadius(8)
|
|
|
167 |
.overlay(
|
|
|
168 |
RoundedRectangle(cornerRadius: 8)
|
|
|
169 |
.stroke(Color("color_capsule_comment_rating_image_border"), lineWidth:1)
|
|
|
170 |
)
|
|
|
171 |
.shadow(color: Color("color_capsule_inprogress_shadow"), radius:4, x: 5, y: 5)
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
struct MyCapsuleInProgressView_Previews: PreviewProvider {
|
|
|
178 |
static var previews: some View {
|
|
|
179 |
MyCapsuleInProgressView(capsuleUuid: "C123")
|
|
|
180 |
}
|
|
|
181 |
}
|