Challenge 1: An Offline-First Repository — Solution class NoteRepository @Inject constructor( private val dao: NoteDao, private val api: NoteApiService ) { val notes: Flow> = dao.getAllNotes() suspend fun refresh() { try { val remoteNotes = api.getNotes() remoteNotes.forEach { dao.insert(it) } } catch (e: IOException) { // Network failed — do nothing; the UI keeps observing whatever // is already cached in Room via the "notes" Flow above. } } } Notes: - notes exposes dao.getAllNotes() DIRECTLY — the UI (via a ViewModel) only ever observes the local database, never the network response itself. This is the defining trait of offline-first: local storage is the single source of truth the UI actually watches. - refresh() is a one-way sync: fetch from the network, then write each result into Room via dao.insert(...). Because notes is a Flow backed by Room (per Chapter 3), those writes automatically cause "notes" to re-emit with the fresh data — no separate manual "update the UI" step is needed after a successful refresh. - The empty catch block is intentional, not an oversight — if the network call fails, the UI simply continues showing whatever was already cached from the last successful refresh (or from earlier app usage), which is a perfectly reasonable degraded experience rather than an error state that needs special UI handling.