> For the complete documentation index, see [llms.txt](https://android-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://android-course.cornellappdev.com/course-material/week-5-or-coroutines-networking-json/a5-bananazon.md).

# A5: Bananazon

This assignment has a release code! Please download it below, extract it, and open it in Android Studio. Ensure it can compile and run fine on your emulator before starting this assignment.

{% file src="/files/vLFZU5eqRj3fLjDqeRvB" %}
A5 Release Code!
{% endfile %}

For our fifth assignment, we'll have you develop the networking logic for a basic e-commerce app!

*We've talked about money and happiness, and now, let us ponder — can money buy happiness? Perhaps not, but money sure can buy a lot of things — let's dive into the depths of materialism...*

Let's walk through the code, shall we?

***

## Release Code

Expand each of the files below for a description of the release code!

<details>

<summary><code>data</code> package</summary>

Contains all code that deals with data directly (data layer)

* `model` contains the data classes that will be used to represent the Product data
* `remote` contains the Product API Service interface
* `repository` contains the `ProductRepository` that will be used to handle and expose Product data to the UI layer.

</details>

<details>

<summary><code>di</code> package</summary>

Contains all code that deals with dependency injection

* `BananzonApplication` contains the Hilt Application Class for the app
* `NetworkModule` contains the providers for the various parts of the retrofit layer like the OkHttpClient

</details>

<details>

<summary><code>ui</code> package</summary>

Contains all code in the UI Layer including ViewModels

* `components` contains a couple Composables that will be used in the `ProductScreen`
  * `Header` contains the top part and search bar of the screen
  * `ProductCard` contains the component that represents the Product data as a card
* `screens` contains the `ProductScreen` that displays the products as a list and uses a search bar to filter the results
* `viewmodels` contains the `ProductViewModel` that handles the business logic of `ProductScreen`

</details>

***

## Requirements:

This assignment is not split into features, but rather more so as steps towards implementing Retrofit correctly.

<details>

<summary>1) OkHttpClient</summary>

Create the OkHttpClient provider in `NetworkModule`

</details>

<details>

<summary>2) Retrofit Instance</summary>

Create the Retrofit instance provider. For our base url, we will be using <https://dummyjson.com/>.   &#x20;

</details>

<details>

<summary>3) ProductAPIService</summary>

We will be using the Get All Products and Search Products endpoints from [here](https://dummyjson.com/docs/products#products-all). Based on that information, do the following:

1. Create the relevant serializable data classes in `Product.kt` to represent the JSON responses. To see the example JSON output, you can visit <https://dummyjson.com/products> for example.&#x20;
   1. It might be helpful to have AI do the heavy lifting for creating the data classes with serial name.
2. Define the methods that represent the API endpoints we are using with the correct Retrofit annotations in `ProductApiService.kt`
3. Create the API Service instance in `NetworkModule` using the retrofit instance provider you made earlier and the interface you just defined.

</details>

<details>

<summary>4) ProductRepository.kt</summary>

1. Inject the api service into the repository.
2. Implement the `getAllProducts` method by using the api service and returning a Result\<List\<Product>>.
3. Do the same for the `searchProducts` method.

</details>

<details>

<summary>5) ProductViewModel.kt</summary>

1. Inject the repository into the ViewModel.
2. Replace Any with the actual Product data class you defined earlier in the `ProductUiState`.
3. Implement `loadProducts` with the repository functions. Remember to handle the loading and error states accordingly when the function is called, on success of the repository function result, and on failure of the repository function result.
4. Do the same for `searchProducts`.

</details>

<details>

<summary>6) ProductScreen.kt</summary>

Alright, time to tie it all together! In this part, you'll connect your screen to the viewmodel and test the final networking logic to get your app actually showing the proper response from the backend.

1. Display the list of products in the `ProductsContent` composable using `LazyColumn` and the `ProductCard` composable.
2. Collect the uiState and searchQuery StateFlows from the ViewModel.&#x20;
3. Pass the states and the relevant handlers into the `ProductsScreenContent` composable which you should add to the `ProductsScreen` composable.

If you get any networking errors, make sure to debug with LogCat errors!

</details>

If you've solved A5 correctly, your solution should look something like this...

{% file src="/files/YaD7JGG97cXXtqnsI4pU" %}
A5 Solution Demo Video!
{% endfile %}

When you're done, export your project through Android Studio and upload your ZIP to CMS! Congrats on finishing A5!

<figure><img src="/files/r52zfAnfr9pDA56ssqN8" alt=""><figcaption><p>Exporting with File -> Export -> Export to Zip File...</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://android-course.cornellappdev.com/course-material/week-5-or-coroutines-networking-json/a5-bananazon.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
