Capstone Notes App
Android Development with Compose: Architecture & Data
Course 5 · Chapter 11 · Putting It All Together
You have met every part separately. This chapter asks you to build one small app that uses all of them together: a notes app that stores notes in Room, shows them through a ViewModel, remembers a sort order in DataStore, can fetch sample notes from a server, can export its notes as JSON, and wires its objects together properly. There is very little new teaching here; the point is the joins.
StateFlow in Chapter 2; coroutines, stateIn and cancellation in Chapter 3; Room in Chapter 4 (which has the Room 2.x against 3.0 choice); the repository in Chapter 5; serialization in Chapter 6; Retrofit in Chapter 7 (whose converter coordinates are unconfirmed); DataStore in Chapter 8; manual injection in Chapter 9; Hilt in Chapter 10.
Added here, general knowledge: the @Update-style targeted query, the five-flow limit of the typed combine and grouping flows into one, the AlertDialog, and the checklist and problems table, which are a summary of what went wrong in earlier chapters, not a docs-checked list. All code is unrun (no Kotlin compiler on the machine used to write this); nothing was seen on your install.
What You Are Building
| Feature | Uses |
|---|---|
| Add, edit, delete and list notes | Room, repository, ViewModel, stateless screen (Chapters 1 to 5) |
| Search as you type | A query held in the ViewModel's state |
| Newest-first or oldest-first | DataStore setting feeding the state (Chapter 8) |
| Refresh sample notes from a server | Retrofit, the converter, Room as the source of truth (Chapters 6 and 7) |
| Export the notes as JSON | kotlinx.serialization (Chapter 6) |
| Objects wired deliberately | Manual container (Chapter 9) or Hilt (Chapter 10): your choice |
The Shape of the App
State flows down the top row; events and the network come in from below. Nothing in the UI knows Room, Retrofit or DataStore exist (Chapter 5's table, who may know what).
Build It in Stages
| Stage | Do this |
|---|---|
| 1. Storage | Entity, DAO and database (Chapter 4); the Note model, mappers and repository interface with a fake (Chapter 5). Checkpoint: the DAO test passes. |
| 2. State holder | NotesUiState, the ViewModel exposing a StateFlow built from the repository's Flow (Chapters 1 to 3). Checkpoint: the ViewModel test passes against the fake. |
| 3. Screen | Route and stateless screen with add, delete and a list, plus previews (Chapters 1 and 2). Checkpoint: add a note, rotate, close and reopen: it is still there. |
| 4. Settings, search and edit | The DataStore sort switch (Chapter 8), a search box, and editing a note's text. Checkpoint: the sort order survives a restart; search narrows the list as you type. |
| 5. Network and export | Refresh from the server into Room (Chapter 7), and export the notes as JSON (Chapter 6). Checkpoint: aeroplane mode still shows the list, and a failed refresh shows a message. |
| 6. Wiring | Hand-written container and factory (Chapter 9) or Hilt (Chapter 10). Checkpoint: no class builds its own dependencies. |
Finish each checkpoint before moving on. If a later stage breaks an earlier checkpoint, that is information about a leaky boundary.
The New Pieces
Three small additions that earlier chapters did not cover. Editing a note, with a targeted query so that other columns are left alone:
(general knowledge) The tempting alternative is @Update with note.toEntity(), but Note has no remoteId, so the mapper would reset it and an imported note would turn into a local one.
The state and a JSON export of the notes:
Here is the whole ViewModel, so you can see the earlier chapters joined. Notice the Transient class: the typed combine takes five flows (general knowledge), so the short-lived bits (a message and the export text) are grouped into one flow.
Three Kinds of Test
Acceptance Checklist
Your capstone is done when every line is true:
- ☐ The UI never imports a DAO, an entity, Retrofit or DataStore.
- ☐ Every screen state can be previewed without running the app.
- ☐ The list survives rotation, closing the app and aeroplane mode.
- ☐ A failed refresh shows a message and does not clear the list.
- ☐ The sort order survives a restart.
- ☐ One database, one Retrofit instance, one DataStore for the whole app.
- ☐ No loading starts in a ViewModel's
init. - ☐ Cancellation is never swallowed (
CancellationExceptionis rethrown if you catch broadly). - ☐ The ViewModel can be built in a test with fakes and no Android.
- ☐ All versions are current and the build is clean.
When Something Goes Wrong
| Symptom | Likely cause |
|---|---|
| Build fails in a generated Room or Hilt class | Wrong or mismatched plugin, KSP or library versions (Chapters 4 and 10); a typo in an annotation or query. |
| App crashes on first run after changing the entity | The database version was not raised or there is no migration; uninstall while developing (Chapter 7). |
| List is empty until the first refresh | Expected: the table starts empty; show a helpful empty state, or refresh when the table is empty (Chapter 7, Exercise 3). |
| Fetch works but notes overwrite each other | Server ids stored as local ids; use a separate remoteId with a unique index (Chapter 7). |
| State never updates after a change | The upstream flow is not being collected: with WhileSubscribed nothing runs without a collector (Chapter 3). |
| Hilt reports a missing binding | An interface without a @Binds, or a class without an @Inject constructor (Chapter 10). |
Try It Yourself
Build stages 1 to 3: storage, the state holder and the screen. Show the checkpoint results: the DAO test and the ViewModel test passing, and a note that survives rotation and a restart.
📄 View solutionBuild stages 4 and 5: the sort setting, search, editing, refresh from the server and the JSON export. Report which stage took longest, and which earlier chapter you had to reread.
📄 View solutionBuild stage 6 your chosen way, then walk the acceptance checklist and write down any line that is not yet true. Finish with a short review: if the server went away for good, what would you have to change, and what could stay exactly as it is?
📄 View solutioncollectAsStateWithLifecycle version note).General knowledge, not checked: the targeted update query; the five-flow limit of the typed
combine; the AlertDialog code; the file layout; the checklist and the problems table.Not verified: the complete app has never been built or run, so the pieces from different chapters may need small fixes to compile together; every listing and solution (unrun); the exercises (not run by me). Nothing was checked on your install.
Sources: the sources listed in the Not Yet Verified boxes of Android Development with Compose: Architecture & Data 1 to 10.
android6, not yet written), and Personal Catalogue: Android (Kotlin & Compose), a larger project that applies all of this.