CMPUT 301

Software Engineering

Lab 3 Instructions


Lab 3: More Android

1. Getting Started

  1. Fork and clone this repository and open the /code folder in Android Studio.
  2. You'll find a basic ListyCity app that displays a static list of cities and provinces.

2. Demo Instructions

During the lab demo, we'll implement "Add City" functionality:

  1. Review Lab 3 Slides
  2. Follow along with Lab 3 Instructions
  3. Read about Code Conventions (see the Kotlin Code Conventions PDF).
  4. By the end, you'll have implemented the ability to add new cities to the list.

3. Lab 3 Participation Exercise

Task
Example Implementation

Screen1 Screen2 Screen3 Screen4

Note: Your app does NOT need to look exactly like the screenshots. The only requirement is the ability to edit an existing city.

4. Implementation Tips

1. City Class Updates
data class City(
    val name: String,
    val province: String
)

Since name and province use val, they cannot be changed directly after a City object is created

To edit a city, create a new City object with the updated values and replace the old city in the list

Example:

val updatedCity = City(
    name = newCityName,
    province = newProvinceName
)
2. Choose Your Implementation

Recommended Approach:

Example Code

One approach is to add an updateCity() function to CityRepository:

fun updateCity(oldCity: City, updatedCity: City) {
    val index = _cities.indexOf(oldCity)
    if (index != -1) {
        _cities[index] = updatedCity
    }
}
Compose Hints
var selectedCity by remember { mutableStateOf<City?>(null) }

5. Submission

[!CAUTION] Make sure to commit and push your code to the GitHub repository before the deadline!

Once you completed, please go to Canvas and submit your Lab 3 GitHub repository link.

Due Date

Friday after the Thursday lab at 5 PM