@@ -2,103 +2,135 @@ package com.example.axelero.ui
2
2
3
3
import android.app.Activity
4
4
import android.content.Intent
5
- import android.hardware.SensorManager
6
- import android.os.Bundle
7
- import android.os.Environment
8
5
import androidx.activity.result.ActivityResultLauncher
9
6
import androidx.compose.foundation.layout.Arrangement
10
7
import androidx.compose.foundation.layout.Column
11
8
import androidx.compose.foundation.layout.Spacer
12
9
import androidx.compose.foundation.layout.fillMaxSize
10
+ import androidx.compose.foundation.layout.fillMaxWidth
13
11
import androidx.compose.foundation.layout.height
14
- import androidx.compose.material3.Button
12
+ import androidx.compose.foundation.layout.padding
13
+ import androidx.compose.foundation.rememberScrollState
14
+ import androidx.compose.foundation.shape.RoundedCornerShape
15
+ import androidx.compose.foundation.verticalScroll
16
+ import androidx.compose.material.icons.Icons
17
+ import androidx.compose.material.icons.automirrored.filled.ArrowBack
18
+ import androidx.compose.material3.CardDefaults
19
+ import androidx.compose.material3.ExperimentalMaterial3Api
20
+ import androidx.compose.material3.Icon
21
+ import androidx.compose.material3.IconButton
22
+ import androidx.compose.material3.MaterialTheme
23
+ import androidx.compose.material3.OutlinedButton
24
+ import androidx.compose.material3.OutlinedCard
25
+ import androidx.compose.material3.Scaffold
15
26
import androidx.compose.material3.Text
27
+ import androidx.compose.material3.TopAppBar
16
28
import androidx.compose.runtime.Composable
17
- import androidx.compose.runtime.State
18
- import androidx.compose.runtime.getValue
19
- import androidx.compose.runtime.mutableIntStateOf
20
- import androidx.compose.runtime.mutableStateOf
21
29
import androidx.compose.runtime.produceState
22
30
import androidx.compose.runtime.remember
23
- import androidx.compose.runtime.setValue
31
+ import androidx.compose.runtime.rememberCoroutineScope
24
32
import androidx.compose.ui.Alignment
25
33
import androidx.compose.ui.Modifier
34
+ import androidx.compose.ui.platform.LocalContext
26
35
import androidx.compose.ui.unit.dp
27
- import androidx.core.app.ActivityCompat.startActivityForResult
28
36
import com.example.axelero.db.OrientationData
29
37
import com.example.axelero.repository.OrientationDataRepository
30
38
import com.example.axelero.ui.components.LineChart
31
- import com.example.axelero.ui.components.SensorDelayDropdownMenu
32
39
import com.patrykandpatrick.vico.core.model.CartesianChartModelProducer
33
- import kotlinx.coroutines.CoroutineScope
34
- import kotlinx.coroutines.Dispatchers
35
40
import kotlinx.coroutines.launch
36
- import java.io.File
37
41
42
+ @OptIn(ExperimentalMaterial3Api ::class )
38
43
@Composable
39
- fun HistoryContent (orientationDataRepository : OrientationDataRepository , createDocumentResult : ActivityResultLauncher <Intent >) {
44
+ fun HistoryContent (
45
+ orientationDataRepository : OrientationDataRepository ,
46
+ createDocumentResult : ActivityResultLauncher <Intent >
47
+ ) {
48
+ val context = LocalContext .current
40
49
val orientationData = produceState<List <OrientationData >>(initialValue = emptyList()) {
41
50
value = orientationDataRepository.getOrientationData()
42
51
}
43
-
44
52
val modelProducer1 = remember { CartesianChartModelProducer .build() }
45
53
val modelProducer2 = remember { CartesianChartModelProducer .build() }
46
54
val modelProducer3 = remember { CartesianChartModelProducer .build() }
55
+ val coroutineScope = rememberCoroutineScope()
56
+ val scrollState = rememberScrollState()
47
57
48
- Column (
49
- modifier = Modifier .fillMaxSize(),
50
- verticalArrangement = Arrangement .Center ,
51
- horizontalAlignment = Alignment .CenterHorizontally
52
- ) {
53
- Text (" Orientation Data History" )
54
- Spacer (modifier = Modifier .height(16 .dp))
55
-
56
- // Display the three line charts for the actual orientation angles
57
- LineChart (
58
- " X Angle" ,
59
- orientationData.value.map { it.xAngle },
60
- modelProducer1
61
- )
62
- Spacer (modifier = Modifier .height(16 .dp))
63
- LineChart (
64
- " Y Angle" ,
65
- orientationData.value.map { it.yAngle },
66
- modelProducer2
67
- )
68
- Spacer (modifier = Modifier .height(16 .dp))
69
- LineChart (
70
- " Z Angle" ,
71
- orientationData.value.map { it.zAngle },
72
- modelProducer3
73
- )
58
+ Scaffold (
59
+ topBar = {
60
+ TopAppBar (title = { Text (" Orientation Data History" ) },
61
+ navigationIcon = {
62
+ IconButton (onClick = {(context as ? Activity )?.onBackPressed() }) {
63
+ Icon (Icons .AutoMirrored .Filled .ArrowBack , contentDescription = " Back" )
64
+ }
65
+ }
66
+ )
67
+ }
68
+ ) { padding ->
69
+ Column (
70
+ modifier = Modifier
71
+ .fillMaxSize()
72
+ .padding(padding)
73
+ .padding(horizontal = 16 .dp)
74
+ .verticalScroll(scrollState),
75
+ verticalArrangement = Arrangement .Center ,
76
+ horizontalAlignment = Alignment .CenterHorizontally
77
+ ) {
78
+ Spacer (Modifier .height(16 .dp))
79
+ OutlinedCard (modifier = Modifier .fillMaxWidth(), elevation = CardDefaults .outlinedCardElevation(defaultElevation = 4 .dp)) {
80
+ Column (modifier = Modifier .padding(16 .dp)) {
81
+ Text (" X Angle" , style = MaterialTheme .typography.titleMedium)
82
+ Spacer (Modifier .height(8 .dp))
83
+ LineChart (" X Angle" , orientationData.value.map { it.xAngle }, modelProducer1)
84
+ }
85
+ }
74
86
75
- Spacer (modifier = Modifier .height(16 .dp))
76
- Button (
77
- onClick = {
78
- // Save the orientation data to a text file on the device
79
- val intent = Intent (Intent .ACTION_CREATE_DOCUMENT ).apply {
80
- addCategory(Intent .CATEGORY_OPENABLE )
81
- type = " text/plain"
82
- putExtra(Intent .EXTRA_TITLE , " orientation_data_" + {orientationDataRepository.sensingInterval.toString()} + " .txt" )
87
+ Spacer (Modifier .height(16 .dp))
88
+ OutlinedCard (modifier = Modifier .fillMaxWidth(), elevation = CardDefaults .outlinedCardElevation(defaultElevation = 4 .dp)) {
89
+ Column (modifier = Modifier .padding(16 .dp)) {
90
+ Text (" Y Angle" , style = MaterialTheme .typography.titleMedium)
91
+ Spacer (Modifier .height(8 .dp))
92
+ LineChart (" Y Angle" , orientationData.value.map { it.yAngle }, modelProducer2)
83
93
}
84
- createDocumentResult.launch(intent)
85
94
}
86
- ) {
87
- Text (" Export Data" )
88
- }
89
- Spacer (modifier = Modifier .height(16 .dp))
90
- Button (
91
- onClick = {
92
- // Reset the orientation data in the database
93
- CoroutineScope (Dispatchers .IO ).launch {
94
- orientationDataRepository.clearOrientationData()
95
+
96
+ Spacer (Modifier .height(16 .dp))
97
+ OutlinedCard (modifier = Modifier .fillMaxWidth(), elevation = CardDefaults .outlinedCardElevation(defaultElevation = 4 .dp)) {
98
+ Column (modifier = Modifier .padding(16 .dp)) {
99
+ Text (" Z Angle" , style = MaterialTheme .typography.titleMedium)
100
+ Spacer (Modifier .height(8 .dp))
101
+ LineChart (" Z Angle" , orientationData.value.map { it.zAngle }, modelProducer3)
95
102
}
96
103
}
97
- ) {
98
- Text (" Reset Data" )
104
+
105
+ Spacer (Modifier .height(24 .dp))
106
+ OutlinedButton (
107
+ onClick = {
108
+ val intent = Intent (Intent .ACTION_CREATE_DOCUMENT ).apply {
109
+ addCategory(Intent .CATEGORY_OPENABLE )
110
+ type = " text/plain"
111
+ putExtra(Intent .EXTRA_TITLE , " orientation_data_" + orientationDataRepository.sensingInterval.toString() + " .txt" )
112
+ }
113
+ createDocumentResult.launch(intent)
114
+ },
115
+ modifier = Modifier .fillMaxWidth(0.6f ),
116
+ shape = RoundedCornerShape (8 .dp)
117
+ ) {
118
+ Text (" Export Data" )
119
+ }
120
+ Spacer (Modifier .height(16 .dp))
121
+ OutlinedButton (
122
+ onClick = {
123
+ coroutineScope.launch {
124
+ orientationDataRepository.clearOrientationData()
125
+ }
126
+ },
127
+ modifier = Modifier .fillMaxWidth(0.6f ),
128
+ shape = RoundedCornerShape (8 .dp)
129
+ ) {
130
+ Text (" Reset Data" )
131
+ }
99
132
}
100
133
}
101
134
}
102
135
103
136
104
-
0 commit comments