Overview
TheHomeScreen is the primary interface of the EV Sum 2 application. It provides users with the ability to create, manage, search, and play back saved phrases using text-to-speech technology. This screen is displayed after successful authentication and serves as the central hub for all phrase management operations.
File Location: com.demodogo.ev_sum_2.ui.home.HomeScreen.kt:64
Function Signature
Parameters
Callback function invoked when the user clicks the logout button. Typically navigates back to the login screen.
Callback function invoked when the user wants to view their device location. Opens the DeviceLocationScreen.
State Management
The HomeScreen maintains several state variables to manage user interactions and data:User Input State
Stores the text for creating a new phrase. Managed with
rememberSaveable.Stores the search query for filtering saved phrases. Managed with
rememberSaveable.Edit Dialog State
Holds the ID of the phrase currently being edited, or null if no phrase is being edited.
Stores the temporary text while editing a phrase.
Controls the visibility of the phrase editing dialog.
Data State
Contains the list of all user phrases loaded from the backend.
Indicates whether an async operation is in progress.
Stores error messages to display to the user.
Stores informational messages to display to the user.
Services & Controllers
AuthService
Handles user authentication operations:currentEmail()- Retrieves the currently logged-in user’s emaillogout()- Logs out the current user
PhraseService
Manages phrase CRUD operations:get()- Fetches all phrases for the current useradd(text: String)- Creates a new phraseupdate(id: String, text: String)- Updates an existing phrasedelete(id: String)- Deletes a phrase
TextToSpeechController
Provides text-to-speech functionality:speak(text: String)- Speaks the provided text alouddestroy()- Cleans up TTS resources
User Interactions
Creating a New Phrase
- User enters text in the “¿Qué quieres decir?” text field
- User clicks “GUARDAR NUEVA FRASE” button
- Validation ensures the text is not blank
- Phrase is saved via
PhraseService.add() - List is refreshed to show the new phrase
HomeScreen.kt:177-202
Searching Phrases
The search functionality filters phrases in real-time based on user input:HomeScreen.kt:116-120
Playing Phrase Audio
Each phrase card includes a “REPRODUCIR VOZ” button that uses text-to-speech:HomeScreen.kt:238-250
Copying to Clipboard
Users can copy phrase text to the system clipboard:HomeScreen.kt:94-98
Editing Phrases
- User clicks “Editar” button on a phrase card
- Alert dialog opens with the phrase text
- User modifies the text
- User clicks “Guardar” to save changes
- Phrase is updated via
PhraseService.update()
Deleting Phrases
Users can delete phrases with a single click:HomeScreen.kt:289-295
UI Components
The HomeScreen uses Material 3 components:- Surface - Root container with background color
- Column - Main vertical layout with scrolling
- Card - User info display and phrase containers
- OutlinedTextField - Text input for new phrases and search
- Button - Primary actions (save, play, delete, logout)
- OutlinedButton - Secondary action (view location)
- LazyColumn - Scrollable list of phrase cards
- LinearProgressIndicator - Loading state indicator
- AlertDialog - Edit phrase dialog
Example Usage
The HomeScreen automatically loads phrases when first displayed using
LaunchedEffect(Unit). The TextToSpeechController is properly cleaned up when the composable is disposed.Best Practices
- Error Handling - All async operations include try-catch blocks with user-friendly error messages
- Resource Cleanup - TTS controller is destroyed in
DisposableEffectto prevent memory leaks - State Persistence - User input is preserved across configuration changes using
rememberSaveable - Optimized Filtering - Search filtering uses
rememberto avoid unnecessary recomputations