Added Searching and Teacher screens
This commit is contained in:
parent
28ce28ed54
commit
b18dfb1e28
@ -1,20 +1,129 @@
|
||||
package it.edu.cassandroferminervi.flowschool.screens
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.ramcosta.composedestinations.TeacherScreenDestination
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
|
||||
@Destination
|
||||
@Composable
|
||||
fun SearchingScreen() {
|
||||
Box (
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
Text("Searching screen")
|
||||
fun SearchingScreen(navigator: DestinationsNavigator) {
|
||||
val teachers = listOf(
|
||||
"Mario Rossi",
|
||||
"Michele Verdi",
|
||||
"Fabio Bianchi"
|
||||
).groupBy {
|
||||
it.first()
|
||||
}.toSortedMap()
|
||||
.map {
|
||||
Category(
|
||||
it.key.toString(),
|
||||
items = it.value
|
||||
)
|
||||
}
|
||||
var filter by remember { mutableStateOf("") }
|
||||
|
||||
Column {
|
||||
TextField(
|
||||
value = filter,
|
||||
onValueChange = { filter = it },
|
||||
label = { Text("Cerca") },
|
||||
singleLine = true,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
)
|
||||
CategorizedLazyColumn(
|
||||
categories = teachers,
|
||||
navigator = navigator,
|
||||
filter = filter
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class Category(
|
||||
val name: String,
|
||||
val items: List<String>
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun CategoryHeader(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.primaryContainer)
|
||||
.padding(16.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CategoryItem(
|
||||
text: String,
|
||||
navigator: DestinationsNavigator,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
TextButton(onClick = {
|
||||
navigator.navigate(TeacherScreenDestination("test"))
|
||||
}) {
|
||||
Text(
|
||||
text = text,
|
||||
fontSize = 14.sp,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
.padding(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun CategorizedLazyColumn(
|
||||
categories: List<Category>,
|
||||
navigator: DestinationsNavigator,
|
||||
filter: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
LazyColumn(modifier) {
|
||||
categories.forEach { category ->
|
||||
if (category.items.any {
|
||||
it.contains(filter, ignoreCase = true)
|
||||
}) {
|
||||
stickyHeader {
|
||||
CategoryHeader(category.name)
|
||||
}
|
||||
}
|
||||
|
||||
items(items = category.items.filter {
|
||||
it.contains(filter, ignoreCase = true)
|
||||
}) { text ->
|
||||
CategoryItem(text, navigator)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package it.edu.cassandroferminervi.flowschool.screens
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
|
||||
@Destination
|
||||
@Composable
|
||||
fun TeacherScreen(codice: String) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
Text("Codice prof: $codice")
|
||||
Text("Presente: si")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user