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/src/main/java/es/fpsumma/dam2/intro/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.ivancorrales.basicjetpackcompose.ui.theme.IntroTheme
import es.fpsumma.dam2.intro.ui.theme.IntroTheme
import es.fpsumma.dam2.intro.ui.screens.CounterScreen

class MainActivity : ComponentActivity() {
Expand Down
63 changes: 44 additions & 19 deletions app/src/main/java/es/fpsumma/dam2/intro/ui/screens/CounterScreen.kt
Original file line number Diff line number Diff line change
@@ -1,53 +1,78 @@
package es.fpsumma.dam2.intro.ui.screens

import android.graphics.Color
import androidx.compose.foundation.isSystemInDarkTheme
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.material3.FilledTonalButton
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
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 es.fpsumma.dam2.intro.ui.theme.IntroTheme


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

var count by remember { mutableStateOf(5) }
var user : String="Raúl";
Column(
modifier = Modifier
.fillMaxSize()
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text("Hola mi amig@!", style = MaterialTheme.typography.headlineMedium)
Text("Hola $user!", style = MaterialTheme.typography.headlineMedium)
Text("Contador: $count", style = MaterialTheme.typography.titleLarge)
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button(
onClick = {},
modifier = Modifier.semantics { contentDescription = "Incrementar" }
) { Text("+1") }

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

IconButton(
onClick = {},
modifier = Modifier.size(48.dp)
) {
Icon(Icons.Outlined.Refresh, contentDescription = "Reiniciar contador")
}
IntroTheme{
Button(
onClick = { count = count + 1 },
modifier = Modifier.semantics { contentDescription = "Incrementar" },
colors = ButtonDefaults.buttonColors(
containerColor = Color.(0xFF5DFF00),
),
) { Text("+1") }

FilledTonalButton(
onClick = {
if (count > 0) {
count = count - 1
}
},
modifier = Modifier.semantics { contentDescription = "Decrementar" }
) { Text("-1") }}
IconButton(
onClick = { count = 0 },
modifier = Modifier.size(48.dp)
) {
Icon(Icons.Outlined.Refresh, contentDescription = "Reiniciar contador")

}
Button(
modifier = Modifier.width((100 + count * 10).dp.coerceAtMost(500.dp)),
content = {},
)


}
}
}



@Composable
fun IntoTheme(content: @Composable () -> Unit) {
TODO("Not yet implemented")
}

@Preview(showBackground = true)
@Composable
private fun CounterPreview() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package es.fpsumma.dam2.intro.ui.screens


import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand All @@ -16,28 +17,28 @@ import androidx.compose.ui.unit.dp
fun InputDemoScreen() {
val focusManager = LocalFocusManager.current

var name by rememberSaveable { mutableStateOf("") }
var user by rememberSaveable { mutableStateOf("") }
var greeting by remember { mutableStateOf<String?>(null) }

// 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(user) {
derivedStateOf {
null
}
}

fun submit() {
if (error == null) {
greeting = "Hola, 👋"
greeting = "Hola, $user 👋"
focusManager.clearFocus()
}
}

Column(Modifier.fillMaxSize().padding(24.dp)) {
OutlinedTextField(
value = name,
onValueChange = { name = it },
value = user,
onValueChange = { user = it },
label = { Text("Tu nombre") },
isError = error != null,
supportingText = { if (error != null) Text(error!!) },
Expand All @@ -54,7 +55,7 @@ fun InputDemoScreen() {
Text("Saludar")
}
Spacer(Modifier.height(16.dp))
if (error == null && name.isNotBlank()) {
if (error == null && user.isNotBlank()) {
Text(greeting?: "" )
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/es/fpsumma/dam2/intro/ui/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ivancorrales.basicjetpackcompose.ui.theme
package es.fpsumma.dam2.intro.ui.theme

import androidx.compose.ui.graphics.Color

Expand All @@ -8,4 +8,6 @@ val Pink80 = Color(0xFFEFB8C8)

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

val Green = Color(0xFF5DFF00)
12 changes: 4 additions & 8 deletions app/src/main/java/es/fpsumma/dam2/intro/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
package com.ivancorrales.basicjetpackcompose.ui.theme
package es.fpsumma.dam2.intro.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import com.ivancorrales.basicjetpackcompose.ui.theme.LightColorScheme

private val DarkColorScheme = darkColorScheme(
primary = Purple80,
primary = Green, //Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)

private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
primary = Green, //Purple40,
secondary = Green, //PurpleGrey40,
tertiary = Pink40
)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/es/fpsumma/dam2/intro/ui/theme/Type.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ivancorrales.basicjetpackcompose.ui.theme
package es.fpsumma.dam2.intro.ui.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<!-- Base application theme. -->
<style name="Theme.Intro" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">@color/green_200</item>
<item name="colorPrimaryVariant">@color/green_500</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="green_500">#4CAF50</color>
<color name="green_200">#8BC34A</color>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<style name="Theme.Intro" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimaryVariant">@color/green_500</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
Expand Down
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"
material3 = "1.4.0"

[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-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }

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