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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.compose.ui)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
4 changes: 3 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,8 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
CounterScreen()
//CounterScreen()
InputDemoScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package es.fpsumma.dam2.intro.ui.screens

import es.fpsumma.dam2.intro.R
import androidx.appcompat.widget.ButtonBarLayout
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Refresh
Expand All @@ -8,15 +10,19 @@ import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
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
import androidx.compose.ui.unit.times


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


Column(
modifier = Modifier
Expand All @@ -25,26 +31,40 @@ fun CounterScreen() {
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text("Hola mi amig@!", style = MaterialTheme.typography.headlineMedium)

Text(stringResource(id = R.string.app_presentacion), 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=count+1},
modifier = Modifier.semantics { contentDescription = "Incrementar" },
colors = ButtonDefaults.buttonColors(
containerColor = Color.Green,
contentColor = Color.White
)
) { Text("+1") }

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

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

}

val ButtonWidth = 5.dp
Button(
onClick = {},
modifier = Modifier.width(count * ButtonWidth)
) { }

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ fun InputDemoScreen() {
// TODO: valida name: no vacío, mínimo 3 caracteres (trim).
val error: String? by remember(name) {
derivedStateOf {
null
if (name.trim().isEmpty()) {
"El nombre no puede estar vacío";
}else if (name.trim().length < 3) {
"El nombre no debe tener menos de 3 caracteres";
}
else null
}
}


fun submit() {
if (error == null) {
greeting = "Hola, 👋"
greeting = "Hola, ${name.trim()}👋" // $name hace que muestre el nombre que insertes por pantalla se muestre
focusManager.clearFocus()
}
}
Expand All @@ -49,7 +55,8 @@ fun InputDemoScreen() {
Spacer(Modifier.height(16.dp))
Button(
onClick = { submit() },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
enabled = error === null && name.trim().isNotBlank()
) {
Text("Saludar")
}
Expand Down
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)

5 changes: 3 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,10 +28,11 @@ 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 {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">Intro</string>
</resources>
<string name="app_presentacion">¡Buenos días!</string>
</resources>

2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ appcompat = "1.7.1"
material = "1.13.0"
activity = "1.11.0"
constraintlayout = "2.2.1"
ui = "1.9.4"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -32,6 +33,7 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "ui" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down