-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEndView.swift
96 lines (92 loc) · 2.87 KB
/
EndView.swift
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// StartSymptomSurvey.swift
// covid19-sounds
//
// Authors (by order of contribution):
//
// Andreas Grammenos
// Api Hastanasombat
//
// Copyright © 2020 Computer Lab / Mobile Systems Group. All rights reserved.
//
import SwiftUI
import Combine
/// The `View` that is displayed at the end of the survey - due to length it has been segmented
/// to various subviews, which can be seen as independent bits that comprise this.
///
struct EndView: View {
/// the `UserInstance` instance as an `EnvironmentObject`.
@EnvironmentObject private var userInstance: UserInstance
/// the `AppStatus` instance as an `EnvironmentObject`.
@EnvironmentObject private var appStatus: AppStatus
/// shows an alert if we had an error
@State private var alert = false
/// the variable that is used to check if we are fetching location or uploading.
@ObservedObject private var buttonState = uploadButtonState
//
/// the `View` body definition.
var body: some View {
ZStack {
//
VStack {
//
if appStatus.appState == .justUploaded {
//
EndViewTopTextView().frame(minHeight: 370).onAppear {
finaliseActions()
}
//
Spacer()
//
EndViewBottomTextView()
.frame(maxHeight: 400)
//
} else {
// normally the state should be either
// .failed or .failedButCanTryAgain
//
EndViewErrorView()
//
}
}
.modifier(AppBackgroundStyle())
.disabled(buttonState.loading)
.blur(radius: buttonState.loading ? 3 : 0)
//
ActivityIndicatorView()
//
}.alert(isPresented: self.$alert) {
Alert(title: Text("Error uploading"),
message: Text(appStatus.getErrorDescription()),
dismissButton: .default(Text("OK")))
}
}
}
/// This function is responsible for saving the final data to the `CoreData` as well as deleting
/// the generated audio files.
///
private func finaliseActions() {
log.info("Performing the final commit using global data service.")
ds.save()
// now try to delete the files
do {
log.info("Trying to delete audio files.")
try FileManager.default.removeItem(at: dailyQuestionnaireInstance.breathingAudio)
try FileManager.default.removeItem(at: dailyQuestionnaireInstance.coughingAudio)
try FileManager.default.removeItem(at: dailyQuestionnaireInstance.readingAudio)
log.info("Removed all audio files successfully.")
} catch {
log.error("There was an error while deleting the audio files, reason: \(error)")
}
}
// only render this in debug mode
#if DEBUG
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
EndView()
.environmentObject(debugUserInstance)
.environmentObject(debugAppStatusInstance)
.environment(\.locale, .init(identifier: debugLocale))
}
}
#endif