Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSC 214

Homework Assignment #5

Due: March 4, 2024

It is time for Books 2.0 with added Navigation and a DetailsScreen. Adopt the following functions into your viewModel:

fun selectBook(idx: Int) {

val book = uiState.value.books.find { it.index == idx }

_uiState.value = _uiState.value.copy(

selectedBook = book,

showsDetail = true

)

}

fun hideDetail() {

_uiState.value = _uiState.value.copy(

selectedBook = _uiState.value.books.first(),

showsDetail = false

)

}

HomeScreen [20 points]

Create a new package named screens in the ui package, then add a new file HomeScreen. Copy the contents from BooksApp into this le and update its layout as shown. Add a preview. This screen does not display the synopsis.

DetailScreen [20 points]

Add a new file DetailScreen in screens. Copy parts from BooksApp into this file as needed and update its layout as shown. Then add a preview. This screen does not display the quote and adds a button.

Display Test [30 points]

Remove old ui code in BooksApp that is now contained in HomeScreen and DetailScreen. Add a Boolean 'showsDetail' in HomeUIState. Update BooksApp with the following test to switch screens in your preview. (This will need updating in the next step).

if (homeUIState.showsDetail) {

DetailsScreen(

book = BooksTestData.allPotter.first())

} else {

HomeScreen(

homeUIState = homeUIState,

showDetail = showDetail)

}

Show Detail [10 points]

Pass viewModel's selectBook MainActivity through to BookItem to execute it. In the simulator a click now results in one-way navigation to the DetailScreen.

.clickable { selectBook(book.index) },

Back Button [10 points]

Pass viewModel's hideDetail from MainActivity through to the 'Back' button in DetailsScreen and execute it. Two-way navigation now works in the simulator.

Button(onClick = hideDetail) {

Text(stringResource(R.string.back))

}

Git [10 points]

Have at least 6 commits in the project's repo.

Hand In

1.      create an upload folder naming it using your id, assignment type and version separated by dashes (hw for homework, p for project): jsmith24-hw-5

2.      ensure that your project's package name includes your id (com.jsmith24)

3.      add the entire project folder to the upload folder

4.      add a signed and dated copy of the ReadMe file next to your project folder

5.     compress (zip) your upload folder and upload it to Blackboard