Introducci贸n a Jetpack Compose
Qu茅 es Jetpack Compose
Configuraci贸n inicial del proyecto
Personalizaci贸n de la UI con Material Design
Colores, Fuentes y Material Theme
Creaci贸n de Componentes de UI
Compose: Fases y Recomposici贸n
Quiz: Personalizaci贸n de la UI con Material Design
Composici贸n de layouts en Jetpack Compose
Creaci贸n y abstracci贸n modelos de dominio
Layouts: Column, Row y Box
C贸mo utilizar Scaffold, TopAppBar, FAB y Listas
Vista de progreso personalizada con Canvas
Arquitectura de Acci贸n - Estado - Evento en ViewModel
Ajustes en pantalla de lista de tareas
Quiz: Composici贸n de layouts en Jetpack Compose
Construcci贸n de funcionalidades
Pantalla de creaci贸n de tareas
Creaci贸n de Viewmodel para CreateTaskScreen
Quiz: Construcci贸n de funcionalidades
Navegaci贸n en Jetpack Compose
Introducci贸n a la navegaci贸n en Compose
Manejo de navegaci贸n con argumentos
Quiz: Navegaci贸n en Jetpack Compose
Creaci贸n de Bases de datos y dependencias
Creaci贸n de la base de datos con Room
Inyecci贸n de dependencias con Hilt
Quiz: Creaci贸n de Bases de datos y dependencias
Finalizaci贸n de la app
Ajustes finales de UI para tu App
Demostraci贸n final de tu App
You don't have access to this class
Keep learning! Join and start boosting your career
It is fascinating to see how an application can respond to user interactions, allowing you to mark tasks as completed, delete them, or update them. When approaching programming in Android, the ViewModel is a key tool that makes it easy to organize and manage these interactive actions. Here are the essential steps to get your application to respond appropriately to these actions.
To enable the visibility of the information on the screen, some modifications are made to the FakeDataLocalDataSource
class. Adding an init
block after the task flow is essential. The goal is to load a first batch of completed and pending task information, merging lists so that everything is ready for display in the user interface.
init { completed = completedTask + pendingTask}
Separating the status from the home in a separate class improves the organization of the project. Using a specific data class
like HomeDataState
allows to keep everything much more organized and in its proper place.
data class HomeDataState( val completedTasks: List , val pendingTasks: List )
A Sealed Interface
in Android allows you to clearly describe the actions that the user can perform. These actions are specified through separate data classes
for each type of action. This allows to manage different behaviors such as marking complete tasks or deleting a specific task.
sealed interface HomeScreenAction { data class OnToggleTask(val task: Task) : HomeScreenAction data class OnDeleteTask(val task: Task) : HomeScreenAction object OnDeleteAllTasks : HomeScreenAction object OnAddTask : HomeScreenAction}
The use of a sealed class
to model events is fundamental. These classes help map specific events that are triggered by user actions, ensuring a detailed and organized handling of each event.
sealed class HomeScreenEvent { object OnTaskUpdated : HomeScreenEvent() object OnAllTasksDeleted : HomeScreenEvent() object OnTaskDeleted : HomeScreenEvent()}
The ViewModel
is used to manage state changes and actions on the screen. Implementing a ViewModel
involves:
Maintaining the state of the ViewModel
using an event channel.
Filtering completed and pending tasks.
Updating the status with each data issue.
Privately handle state changes and process actions derived from the task flow.
class HomeScreenViewModel : ViewModel() { private val taskLocalDataSourceFake = TaskLocalDataSourceFake() private val _state = mutableStateOf(HomeDataState(listOf(), listOf())) val state: State = _state
fun onAction(action: HomeScreenAction) { when (action) { is HomeScreenAction.OnDeleteAllTasks -> { // Handle delete all tasks action } is HomeScreenAction.OnToggleTask -> { // Handle toggle task action } }} } }
}
Integrating actions
and events
involves handling them in the interactive elements of the interface. Each action and event must be properly implemented in the Composables
of the screen to ensure reactivity.
Delete All Action: When the icon is selected to delete all tasks, it must be interacted with the ViewModel
.
Event Filter: Use collect
to react to events such as displaying informative Toast
messages or immediate UI changes.
fun HomeScreen(onAction: (HomeScreenAction) -> Unit) { // UI composables... FloatingActionButton(onClick = { onAction(HomeScreenAction.OnDeleteAllTasks) }) { Text(text = "Delete All") }
// Handle actions...
}
By implementing these practices, you are charged with designing an Android application that not only organizes its business logic better, but also responds nimbly to user interactions, significantly improving the user experience.
Contributions 6
Questions 0
Want to see more contributions, questions and answers from the community?