DEV Community

Vivian
Vivian

Posted on

1

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!

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools 🔁

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more