1 |
efrain |
1 |
//
|
|
|
2 |
// ProgressView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 5/5/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import Foundation
|
|
|
9 |
import SwiftUI
|
|
|
10 |
|
|
|
11 |
struct MyProgressView: View {
|
|
|
12 |
|
|
|
13 |
@EnvironmentObject private var networkMonitor : NetworkMonitor
|
|
|
14 |
@EnvironmentObject private var appNavigation : AppNavigation
|
|
|
15 |
@ObservedObject private var viewModel = ProgressViewModel()
|
|
|
16 |
|
|
|
17 |
init()
|
|
|
18 |
{
|
|
|
19 |
viewModel.load()
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
var body: some View {
|
|
|
23 |
|
|
|
24 |
GeometryReader { geometry in
|
|
|
25 |
VStack(spacing: 0) {
|
|
|
26 |
HStack {
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
Image("logo")
|
|
|
30 |
.resizable()
|
|
|
31 |
.frame(width: 32, height: 32, alignment: .center)
|
|
|
32 |
.aspectRatio(contentMode: .fit)
|
|
|
33 |
.foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
|
|
|
34 |
.padding(.leading, 16)
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : Config.LANG_TAB_BAR_BUTTON_PROGRESS)
|
|
|
38 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
|
|
|
39 |
.foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))
|
|
|
40 |
.padding(.leading, 4)
|
|
|
41 |
|
|
|
42 |
Spacer()
|
|
|
43 |
|
|
|
44 |
}
|
|
|
45 |
.edgesIgnoringSafeArea(.top)
|
|
|
46 |
.frame(height: 50)
|
|
|
47 |
.background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
|
|
|
48 |
|
|
|
49 |
Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
HStack {
|
|
|
54 |
Text("Cápsulas")
|
|
|
55 |
.font(.title3)
|
|
|
56 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
57 |
.foregroundColor(Color("color_app_bar_foreground"))
|
|
|
58 |
Spacer()
|
|
|
59 |
}.padding([.top], 10)
|
|
|
60 |
.padding(.horizontal, 10)
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
HStack {
|
|
|
64 |
Spacer()
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
PieChartView(
|
|
|
68 |
values:[viewModel.percentajeCapsuleIncomplete, viewModel.percentajeCapsuleComplete],
|
|
|
69 |
names: ["", ""],
|
|
|
70 |
formatter: {value in String(format: "%.2f%%", value)},
|
|
|
71 |
colors: [
|
|
|
72 |
Color("color_progress_graph_background"),
|
|
|
73 |
Color("color_progress_graph_foreground")
|
|
|
74 |
],
|
|
|
75 |
backgroundColor: Color("color_window_background"),
|
|
|
76 |
widthFraction: 0.75,
|
|
|
77 |
innerRadiusFraction: 0.60,
|
|
|
78 |
chartSize : 250,
|
|
|
79 |
total : viewModel.percentajeCapsuleComplete
|
|
|
80 |
)
|
|
|
81 |
.frame(width: 190, height: 190, alignment: .center)
|
|
|
82 |
|
|
|
83 |
Spacer()
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
HStack {
|
|
|
89 |
Spacer()
|
|
|
90 |
VStack {
|
|
|
91 |
Text(String(viewModel.capsuleTotal))
|
|
|
92 |
.font(.subheadline)
|
|
|
93 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
94 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
95 |
|
|
|
96 |
Text("Total")
|
|
|
97 |
.font(.subheadline)
|
|
|
98 |
.foregroundColor(.gray)
|
|
|
99 |
}
|
|
|
100 |
VStack {
|
|
|
101 |
Text(String(viewModel.capsuleTotalStarted))
|
|
|
102 |
.font(.subheadline)
|
|
|
103 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
104 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
105 |
|
|
|
106 |
Text("Iniciadas")
|
|
|
107 |
.font(.subheadline)
|
|
|
108 |
.foregroundColor(.gray)
|
|
|
109 |
}
|
|
|
110 |
VStack {
|
|
|
111 |
Text(String(viewModel.capsuleTotalForStart))
|
|
|
112 |
.font(.subheadline)
|
|
|
113 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
114 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
115 |
|
|
|
116 |
Text("Por realizar")
|
|
|
117 |
.font(.subheadline)
|
|
|
118 |
.foregroundColor(.gray)
|
|
|
119 |
}
|
|
|
120 |
VStack {
|
|
|
121 |
Text(String(viewModel.capsuleTotalCompleted))
|
|
|
122 |
.font(.subheadline)
|
|
|
123 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
124 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
125 |
|
|
|
126 |
Text("Completadas")
|
|
|
127 |
.font(.subheadline)
|
|
|
128 |
.foregroundColor(.gray)
|
|
|
129 |
}
|
|
|
130 |
Spacer()
|
|
|
131 |
|
|
|
132 |
}.padding([.top], 5)
|
|
|
133 |
|
|
|
134 |
HStack {
|
|
|
135 |
Text("Retorno")
|
|
|
136 |
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
|
|
|
137 |
.font(.title3)
|
|
|
138 |
.foregroundColor(Color("color_textview_foreground"))
|
|
|
139 |
Spacer()
|
|
|
140 |
}.padding([.top], 5)
|
|
|
141 |
.padding(.horizontal, 10)
|
|
|
142 |
|
|
|
143 |
HStack {
|
|
|
144 |
Spacer()
|
|
|
145 |
|
|
|
146 |
PieChartView(
|
|
|
147 |
values:[
|
|
|
148 |
Double(viewModel.capsuleTotalWithoutReturning),
|
|
|
149 |
Double(viewModel.capsuleTotalWithReturning)
|
|
|
150 |
],
|
|
|
151 |
names: ["", ""],
|
|
|
152 |
formatter: {value in String(format: "%.0f", value)},
|
|
|
153 |
colors: [
|
|
|
154 |
Color("color_progress_graph_background"),
|
|
|
155 |
Color("color_progress_graph_foreground")
|
|
|
156 |
],
|
|
|
157 |
backgroundColor: Color("color_window_background"),
|
|
|
158 |
widthFraction: 0.75,
|
|
|
159 |
innerRadiusFraction: 0.60,
|
|
|
160 |
chartSize : 250,
|
|
|
161 |
total : Double(viewModel.capsuleTotalWithReturning)
|
|
|
162 |
|
|
|
163 |
)
|
|
|
164 |
.frame(width: 190, height: 190, alignment: .center)
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
Spacer()
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
Spacer()
|
|
|
172 |
|
|
|
173 |
}.onAppear {
|
|
|
174 |
viewModel.load()
|
|
|
175 |
}
|
|
|
176 |
.frame(width: geometry.size.width, height: geometry.size.height, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
|
|
177 |
.background(Color("color_window_background"))
|
|
|
178 |
.navigationTitle("Progreso")
|
|
|
179 |
.navigationBarTitleDisplayMode(.inline)
|
|
|
180 |
.navigationBarBackButtonHidden(true)
|
|
|
181 |
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
struct MyProgressView_Previews: PreviewProvider {
|
|
|
188 |
static var previews: some View {
|
|
|
189 |
MyProgressView()
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|