Homework 2
Let's build an application that allows browsing between a set of plants in a greenhouse.
The app has 2 views:
- A List of all plants
- A Detailed view of one plant.
Implementing UI & Navigation
The UI should be implemented using 1 Activity and 2 Fragments.
- One Fragment for List of plants
- The list should be implemented using RecyclerView
- Each list item layout should have a TextView and an ImageView
- By default, the ImageView should not be visible
- The user should be able to select one plant in the List, which navigates them to the details View of the selected Plant.
- The movement between the list and detailed view should be implemented using a Navigation Graph (Recall Lab 2)
- Use Fragment Arguments to pass data to the Details view
- Second Fragment for the Detailed view of one plant. It should include at minimum
- A TextView for the name of the plant,
- A TextView for Description of the Plant
- An ImageView, which will have a default image or be hidden by default (up to you).
- A Button with the text "Take picture" (see below)
Base project
Use [ this base project ] as a starting point for the app. It provides a Plant data class and a PlantRepository and PlantDataset classes. Use PlantDataset to get the list of plants or fetch a single one by ID / Name or to assign a thumbnail to a plant.
- Use
PlantRepository.instance(context)
to get an instance of a PlantDataset object.- PlantRepository uses the Singleton pattern to ensure that only 1 instance of PlantDataset exists, even if the above is called multiple times, from different Activities, Fragments, etc.
- Use methods of PlantDataset to get a list of all plants from the json. You should use setPlantThumbnail(..) to update the thumbnail
- NB! make sure you test your to ensure the recycling of views during scrolling does not introduce unexpected bugs!
- Your RecyclerView custom Adapter should manage a dataset of the Plant class/type (instead of String as we did in Lab 4).
"Take picture" button
- Clicking the "Take Picture" button brings the user to the Camera app for taking a picture.
- After the picture is taken, the user is returned to the Detail view, and the image is shown in the DetailsView with an ImageView
- Recall how we started new Activities in Lab 2, use Intents, refer to this material to get started
- You can use the simpler version of image capture that only returns the thumbnail in Intent Extras, handling the full-size image requires some more work, not needed for this homework. See here
Distinguishing plants that have a Pictures in the list
- After a picture has been taken and returning back to the list, listed plants that have a picture taken should have a little Icon next to their name, distinguishing whether or not a picture was taken.
- Hint: achieve this with View Binding of RecyclerViews, and use the thumbnail attribute of the Plant data class. Use the
PlantRepository.instance(context).setPlantThumbnail( .. )
helper method to update the in-memory object.
- Hint: achieve this with View Binding of RecyclerViews, and use the thumbnail attribute of the Plant data class. Use the
Note: If the app is closed, the state is lost, we are not requiring storing any long-term state.
Submission
Create a sub-folder particularly for this homework (call it homework2), it should contain the source code of your Android Studio project.
- Create a new Git TAG named
homework2
for the last commit related to this homework. - Update the .MD file at the root of your repository, so it contains a link to the subfolder of this homework.