Examen terminado
This commit is contained in:
parent
4b1d224620
commit
c89b2083df
|
|
@ -18,8 +18,6 @@ class ExerciseOneViewModel: ViewModel() {
|
|||
|
||||
private val idAutoincrement: AtomicInteger = AtomicInteger()
|
||||
|
||||
var showLazy by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
fun setNumCounters(value: Int){
|
||||
for (i in 1 .. value){
|
||||
|
|
@ -28,12 +26,10 @@ class ExerciseOneViewModel: ViewModel() {
|
|||
num = 0
|
||||
))
|
||||
}
|
||||
/* showLazy = !showLazy*/
|
||||
}
|
||||
|
||||
fun resetAll(){
|
||||
_counters.removeAll(counters)
|
||||
/*showLazy = !showLazy*/
|
||||
}
|
||||
|
||||
fun increment(element: CounterNumber){
|
||||
|
|
|
|||
|
|
@ -1,9 +1,103 @@
|
|||
package ies.teis.genol_salatiel_ex2tdist.ui.exerciseTwo
|
||||
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
|
||||
@Composable
|
||||
fun ExerciseTwoComposable(){
|
||||
Text(text = "2")
|
||||
fun ExerciseTwoComposable() {
|
||||
|
||||
val viewModel: ExerciseTwoViewModel = viewModel()
|
||||
var inputState by rememberSaveable { mutableStateOf("") }
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(title = {
|
||||
Row() {
|
||||
Text(
|
||||
text = "Contadores",
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 10.dp)
|
||||
.weight(1f)
|
||||
)
|
||||
Text(text = "Global: ")
|
||||
Text(
|
||||
text = viewModel.counters.sumOf {
|
||||
it.numCounter
|
||||
}.toString(),
|
||||
modifier = Modifier.padding(end = 10.dp)
|
||||
)
|
||||
}
|
||||
})
|
||||
}) { paddingValues ->
|
||||
|
||||
Column(Modifier.padding(paddingValues)) {
|
||||
Row(
|
||||
Modifier
|
||||
.padding(top = 15.dp)
|
||||
.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
TextField(value = inputState, onValueChange = { inputState = it })
|
||||
Button(onClick = { viewModel.addCounter(inputState) }) {
|
||||
Text(text = "Añadir")
|
||||
}
|
||||
}
|
||||
LazyColumn(state = listState) {
|
||||
items(viewModel.counters) { counterModel ->
|
||||
Card(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Column(Modifier.background(MaterialTheme.colors.secondary)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = counterModel.counterName,
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(start = 16.dp)
|
||||
)
|
||||
|
||||
Text(text = counterModel.numCounter.toString())
|
||||
|
||||
IconButton(onClick = { viewModel.eliminar(counterModel) }) {
|
||||
Icon(Icons.Filled.Close, contentDescription = "Close")
|
||||
}
|
||||
}
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Text(text = "Sumar", modifier = Modifier.clickable { viewModel.sumar(element = counterModel) })
|
||||
Text(text = "Restar", modifier = Modifier.clickable { viewModel.restar(element = counterModel)})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue