1
+ package com.example.studysmart.presentation.session
2
+
3
+ import androidx.compose.foundation.border
4
+ import androidx.compose.foundation.layout.Arrangement
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.Column
7
+ import androidx.compose.foundation.layout.Row
8
+ import androidx.compose.foundation.layout.aspectRatio
9
+ import androidx.compose.foundation.layout.fillMaxSize
10
+ import androidx.compose.foundation.layout.fillMaxWidth
11
+ import androidx.compose.foundation.layout.padding
12
+ import androidx.compose.foundation.layout.size
13
+ import androidx.compose.foundation.lazy.LazyColumn
14
+ import androidx.compose.foundation.shape.CircleShape
15
+ import androidx.compose.material.icons.Icons
16
+ import androidx.compose.material.icons.filled.ArrowBack
17
+ import androidx.compose.material.icons.filled.ArrowDropDown
18
+ import androidx.compose.material3.Button
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.Scaffold
24
+ import androidx.compose.material3.Text
25
+ import androidx.compose.material3.TopAppBar
26
+ import androidx.compose.material3.rememberModalBottomSheetState
27
+ import androidx.compose.runtime.Composable
28
+ import androidx.compose.runtime.getValue
29
+ import androidx.compose.runtime.mutableStateOf
30
+ import androidx.compose.runtime.remember
31
+ import androidx.compose.runtime.rememberCoroutineScope
32
+ import androidx.compose.runtime.saveable.rememberSaveable
33
+ import androidx.compose.runtime.setValue
34
+ import androidx.compose.ui.Alignment
35
+ import androidx.compose.ui.Modifier
36
+ import androidx.compose.ui.unit.dp
37
+ import androidx.compose.ui.unit.sp
38
+ import com.example.studysmart.presentation.components.DeleteDialog
39
+ import com.example.studysmart.presentation.components.SubjectListBottomSheet
40
+ import com.example.studysmart.presentation.components.studySessionsList
41
+ import com.example.studysmart.sessions
42
+ import com.example.studysmart.subjects
43
+ import kotlinx.coroutines.launch
44
+
45
+ @OptIn(ExperimentalMaterial3Api ::class )
46
+ @Composable
47
+ fun SessionScreen () {
48
+
49
+ val scope = rememberCoroutineScope()
50
+ val sheetState = rememberModalBottomSheetState()
51
+ var isBottomSheetOpen by remember { mutableStateOf(false ) }
52
+
53
+ var isDeleteDialogOpen by rememberSaveable { mutableStateOf(false ) }
54
+
55
+
56
+ SubjectListBottomSheet (
57
+ sheetState = sheetState,
58
+ isOpen = isBottomSheetOpen,
59
+ subjects = subjects,
60
+ onDismissRequest = { isBottomSheetOpen = false },
61
+ onSubjectClicked = {
62
+ scope.launch { sheetState.hide() }.invokeOnCompletion {
63
+ if (! sheetState.isVisible) isBottomSheetOpen = false
64
+ }
65
+ }
66
+ )
67
+
68
+ DeleteDialog (
69
+ isOpen = isDeleteDialogOpen,
70
+ title = " Delete Session?" ,
71
+ bodyText = " Are you sure, you want to delete this session? " +
72
+ " This action can not be undone." ,
73
+ onDismissRequest = { isDeleteDialogOpen = false },
74
+ onConfirmButtonClick = {
75
+ isDeleteDialogOpen = false
76
+ }
77
+ )
78
+
79
+ Scaffold (
80
+ topBar = {
81
+ SessionScreenTopBar (onBackButtonClick = {})
82
+ }
83
+ ) { paddingValues ->
84
+ LazyColumn (
85
+ modifier = Modifier
86
+ .fillMaxSize()
87
+ .padding(paddingValues)
88
+ ) {
89
+ item {
90
+ TimerSection (
91
+ modifier = Modifier
92
+ .fillMaxWidth()
93
+ .aspectRatio(1f )
94
+ )
95
+ }
96
+ item {
97
+ RelatedToSubjectSection (
98
+ modifier = Modifier
99
+ .fillMaxWidth()
100
+ .padding(horizontal = 12 .dp),
101
+ relatedToSubject = " English" ,
102
+ selectSubjectButtonClick = { isBottomSheetOpen = true }
103
+ )
104
+ }
105
+ item {
106
+ ButtonsSection (
107
+ modifier = Modifier
108
+ .fillMaxWidth()
109
+ .padding(12 .dp),
110
+ startButtonClick = { },
111
+ cancelButtonClick = { },
112
+ finishButtonClick = { }
113
+ )
114
+ }
115
+ studySessionsList(
116
+ sectionTitle = " STUDY SESSIONS HISTORY" ,
117
+ emptyListText = " You don't have any recent study sessions.\n " +
118
+ " Start a study session to begin recording your progress." ,
119
+ sessions = sessions,
120
+ onDeleteIconClick = { isDeleteDialogOpen = true }
121
+ )
122
+ }
123
+ }
124
+ }
125
+
126
+ @OptIn(ExperimentalMaterial3Api ::class )
127
+ @Composable
128
+ private fun SessionScreenTopBar (
129
+ onBackButtonClick : () -> Unit
130
+ ) {
131
+ TopAppBar (
132
+ navigationIcon = {
133
+ IconButton (onClick = onBackButtonClick) {
134
+ Icon (
135
+ imageVector = Icons .Default .ArrowBack ,
136
+ contentDescription = " Navigate to Back Screen"
137
+ )
138
+ }
139
+ },
140
+ title = {
141
+ Text (text = " Study Sessions" , style = MaterialTheme .typography.headlineSmall)
142
+ }
143
+ )
144
+ }
145
+
146
+ @Composable
147
+ private fun TimerSection (
148
+ modifier : Modifier
149
+ ) {
150
+ Box (
151
+ modifier = modifier,
152
+ contentAlignment = Alignment .Center
153
+ ) {
154
+ Box (
155
+ modifier = Modifier
156
+ .size(250 .dp)
157
+ .border(5 .dp, MaterialTheme .colorScheme.surfaceVariant, CircleShape )
158
+ )
159
+ Text (
160
+ text = " 00:05:32" ,
161
+ style = MaterialTheme .typography.titleLarge.copy(fontSize = 45 .sp)
162
+ )
163
+ }
164
+ }
165
+
166
+ @Composable
167
+ private fun RelatedToSubjectSection (
168
+ modifier : Modifier ,
169
+ relatedToSubject : String ,
170
+ selectSubjectButtonClick : () -> Unit
171
+ ) {
172
+ Column (modifier = modifier) {
173
+ Text (
174
+ text = " Related to subject" ,
175
+ style = MaterialTheme .typography.bodySmall
176
+ )
177
+ Row (
178
+ modifier = Modifier .fillMaxWidth(),
179
+ horizontalArrangement = Arrangement .SpaceBetween ,
180
+ verticalAlignment = Alignment .CenterVertically
181
+ ) {
182
+ Text (
183
+ text = relatedToSubject,
184
+ style = MaterialTheme .typography.bodyLarge
185
+ )
186
+ IconButton (onClick = selectSubjectButtonClick) {
187
+ Icon (
188
+ imageVector = Icons .Default .ArrowDropDown ,
189
+ contentDescription = " Select Subject"
190
+ )
191
+ }
192
+ }
193
+ }
194
+ }
195
+
196
+ @Composable
197
+ private fun ButtonsSection (
198
+ modifier : Modifier ,
199
+ startButtonClick : () -> Unit ,
200
+ cancelButtonClick : () -> Unit ,
201
+ finishButtonClick : () -> Unit ,
202
+ ) {
203
+ Row (
204
+ modifier = modifier,
205
+ horizontalArrangement = Arrangement .SpaceBetween
206
+ ) {
207
+ Button (onClick = cancelButtonClick) {
208
+ Text (
209
+ modifier = Modifier .padding(horizontal = 10 .dp, vertical = 5 .dp),
210
+ text = " Cancel"
211
+ )
212
+ }
213
+ Button (onClick = startButtonClick) {
214
+ Text (
215
+ modifier = Modifier .padding(horizontal = 10 .dp, vertical = 5 .dp),
216
+ text = " Start"
217
+ )
218
+ }
219
+ Button (onClick = finishButtonClick) {
220
+ Text (
221
+ modifier = Modifier .padding(horizontal = 10 .dp, vertical = 5 .dp),
222
+ text = " Finish"
223
+ )
224
+ }
225
+ }
226
+ }
0 commit comments