Add select functionality to grades

This commit is contained in:
BuildTools
2024-04-11 19:53:03 +02:00
parent c5d32a5add
commit 46f0ae21a6
2 changed files with 154 additions and 38 deletions

View File

@@ -20,9 +20,11 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
@@ -103,6 +105,16 @@ fun GradeContent(activity: ComponentActivity, name : String){
)
}
},
// TODO: add confirmation to delete all
actions = {
IconButton(onClick = { grades = emptyList() }) {
Icon(
imageVector = Icons.Outlined.Delete,
contentDescription = null,
modifier = Modifier.size(28.dp)
)
}
},
modifier = Modifier.fillMaxWidth()
)
},
@@ -148,8 +160,16 @@ fun GradeContent(activity: ComponentActivity, name : String){
}
}
val types = listOf("Schulaufgabe", "Test", "Ex", "Referat", "Mündlich", "Sonstiges")
val grades = listOf(1, 2, 3, 4, 5, 6)
val weights = listOf(0.5f, 1f, 1.5f, 2f)
@Composable
fun GradePrefab(onClose: () -> Unit, color: Color){
var editing by remember {
mutableStateOf(true)
}
var typeExpanded by remember {
mutableStateOf(false)
}
@@ -160,53 +180,105 @@ fun GradePrefab(onClose: () -> Unit, color: Color){
mutableStateOf(false)
}
var selectedType by remember {
mutableStateOf("Typ")
}
var selectedGrade by remember {
mutableStateOf(1)
}
var selectedWeight by remember {
mutableStateOf(1f)
}
// Background
Surface(
shape = RoundedCornerShape(20),
color = color,
modifier = Modifier
.fillMaxWidth()
.height(128.dp)
.height(120.dp)
.padding(start = 16.dp, end = 16.dp, top = 16.dp)
) {
// Content
Column(modifier = Modifier.padding(16.dp)) {
// Top Row
Row {
// Type
Surface(
shape = RoundedCornerShape(10),
color = color,
border = BorderStroke(2.dp, TextOnColouredButton),
border = if(editing) BorderStroke(2.dp, TextOnColouredButton) else null,
modifier = Modifier
.size(width = 128.dp, height = 32.dp)
.clickable { typeExpanded = !typeExpanded }
.size(width = 170.dp, height = 32.dp)
.let { if (editing) it.clickable { typeExpanded = !typeExpanded } else it }
) {
Row(verticalAlignment = CenterVertically,
modifier = Modifier.padding(4.dp)) {
Text(text = "Typ", color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
DropdownMenu(expanded = typeExpanded, onDismissRequest = { typeExpanded = false }) {
DropdownMenuItem(text = { Text(text = "Test") }, onClick = { /*TODO*/ })
Text(text = selectedType, color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
if(editing) {
DropdownMenu(
expanded = typeExpanded,
onDismissRequest = { typeExpanded = false }
){
types.forEach { type ->
Item(
name = type,
onItemClick = {
selectedType = type
typeExpanded = !typeExpanded
}
)
}
}
Spacer(modifier = Modifier.weight(1f))
Icon(
imageVector = if (typeExpanded) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown,
contentDescription = null,
tint = TextOnColouredButton
)
}
Spacer(modifier = Modifier.weight(1f))
Icon(imageVector = if (typeExpanded) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown,
contentDescription = null,
tint = TextOnColouredButton)
}
}
// Delete
// Buttons
Spacer(modifier = Modifier.weight(1f))
Icon(
imageVector = Icons.Filled.Close,
contentDescription = null,
tint = TextOnColouredButton,
modifier = Modifier
.size(28.dp)
.clickable { onClose() }
)
if (editing) {
// Delete
Icon(
imageVector = Icons.Outlined.Delete,
contentDescription = null,
tint = TextOnColouredButton,
modifier = Modifier
.size(28.dp)
.clickable { onClose() }
)
Spacer(modifier = Modifier.width(4.dp))
// Confirm
Icon(
imageVector = Icons.Filled.Check,
contentDescription = null,
tint = TextOnColouredButton,
modifier = Modifier
.size(28.dp)
.clickable { editing = !editing }
)
}
else{
// Edit
Icon(
imageVector = Icons.Outlined.Edit,
contentDescription = null,
tint = TextOnColouredButton,
modifier = Modifier
.size(28.dp)
.clickable { editing = !editing }
)
}
}
Spacer(modifier = Modifier.weight(1f))
// Bottom Row
Row (verticalAlignment = CenterVertically) {
// Grade
Text(text = "Note:", color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
@@ -214,41 +286,76 @@ fun GradePrefab(onClose: () -> Unit, color: Color){
Surface(
shape = RoundedCornerShape(10),
color = color,
border = BorderStroke(2.dp, TextOnColouredButton),
border = if(editing) BorderStroke(2.dp, TextOnColouredButton) else null,
modifier = Modifier
.size(width = 48.dp, height = 32.dp)
.clickable { gradeExpanded = !gradeExpanded }
.let { if (editing) it.clickable { gradeExpanded = !gradeExpanded } else it }
) {
Row(verticalAlignment = CenterVertically,
modifier = Modifier.padding(4.dp)) {
Text(text = "1", color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
DropdownMenu(expanded = gradeExpanded, onDismissRequest = { gradeExpanded = false }) {
DropdownMenuItem(text = { Text(text = "Test") }, onClick = { /*TODO*/ })
Text(text = selectedGrade.toString(), color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
if(editing) {
DropdownMenu(
expanded = gradeExpanded,
onDismissRequest = { gradeExpanded = false }) {
grades.forEach { grade ->
Item(
name = grade.toString(),
onItemClick = {
selectedGrade = grade
gradeExpanded = !gradeExpanded
}
)
}
}
Spacer(modifier = Modifier.weight(1f))
Icon(
imageVector = if (gradeExpanded) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown,
contentDescription = null,
tint = TextOnColouredButton
)
}
Spacer(modifier = Modifier.weight(1f))
Icon(imageVector = if (gradeExpanded) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown, contentDescription = null, tint = TextOnColouredButton)
}
}
// Weight
Spacer(modifier = Modifier.width(16.dp))
Spacer(modifier = Modifier.width(8.dp))
Text(text = "Gewichtung:", color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
Spacer(modifier = Modifier.width(8.dp))
Surface(
shape = RoundedCornerShape(10),
color = color,
border = BorderStroke(2.dp, TextOnColouredButton),
border = if(editing) BorderStroke(2.dp, TextOnColouredButton) else null,
modifier = Modifier
.size(width = 64.dp, height = 32.dp)
.clickable { weightExpanded = !weightExpanded }
.size(width = 80.dp, height = 32.dp)
.let { if (editing) it.clickable { weightExpanded = !weightExpanded } else it }
) {
Row(verticalAlignment = CenterVertically,
modifier = Modifier.padding(4.dp)) {
Text(text = "1x", color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
DropdownMenu(expanded = weightExpanded, onDismissRequest = { weightExpanded = false }) {
DropdownMenuItem(text = { Text(text = "Test") }, onClick = { /*TODO*/ })
Text(text = "$selectedWeight" + "x", color = TextOnColouredButton, style = MaterialTheme.typography.labelMedium)
if (editing) {
DropdownMenu(
expanded = weightExpanded,
onDismissRequest = { weightExpanded = false }) {
weights.forEach { weight ->
Item(
name = weight.toString(),
onItemClick = {
selectedWeight = weight
weightExpanded = !weightExpanded
}
)
}
}
Spacer(modifier = Modifier.weight(1f))
Icon(
imageVector = if (weightExpanded) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown,
contentDescription = null,
tint = TextOnColouredButton
)
}
Spacer(modifier = Modifier.weight(1f))
Icon(imageVector = if (weightExpanded) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown, contentDescription = null, tint = TextOnColouredButton)
}
}
}
@@ -256,5 +363,13 @@ fun GradePrefab(onClose: () -> Unit, color: Color){
}
}
@Composable
fun Item(name : String, onItemClick: (String) -> Unit){
DropdownMenuItem(
text = { Text(text = name) },
onClick = { onItemClick(name) }
)
}
data class GradeData(val id: Int, val color: Color)