Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/es/fpsumma/dam2/intro/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.ivancorrales.basicjetpackcompose.ui.theme.IntroTheme
import es.fpsumma.dam2.intro.ui.screens.CounterScreen
import es.fpsumma.dam2.intro.ui.screens.InputDemoScreen

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -19,7 +20,9 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
CounterScreen()
// CounterScreen()
InputDemoScreen()

}
}
}
Expand Down
51 changes: 41 additions & 10 deletions app/src/main/java/es/fpsumma/dam2/intro/ui/screens/CounterScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ package es.fpsumma.dam2.intro.ui.screens
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Refresh

import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp



@Composable
fun CounterScreen() {
var count by remember { mutableStateOf(0) }
var count by rememberSaveable { mutableStateOf(5) }


Column(
modifier = Modifier
Expand All @@ -25,31 +28,59 @@ fun CounterScreen() {
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text("Hola mi amig@!", style = MaterialTheme.typography.headlineMedium)
Text("Buenos_dias", style = MaterialTheme.typography.headlineMedium)
Text("Contador: $count", style = MaterialTheme.typography.titleLarge)


Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {

Button(
onClick = {},
modifier = Modifier.semantics { contentDescription = "Incrementar" }
onClick = { count++ },
modifier = Modifier.semantics { contentDescription = "Incrementar" },
colors = ButtonDefaults.buttonColors(
containerColor = Color.Green,
contentColor = Color.White
)
) { Text("+1") }

FilledTonalButton(
onClick = {},
onClick = {
if (count > 0) {
count--
}
},
modifier = Modifier.semantics { contentDescription = "Decrementar" }
) { Text("-1") }



IconButton(
onClick = {},
onClick = { count = 0 },
modifier = Modifier.size(48.dp)
) {
Icon(Icons.Outlined.Refresh, contentDescription = "Reiniciar contador")

}
}

// Botón con ancho que cambia según el contador
Button(
onClick = { },
modifier = Modifier
.width(40.dp + (count * 10).dp)
.height(48.dp),

) {

}
}
}

@Preview(showBackground = true)
@Composable
private fun CounterPreview() {
CounterScreen()
}
private fun CounterPreviewDark() {
CounterScreen()
}



Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ fun InputDemoScreen() {

// Calcula el error en función del texto (sin estado extra) Pista -> derivedStateOf
// TODO: valida name: no vacío, mínimo 3 caracteres (trim).
val error: String? by remember(name) {
val error: String? by remember(name) { //lo tienes que llamar name.trim por du funcion
derivedStateOf {
null
if (name.trim().isEmpty()) {
"El nombre no puede estar vacío";
}else if (name.trim().length < 3) {
"El nombre debe tener al menos 3 caracteres";
}
else null
}
}

fun submit() {
if (error == null) {
greeting = "Hola, 👋"
if (error == null && name.trim().isNotBlank()) {
greeting = "Hola, ${name.trim()} 👋"
focusManager.clearFocus()
}
}
Expand All @@ -49,7 +54,8 @@ fun InputDemoScreen() {
Spacer(Modifier.height(16.dp))
Button(
onClick = { submit() },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
enabled = error == null && name.trim().isNotBlank() // Hace que no te puede saludar porque desabilita si tiene alguno de los dos errores
) {
Text("Saludar")
}
Expand All @@ -62,4 +68,4 @@ fun InputDemoScreen() {

@Preview(showBackground = true)
@Composable
private fun InputDemoPreview() { InputDemoScreen() }
private fun InputDemoPreview() { InputDemoScreen() }
3 changes: 2 additions & 1 deletion app/src/main/java/es/fpsumma/dam2/intro/ui/theme/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ val Pink80 = Color(0xFFEFB8C8)

val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
val Pink40 = Color(0xFF7D5260)

4 changes: 2 additions & 2 deletions app/src/main/java/es/fpsumma/dam2/intro/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private val LightColorScheme = lightColorScheme(

@Composable
fun IntroTheme(
darkTheme: Boolean = false,
dynamicColor: Boolean = true,
darkTheme: Boolean = true,
dynamicColor: Boolean = false,
content: @Composable () -> Unit
) {
val colorScheme = when {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Intro</string>
<string name="Buenos_dias">Intro</string>
</resources>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ androidx-activity = { group = "androidx.activity", name = "activity", version.re
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 15 11:01:44 CEST 2025
#Mon Oct 20 13:02:11 CEST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists