-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStudentResourcesScreen.kt
More file actions
304 lines (295 loc) · 11.3 KB
/
StudentResourcesScreen.kt
File metadata and controls
304 lines (295 loc) · 11.3 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package com.pennapps.labs.pennmobile.studentresources
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.OpenInNew
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.pennapps.labs.pennmobile.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun StudentResourcesScreen(
onBack: () -> Unit,
modifier: Modifier = Modifier,
) {
val categories = remember { StudentResourcesContent.categories }
var expandedId by remember { mutableStateOf<String?>(null) }
val listState = rememberLazyListState()
LaunchedEffect(expandedId) {
val id = expandedId ?: return@LaunchedEffect
val categoryIndex = categories.indexOfFirst { it.id == id }
if (categoryIndex >= 0) {
listState.animateScrollToItem(
index = categoryIndex + 1,
scrollOffset = -16,
)
}
}
Scaffold(
topBar = {
TopAppBar(
title = { Text("Student Resources") },
navigationIcon = {
IconButton(onClick = onBack) {
Icon(Icons.Filled.ArrowBack, contentDescription = "Back")
}
},
colors =
TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surface,
),
)
},
modifier = modifier,
) { innerPadding ->
LazyColumn(
state = listState,
modifier =
Modifier
.fillMaxSize()
.padding(innerPadding)
.navigationBarsPadding(),
contentPadding =
androidx.compose.foundation.layout.PaddingValues(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 96.dp,
),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
item { HeaderCard() }
categories.forEach { category ->
item(key = category.id) {
CategoryCard(
category = category,
expanded = expandedId == category.id,
onToggle = {
expandedId =
if (expandedId == category.id) null else category.id
},
)
}
}
}
}
}
@Composable
fun StudentResourcesSection(modifier: Modifier = Modifier) {
val categories = remember { StudentResourcesContent.categories }
var expandedId by remember { mutableStateOf<String?>(null) }
Column(
modifier =
modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
HeaderCard()
categories.forEach { category ->
CategoryCard(
category = category,
expanded = expandedId == category.id,
onToggle = {
expandedId = if (expandedId == category.id) null else category.id
},
)
}
}
}
@Composable
private fun HeaderCard(modifier: Modifier = Modifier) {
Card(
modifier = modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors =
CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surface,
),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp),
) {
Column {
Image(
painter = painterResource(id = R.drawable.gym_ringe),
contentDescription = null,
contentScale = androidx.compose.ui.layout.ContentScale.Crop,
modifier =
Modifier
.fillMaxWidth()
.height(140.dp)
.clip(RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)),
)
Row(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Image(
painter = painterResource(id = R.drawable.ua_logo),
contentDescription = "Undergraduate Assembly logo",
contentScale = ContentScale.Crop,
modifier =
Modifier
.size(44.dp)
.clip(RoundedCornerShape(6.dp)),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
text = "Undergraduate Assembly",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.SemiBold,
color = MaterialTheme.colorScheme.onSurface,
)
Text(
text = "Student resources",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Icon(
imageVector = Icons.Filled.OpenInNew,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Text(
text =
"This guide outlines the various resources and support " +
"available to Penn students, including when to use them and " +
"how to access them.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
Spacer(Modifier.height(8.dp))
}
}
}
@Composable
private fun CategoryCard(
category: ResourceCategory,
expanded: Boolean,
onToggle: () -> Unit,
modifier: Modifier = Modifier,
) {
val rotation by animateFloatAsState(
targetValue = if (expanded) 180f else 0f,
label = "chevron-rotation",
)
Card(
modifier = modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors =
CardDefaults.cardColors(
containerColor =
if (expanded) {
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.4f)
} else {
MaterialTheme.colorScheme.surface
},
),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp),
) {
Column {
Row(
modifier =
Modifier
.fillMaxWidth()
.clickable(onClick = onToggle)
.padding(horizontal = 16.dp, vertical = 18.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = category.icon,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface,
)
Spacer(Modifier.width(16.dp))
Text(
text = category.title,
style = MaterialTheme.typography.titleSmall,
fontWeight = FontWeight.SemiBold,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.weight(1f),
)
Icon(
imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = if (expanded) "Collapse" else "Expand",
tint = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.rotate(rotation),
)
}
AnimatedVisibility(
visible = expanded,
enter = fadeIn() + expandVertically(),
exit = fadeOut() + shrinkVertically(),
) {
Column(
modifier =
Modifier.padding(
start = 16.dp,
end = 16.dp,
bottom = 16.dp,
),
verticalArrangement = Arrangement.spacedBy(20.dp),
) {
category.resources.forEachIndexed { index, resource ->
ResourceItem(resource = resource)
if (index < category.resources.lastIndex) {
androidx.compose.material3.HorizontalDivider(
color = MaterialTheme.colorScheme.outlineVariant,
)
}
}
}
}
}
}
}