android5-11 Exercise 2: Stages 4 and 5 ================================== // NoteDao: one new query. A targeted update keeps the other columns (such as remoteId) as they were. @Query("UPDATE notes SET text = :text WHERE id = :id") suspend fun updateText(id: Long, text: String) // NotesRepository and DefaultNotesRepository suspend fun updateNoteText(id: Long, text: String) override suspend fun updateNoteText(id: Long, text: String) { noteDao.updateText(id, text) } data class NotesUiState( val notes: List = emptyList(), val query: String = "", val newestFirst: Boolean = true, val isLoading: Boolean = false, val isRefreshing: Boolean = false, val userMessage: String? = null, val exportText: String? = null ) import kotlinx.serialization.Serializable @Serializable data class NoteExport(val text: String, val createdAt: Long) fun exportNotesAsJson(notes: List): String = json.encodeToString(notes.map { NoteExport(it.text, it.createdAt) }) // In NotesScreen: the export result in a dialog state.exportText?.let { text -> AlertDialog( onDismissRequest = onExportShown, confirmButton = { TextButton(onClick = onExportShown) { Text("Close") } }, text = { Text(text) } ) } The ViewModel in the chapter holds all of stage 4 and 5's logic. Reuse: Sort setting: SettingsRepository and the Switch (Chapter 8). Search: a TextField calling viewModel::onQueryChange, bound to state.query. Refresh: NotesApi, NetworkModule or the container, the remoteId entity change, insertAll and RefreshResult (Chapter 7; remember to uninstall the app after the schema change). Export: NoteExport and exportNotesAsJson (above), shown in the dialog. Report which stage took longest and which chapter you reread. Code unrun.