blob: f9d9c5edb6175ce0a711f66ef9ef4a9e60ff0d00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
//
// GenerationView.swift
// InfiniSolar WatchKit Extension
//
// Created by Evgeny Zinoviev on 08.08.2021.
//
import SwiftUI
struct GenerationView: View {
@ObservedObject var state = InverterGenerationState()
var body: some View {
VStack(alignment: .leading) {
Text("Generation")
.font(.title2)
.fontWeight(.thin)
Spacer().frame(height: 10)
if self.state.failed == true {
Text("Error while fetching info.")
.multilineTextAlignment(.leading)
Spacer().frame(height: 10)
Button(action:{
self.state.fetch()
}) {
Text("Retry")
}
} else if !self.state.done {
ProgressView().progressViewStyle(CircularProgressViewStyle())
} else {
Text("Today: ")
+ Text(String(self.state.today) + " Wh").fontWeight(.thin)
if self.state.yesterday > 0 {
Spacer().frame(height: 5)
Text("Yesterday: ")
+ Text(String(self.state.yesterday) + " Wh").fontWeight(.thin)
}
if self.state.dayBeforeYesterday > 0 {
Spacer().frame(height: 5)
Text("The day before yesterday: ")
+ Text(String(self.state.dayBeforeYesterday) + " Wh").fontWeight(.thin)
}
}
}.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
).onAppear() {
self.state.fetch()
}.onDisappear() {
self.state.stop()
}
}
}
struct GenerationView_Previews: PreviewProvider {
static var previews: some View {
GenerationView()
}
}
|