DEV Community

Cover image for Learnings From Building A Weather App
Kuan Peng
Kuan Peng

Posted on

Learnings From Building A Weather App

Summary

This post is about learnings from my experience building apps while following this Udemy Course.
I ended up adding quite a bit to the base app, and I'm glad I did - it was really good learning to experiment with different frameworks and such. It took some time - about 6 hours or so...

Class Goal

Building a weather app, that fetches and displays information from an existing public API.

Class Learning Goal:

  • Learn how to talk to public APIs and parse JSON from responses.

Alt Text

My personal Goals

As part of trying to build this app, I wanted to learn more about:

  • Dependency Injection
  • JSON parsing frameworks

Most importantly I wanted to build a beautiful app similar to the Yahoo Weather app, which changed its background based on current location.

Result

github


Screenshot / Demo

Alt Text

UX improvements to the base app

  • Beautiful backgrounds appropriate to the City and the current weather in the city.
  • Auto completion suggestions for city names; case insensitive search
  • Toast messages for incorrect spelling
  • Visible Search / Weather panels that doesn't obstruct view of the photos

Learnings

APIs

  • Leverage Unsplash for great images. Unsplash APIs are quite easy and useful; used the "portrait" mode to search for photos that doesn't require resizing as much
  • API tokens can be stored locally via BuildConfigs and git-ignored so they don't appear on the searchable web. See this guide. Not the most secure for production, but good enough for learning projects.
  • Retrofit is such a nice library to use when the API use cases are super simple. It's ability to quickly generated a usable client with auto-json parsing abilities is great (make sure to use the converters like GsonConverter).
  • Gson is a lot easier to use than I expected. Good synergy w/ Lombok.
  • OkHttpInterceptors are good but a little bit of a pain. I read that OkHttpClients should be shared generally, but when they need to interface w/ separate services, I think we need to create a client for each service.

Architecture learnings

  • Dagger takes a little setting up to get going (you have to create an Application Class in addition to the basic activities, and the entry point is for some reason in the activity oncreate). But once it's set up, it's a great framework that makes dependencies super easy to manage. I'll try Hilt next.
  • How to organize package structure for D.I. is still a mystery to me.
  • Always use Java8. Streams are just too powerful to not use.

Android Learnings

  • AsyncTask isn't that bad on the surface... I probably should explore alternatives given it's deprecated.
  • ArrayAdaptors are a lot more finicky that I had expected. They require a layout (either my own or from android) to know how render a TextView. I made the mistake of passing them the activity layout, not realizing that made the dropdown box render the whole activity and crash the app.
  • Animating background changes seems to be a pain. Didn't figure out how to do this. Good next actions.
  • Toast can have gravity and appear in customized locations on the screen.
  • Hiding keyboard is hard, apparently. Also getting Enter key pressed to act like a submit button was interesting - use view.setOnKeyListener . * Careful when reading from file, because it could cost a lot of latency on startup. I honestly think I should've done it async... * Semi-Transparent layouts can help display the image underneath and at the same time help with making texts more legible.

Further Meaningful Augmentations

  • Add Animations/Transitions to photo changes, as I've mentioned
  • Add Temperature, humidity, etc
  • Save preferences
  • Make the TextLayouts that make things legible a color gradient rather than a single grey color. This could also blur the background as well..

That's all! Thanks for reading...

Top comments (0)