DEV Community

Vivian
Vivian

Posted on

OSD600 - Adding New Feature To Weather App

1. The issue

In last contribution for Hacktoberfest, I created a Weather Forecast App. However, users can watch the weather information of one city at a time that is a little inconvenient. I want to update the app so it will have a list of searched locations with some information in another page.

2. Modification process

Here are modifications I did to update the app:

  • Refactor source code by reconstructing the architecture
    Putting all source code in the main class is not a good practice so I decided to split the code into smaller models.
    Image description

    • AppController gets data from API and return the JSON object to other models.
    • Main starts the app, prepares views.
    • Weather Data stores information of a weather data object
    • City Adapter describes how to display each City's info to ListView
    • HistoryListAcitivity displays info and listens for event on each ListView item.
  • Add new List button to the main screen which links to the History List Activity and passes an ArrayList of city's name to this activity.

    Image description

  • Design view for History List Activity

    Image description

View more details in PR

3. Throwback

During the modification process, the hardest part will be splitting the source code. I faced a problem with multi-thread in Java. The data was set to the view before it was returned from API. I tried to apply some knowledge about Thread learning from JAC444 but it did not work well.

As such, I started seeking help from an Android Dev Senior. He is very helpful and enthusiastic. After communicating with him, I found out the solution and got a lot of useful tips for working with Android App.

All in all, thank you so much for reading the post.

Happy coding!

Top comments (0)