LAB 5 — LazyColumn & Room Database ==================================== Mobile Application Development | SUZA | Semester II 2025/2026 OBJECTIVES ---------- - Build scrollable content with LazyColumn and LazyVerticalGrid - Set up Room with Entity, DAO, Database - Use Repository + ViewModel + StateFlow pattern - Perform full CRUD from the UI SETUP ----- Add to build.gradle.kts (Module): implementation("androidx.room:room-runtime:2.6.1") implementation("androidx.room:room-ktx:2.6.1") ksp("androidx.room:room-compiler:2.6.1") Top of file (Module build script): plugins { id("com.google.devtools.ksp") } PART A — Read-Only List App --------------------------- 1. Affirmation Gallery - Create a data class Affirmation(val id: Int, val stringRes: Int, val imageRes: Int) - Build a Datasource.kt with a list of 10 affirmations - Display using LazyColumn of Card composables (image + text) - Try again with LazyVerticalGrid(columns = GridCells.Fixed(2)) PART B — Student Registry (Room CRUD) ------------------------------------- Schema: @Entity students { id (PK auto), name, course, year, email } 1. Entity + DAO + Database Create: - Student entity - StudentDao with insert/update/delete + Flow> getAll() - StudentDatabase with singleton getDatabase(context) 2. Repository + ViewModel - class StudentRepository(private val dao: StudentDao) - class StudentViewModel(private val repo: StudentRepository) : ViewModel() Expose students as StateFlow> via .stateIn(...) Methods: addStudent, updateStudent, deleteStudent 3. Screens (navigate with Nav-Compose) a. ListScreen — LazyColumn of students. Tap item → detail. FAB "+" → AddStudent. Swipe-to-delete (optional bonus). b. AddStudentScreen — form with TextFields + Save button. c. DetailScreen — show details + "Edit" + "Delete". d. EditStudentScreen — pre-fill form, update on Save. 4. ViewModel Factory Provide a ViewModelProvider.Factory because StudentViewModel has arguments. 5. Seed Data On first run, insert 3 sample students so the UI isn't empty. VALIDATION RULES ---------------- - Name: non-empty - Email: must contain "@" - Year: must be 1, 2, 3, or 4 Disable the Save button unless valid; show inline helper errors. DELIVERABLES ------------ - Project "StudentRegistry" on GitHub as "mad-lab05" - Short demo video (< 90 sec) showing: list, add, edit, delete, detail - README.md explaining how to build & run - Architecture diagram (draw.io / Excalidraw) in /docs